Skip to content

Commit 96753d2

Browse files
authored
fix all docs tests and run tests in CI (#100)
- Fix the `docs` project's tests and align their components with more modern standards in the repo. - Run tests in CI
1 parent 8e997c9 commit 96753d2

32 files changed

+232
-261
lines changed

.circleci/config.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ jobs:
2424
- node_modules
2525
key: v1-dependencies-{{ checksum "package.json" }}
2626

27+
- run:
28+
name: test libs/core (@angular-react/core)
29+
command: npm run test:ci -- core
30+
2731
- run:
2832
name: build libs/core (@angular-react/core)
2933
command: npm run build:libs:core
@@ -71,7 +75,11 @@ jobs:
7175
key: v1-dependencies-{{ checksum "package.json" }}
7276

7377
- run:
74-
name: build docs (@angular-react/core)
78+
name: test docs
79+
command: npm run test:ci -- docs
80+
81+
- run:
82+
name: build docs
7583
command: npm run build:demo:github
7684

7785
- deploy:

apps/demo/karma.conf.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
1-
// Karma configuration file, see link for more information
2-
// https://karma-runner.github.io/1.0/config/configuration-file.html
1+
const baseConfig = require('../../test/karma.conf');
32

43
module.exports = function(config) {
5-
config.set({
6-
basePath: '',
7-
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8-
plugins: [
9-
require('karma-jasmine'),
10-
require('karma-chrome-launcher'),
11-
require('karma-jasmine-html-reporter'),
12-
require('karma-coverage-istanbul-reporter'),
13-
require('@angular-devkit/build-angular/plugins/karma'),
14-
],
15-
client: {
16-
clearContext: false, // leave Jasmine Spec Runner output visible in browser
17-
},
18-
coverageIstanbulReporter: {
19-
dir: require('path').join(__dirname, '../../coverage'),
20-
reports: ['html', 'lcovonly'],
21-
fixWebpackSourcePaths: true,
22-
},
23-
reporters: ['progress', 'kjhtml'],
24-
port: 9876,
25-
colors: true,
26-
logLevel: config.LOG_INFO,
27-
autoWatch: true,
28-
browsers: ['Chrome'],
29-
singleRun: false,
30-
});
4+
baseConfig(config);
315
};

apps/docs/karma.conf.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
1-
// Karma configuration file, see link for more information
2-
// https://karma-runner.github.io/1.0/config/configuration-file.html
1+
const baseConfig = require('../../test/karma.conf');
32

43
module.exports = function(config) {
5-
config.set({
6-
basePath: '',
7-
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8-
plugins: [
9-
require('karma-jasmine'),
10-
require('karma-chrome-launcher'),
11-
require('karma-jasmine-html-reporter'),
12-
require('karma-coverage-istanbul-reporter'),
13-
require('@angular-devkit/build-angular/plugins/karma'),
14-
],
15-
client: {
16-
clearContext: false, // leave Jasmine Spec Runner output visible in browser
17-
},
18-
coverageIstanbulReporter: {
19-
dir: require('path').join(__dirname, '../../coverage'),
20-
reports: ['html', 'lcovonly'],
21-
fixWebpackSourcePaths: true,
22-
},
23-
reporters: ['progress', 'kjhtml'],
24-
port: 9876,
25-
colors: true,
26-
logLevel: config.LOG_INFO,
27-
autoWatch: true,
28-
browsers: ['Chrome'],
29-
singleRun: false,
30-
});
4+
baseConfig(config);
315
};

apps/docs/src/app/app.component.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { RouterTestingModule } from '@angular/router/testing';
3+
import { AngularReactBrowserModule } from '@angular-react/core';
4+
import {
5+
FabButtonModule,
6+
FabContextualMenuModule,
7+
FabDropdownModule,
8+
FabPivotModule,
9+
FabCommandBarModule,
10+
} from '@angular-react/fabric';
211

312
import { AppComponent } from './app.component';
13+
import { ComponentsModule } from './components/components.module';
14+
import { MaterialModule } from './material.module';
415

516
describe('AppComponent', () => {
617
let component: AppComponent;
718
let fixture: ComponentFixture<AppComponent>;
819

920
beforeEach(async(() => {
1021
TestBed.configureTestingModule({
22+
imports: [
23+
RouterTestingModule,
24+
MaterialModule,
25+
FabDropdownModule,
26+
ComponentsModule,
27+
AngularReactBrowserModule,
28+
FabPivotModule,
29+
FabContextualMenuModule,
30+
FabCommandBarModule,
31+
FabButtonModule,
32+
],
1133
declarations: [AppComponent],
1234
}).compileComponents();
1335
}));

apps/docs/src/app/components/navbar/navbar.component.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { RouterTestingModule } from '@angular/router/testing';
3+
4+
import { MaterialModule } from '../../material.module';
25

36
import { NavbarComponent } from './navbar.component';
7+
import { SubNavService } from '../../shared/sub-nav.service';
48

59
describe('NavbarComponent', () => {
610
let component: NavbarComponent;
711
let fixture: ComponentFixture<NavbarComponent>;
812

913
beforeEach(async(() => {
1014
TestBed.configureTestingModule({
15+
imports: [MaterialModule, RouterTestingModule],
1116
declarations: [NavbarComponent],
17+
providers: [SubNavService],
1218
}).compileComponents();
1319
}));
1420

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component } from '@angular/core';
22

33
@Component({
44
selector: 'app-page-header',
55
templateUrl: './page-header.component.html',
66
styleUrls: ['./page-header.component.scss'],
77
})
8-
export class PageHeaderComponent implements OnInit {
9-
constructor() {}
10-
11-
ngOnInit() {}
12-
}
8+
export class PageHeaderComponent {}

apps/docs/src/app/components/sub-nav/sub-nav.component.html

Lines changed: 0 additions & 4 deletions
This file was deleted.

apps/docs/src/app/components/sub-nav/sub-nav.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { Component } from '@angular/core';
22

33
@Component({
44
selector: 'app-sub-nav',
5-
templateUrl: './sub-nav.component.html',
5+
template: `
6+
<ng-container *subnav>
7+
<!-- Content is projected into navbar. -->
8+
<ng-content></ng-content>
9+
</ng-container>
10+
`,
611
})
712
export class SubNavComponent {}

apps/docs/src/app/components/triangle/triangle.component.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
// tslint:disable:no-input-rename
22

3-
import {
4-
ChangeDetectionStrategy,
5-
Component,
6-
Input,
7-
OnChanges,
8-
SimpleChanges,
9-
OnInit,
10-
ViewEncapsulation,
11-
ContentChild,
12-
TemplateRef,
13-
ElementRef,
14-
OnDestroy,
15-
} from '@angular/core';
16-
import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
3+
import { Component, OnInit, ContentChild, TemplateRef, ElementRef, OnDestroy } from '@angular/core';
174

185
export const COLORS = { default: { text: '#222', bg: '#ddd' }, hover: { text: '#fff', bg: '#0078D4' } };
196
export const DEFAULT_DOT_SIZE = 25;
@@ -46,7 +33,7 @@ export class TriangleComponent implements OnInit, OnDestroy {
4633
private startTime: number; // In milliseconds
4734
private counter = 0; // Revolving counter, 0-9 and back again.
4835
private _scale: number; // Moves from 1 to 1.5 and back to 1 at a set rate based on time elapsed.
49-
private timer: NodeJS.Timer; // Repeating timer that updates the counter once per second.
36+
private timer: number; // Repeating timer that updates the counter once per second.
5037
private _dots: Array<SierpinskiTriangleDot>; // Collection of dot objects, rendered by the dotTemplate.
5138
public isActive: boolean; // Used to indicate active looping and to prevent further looping (stop).
5239

@@ -106,9 +93,9 @@ export class TriangleComponent implements OnInit, OnDestroy {
10693
// the updates as it is aware of each node being updated. React struggles
10794
// with this update since it is not holistically aware of every node
10895
// being updated. Although React Fiber optimizes updates to prevent
109-
// blocking the single thread and interupting high priority updates such
96+
// blocking the single thread and interrupting high priority updates such
11097
// as animation, each individual React node schedules it's update without
111-
// knowledge of the other nodes (dots) and they all atempt to update
98+
// knowledge of the other nodes (dots) and they all attempt to update
11299
// at the same time, blocking the thread. Further investigation is needed
113100
// to see if there is a way for the separate React dots to share a scheduler
114101
// and coordinate DOM updates.
@@ -120,7 +107,7 @@ export class TriangleComponent implements OnInit, OnDestroy {
120107

121108
// Update the counter (the number shown on each dot).
122109
this.startTime = new Date().getTime();
123-
this.timer = setInterval(() => this.updateCounter(), this.interval);
110+
this.timer = setInterval(() => this.updateCounter(), this.interval) as any;
124111

125112
// Update the scale value for the container (applied via css transform
126113
// on the container).
@@ -170,7 +157,6 @@ class SierpinskiTriangle {
170157
if (size <= targetSize) {
171158
this.dot = new SierpinskiTriangleDot(x - targetSize / 2, y - targetSize / 2, targetSize);
172159
} else {
173-
const newSize = size / 2;
174160
size /= 2;
175161
this.triangles = [
176162
new SierpinskiTriangle({ x, y: y - size / 2, size, targetSize }),
@@ -188,7 +174,7 @@ class SierpinskiTriangle {
188174
class SierpinskiTriangleDot {
189175
hover = false;
190176

191-
constructor(private _x, private _y, private _size) {}
177+
constructor(private readonly _x: number, private readonly _y: number, private readonly _size: number) {}
192178

193179
get x() {
194180
return this._x + 'px';

apps/docs/src/app/containers/component-docs/component-docs.component.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { RouterTestingModule } from '@angular/router/testing';
3+
4+
import { MaterialModule } from '../../material.module';
25

36
import { ComponentDocsComponent } from './component-docs.component';
7+
import { SubNavComponent } from '../../components/components.module';
48

59
describe('ComponentDocsComponent', () => {
610
let component: ComponentDocsComponent;
711
let fixture: ComponentFixture<ComponentDocsComponent>;
812

913
beforeEach(async(() => {
1014
TestBed.configureTestingModule({
11-
declarations: [ComponentDocsComponent],
15+
imports: [RouterTestingModule, MaterialModule],
16+
declarations: [ComponentDocsComponent, SubNavComponent],
1217
}).compileComponents();
1318
}));
1419

0 commit comments

Comments
 (0)