Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 444304a

Browse files
committed
fix(tests): fix units tests throughout app
1 parent 07a1332 commit 444304a

File tree

8 files changed

+337
-1219
lines changed

8 files changed

+337
-1219
lines changed

package-lock.json

Lines changed: 283 additions & 1174 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@
1919
},
2020
"private": true,
2121
"dependencies": {
22-
"@angular/animations": "^5.2.1",
23-
"@angular/cdk": "^5.2.4",
24-
"@angular/common": "^5.2.1",
25-
"@angular/compiler": "^5.2.1",
26-
"@angular/core": "^5.2.1",
27-
"@angular/forms": "^5.2.1",
28-
"@angular/http": "^5.2.1",
29-
"@angular/material": "^5.2.4",
30-
"@angular/material-moment-adapter": "^5.2.4",
31-
"@angular/platform-browser": "^5.2.1",
32-
"@angular/platform-browser-dynamic": "^5.2.1",
33-
"@angular/router": "^5.2.1",
34-
"@angular/service-worker": "^5.2.1",
22+
"@angular/animations": "6.0.0-beta.6",
23+
"@angular/cdk": "6.0.0-beta.4",
24+
"@angular/common": "6.0.0-beta.6",
25+
"@angular/compiler": "6.0.0-beta.6",
26+
"@angular/core": "6.0.0-beta.6",
27+
"@angular/forms": "6.0.0-beta.6",
28+
"@angular/http": "6.0.0-beta.6",
29+
"@angular/material": "6.0.0-beta.4",
30+
"@angular/material-moment-adapter": "6.0.0-beta.4",
31+
"@angular/platform-browser": "6.0.0-beta.6",
32+
"@angular/platform-browser-dynamic": "6.0.0-beta.6",
33+
"@angular/router": "6.0.0-beta.6",
34+
"@angular/service-worker": "6.0.0-beta.6",
3535
"core-js": "^2.4.1",
3636
"moment": "^2.19.1",
3737
"rxjs": "^5.5.0",
3838
"zone.js": "^0.8.4"
3939
},
4040
"devDependencies": {
4141
"@angular/cli": "^1.6.0",
42-
"@angular/compiler-cli": "^5.2.1",
42+
"@angular/compiler-cli": "6.0.0-beta.6",
4343
"@types/jasmine": "^2.5.41",
4444
"@types/node": "^7.0.5",
4545
"firebase-tools": "^3.15.3",

src/app/pages/component-list/component-list.spec.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
22
import {ActivatedRoute} from '@angular/router';
3-
import {Observable} from 'rxjs/Observable';
3+
import {of as observableOf} from 'rxjs/observable/of';
44
import {ComponentList, ComponentListModule} from './component-list';
55
import {DocsAppTestingModule} from '../../testing/testing-module';
66

77
const CATEGORY_ID = 'forms';
8+
const routeWithParams = new ActivatedRoute();
9+
routeWithParams.params = observableOf({
10+
section: 'components',
11+
id: CATEGORY_ID,
12+
});
813
const mockActivatedRoute = {
9-
pathFromRoot: Observable.create(observer => {
10-
observer.next({
11-
params: {
12-
section: 'components',
13-
id: CATEGORY_ID,
14-
}
15-
});
16-
observer.complete();
17-
})
14+
pathFromRoot: [routeWithParams]
1815
};
1916

2017
describe('ComponentList', () => {

src/app/pages/component-sidenav/component-sidenav.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class ComponentNav implements OnInit, OnDestroy {
9393
/** Set the expansions based on the route url */
9494
setExpansions(params: Params) {
9595
const categories = this.docItems.getCategories(params.section);
96-
for (const category of categories) {
96+
for (const category of (categories || [])) {
9797
if (this.expansions[category.id] === true) {
9898
continue;
9999
}

src/app/pages/component-viewer/component-viewer.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {ComponentViewer, ComponentViewerModule} from './component-viewer';
55
import {DocsAppTestingModule} from '../../testing/testing-module';
66

77
import {EXAMPLE_COMPONENTS} from '@angular/material-examples';
8-
import {MatButtonModule} from '@angular/material';
8+
import {MatButtonModule, MatIconModule} from '@angular/material';
99
import {NgModule} from '@angular/core';
1010
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
1111

@@ -17,6 +17,12 @@ const mockActivatedRoute = {
1717
fragment: Observable.create(observer => {
1818
observer.complete();
1919
}),
20+
parent: {
21+
params: Observable.create(observer => {
22+
observer.next({});
23+
observer.complete();
24+
})
25+
},
2026
params: Observable.create(observer => {
2127
observer.next({id: docItemsId});
2228
observer.complete();
@@ -53,6 +59,7 @@ describe('ComponentViewer', () => {
5359
@NgModule({
5460
imports: [
5561
MatButtonModule,
62+
MatIconModule,
5663
NoopAnimationsModule,
5764
],
5865
declarations: [EXAMPLE_COMPONENTS[exampleKey].component],

src/app/shared/footer/footer.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('Footer', () => {
2323
it('should have a link to angular.io', () => {
2424
const link = fixture
2525
.nativeElement
26-
.querySelector('.docs-footer-links a');
26+
.querySelector('.docs-footer-logo a');
2727
const href = link.getAttribute('href');
2828
const text = link.textContent;
2929
expect(href).toContain('angular.io');

src/app/shared/stackblitz/stackblitz-writer.spec.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ describe('StackblitzWriter', () => {
5353

5454
it('should create form element', () => {
5555
expect(stackblitzWriter._createFormElement('index.ts').outerHTML).toBe(
56-
`<form action="https://plnkr.co/edit/?p=preview" method="post" target="_blank"></form>`);
56+
`<form action="https://run.stackblitz.com/api/angular/v1?file=index.ts" ` +
57+
`method="post" target="_blank"></form>`);
5758
});
5859

5960
it('should add files to form input', () => {
@@ -64,37 +65,41 @@ describe('StackblitzWriter', () => {
6465
stackblitzWriter._addFileToForm(form, data, 'Detail', 'src/detail.ts', 'path/to/file');
6566

6667
expect(form.elements.length).toBe(3);
67-
expect(form.elements[0].getAttribute('name')).toBe('files[test.ts]');
68-
expect(form.elements[1].getAttribute('name')).toBe('files[test.html]');
69-
expect(form.elements[2].getAttribute('name')).toBe('files[src/detail.ts]');
68+
expect(form.elements[0].getAttribute('name')).toBe('files[app/test.ts]');
69+
expect(form.elements[1].getAttribute('name')).toBe('files[app/test.html]');
70+
expect(form.elements[2].getAttribute('name')).toBe('files[app/src/detail.ts]');
7071
});
7172

7273
it('should open a new window with stackblitz url', fakeAsync(() => {
7374
let form;
7475
stackblitzWriter.constructStackblitzForm(data).then(result => form = result);
7576
flushMicrotasks();
7677

77-
expect(form.elements.length).toBe(11);
78+
expect(form.elements.length).toBe(14);
7879

7980
// Should have correct tags
8081
expect(form.elements[0].getAttribute('name')).toBe('tags[0]');
8182
expect(form.elements[0].getAttribute('value')).toBe('angular');
83+
expect(form.elements[1].getAttribute('name')).toBe('tags[1]');
8284
expect(form.elements[1].getAttribute('value')).toBe('material');
85+
expect(form.elements[2].getAttribute('name')).toBe('tags[2]');
8386
expect(form.elements[2].getAttribute('value')).toBe('example');
84-
85-
// Should have private and description
87+
88+
// Should bet set as private and have description and dependencies.
8689
expect(form.elements[3].getAttribute('name')).toBe('private');
90+
expect(form.elements[3].getAttribute('value')).toBe('true');
8791
expect(form.elements[4].getAttribute('name')).toBe('description');
88-
89-
// Should have example files
90-
expect(form.elements[5].getAttribute('name')).toBe('files[index.html]');
91-
expect(form.elements[6].getAttribute('name')).toBe('files[systemjs.config.js]');
92-
expect(form.elements[7].getAttribute('name')).toBe('files[main.ts]');
93-
94-
// Should have template files
95-
expect(form.elements[8].getAttribute('name')).toBe('files[test.ts]');
96-
expect(form.elements[9].getAttribute('name')).toBe('files[test.html]');
97-
expect(form.elements[10].getAttribute('name')).toBe('files[src/detail.ts]');
92+
expect(form.elements[5].getAttribute('name')).toBe('dependencies');
93+
94+
// Should have files needed for example.
95+
expect(form.elements[6].getAttribute('name')).toBe('files[index.html]');
96+
expect(form.elements[7].getAttribute('name')).toBe('files[styles.css]');
97+
expect(form.elements[8].getAttribute('name')).toBe('files[polyfills.ts]');
98+
expect(form.elements[9].getAttribute('name')).toBe('files[.angular-cli.json]');
99+
expect(form.elements[10].getAttribute('name')).toBe('files[main.ts]');
100+
expect(form.elements[11].getAttribute('name')).toBe('files[app/test.ts]');
101+
expect(form.elements[12].getAttribute('name')).toBe('files[app/test.html]');
102+
expect(form.elements[13].getAttribute('name')).toBe('files[app/src/detail.ts]');
98103

99104
// TODO(tinagao): Add more test
100105
}));

src/app/shared/stackblitz/stackblitz-writer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export class StackblitzWriter {
195195
// Replace `bootstrap: [MaterialDocsExample]`
196196
// will be replaced as `bootstrap: [ButtonDemo]`
197197
// This assumes the first component listed in the main component
198-
const componentList = data.componentName.split(',')[0];
198+
const componentList = (data.componentName || '').split(',')[0];
199199
fileContent = fileContent.
200200
replace(/bootstrap: \[MaterialDocsExample\]/g,
201201
`bootstrap: [${componentList}]`);

0 commit comments

Comments
 (0)