Skip to content

Commit

Permalink
fix(tests): fix units tests throughout app (angular#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephperrott authored and jelbourn committed Mar 15, 2018
1 parent 07a1332 commit fa29148
Show file tree
Hide file tree
Showing 9 changed files with 342 additions and 1,231 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ env:
- BROWSER_PROVIDER_ERROR_FILE=/tmp/material-angular-io-build/errorfile
matrix:
- MODE=lint
- MODE=e2e
# TODO(josephperrott): Add e2e tests
# - MODE=e2e
- MODE=saucelabs
- MODE=browserstack

Expand Down
1,461 changes: 285 additions & 1,176 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@
"fetch-local": "bash ./tools/fetch-assets-local.sh",
"build-themes": "bash ./tools/build-themes.sh",
"prod-build": "npm run build-themes && ng build --aot --prod",
"postinstall": "webdriver-manager update && bash ./tools/fetch-assets.sh",
"postinstall": "webdriver-manager update && bash ./tools/build-themes.sh && bash ./tools/fetch-assets.sh",
"publish-prod": "bash ./tools/deploy.sh stable prod",
"publish-dev": "bash ./tools/deploy.sh"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.2.1",
"@angular/cdk": "^5.2.4",
"@angular/common": "^5.2.1",
"@angular/compiler": "^5.2.1",
"@angular/core": "^5.2.1",
"@angular/forms": "^5.2.1",
"@angular/http": "^5.2.1",
"@angular/material": "^5.2.4",
"@angular/material-moment-adapter": "^5.2.4",
"@angular/platform-browser": "^5.2.1",
"@angular/platform-browser-dynamic": "^5.2.1",
"@angular/router": "^5.2.1",
"@angular/service-worker": "^5.2.1",
"@angular/animations": "6.0.0-beta.6",
"@angular/cdk": "6.0.0-beta.4",
"@angular/common": "6.0.0-beta.6",
"@angular/compiler": "6.0.0-beta.6",
"@angular/core": "6.0.0-beta.6",
"@angular/forms": "6.0.0-beta.6",
"@angular/http": "6.0.0-beta.6",
"@angular/material": "6.0.0-beta.4",
"@angular/material-moment-adapter": "6.0.0-beta.4",
"@angular/platform-browser": "6.0.0-beta.6",
"@angular/platform-browser-dynamic": "6.0.0-beta.6",
"@angular/router": "6.0.0-beta.6",
"@angular/service-worker": "6.0.0-beta.6",
"core-js": "^2.4.1",
"moment": "^2.19.1",
"rxjs": "^5.5.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "^1.6.0",
"@angular/compiler-cli": "^5.2.1",
"@angular/compiler-cli": "6.0.0-beta.6",
"@types/jasmine": "^2.5.41",
"@types/node": "^7.0.5",
"firebase-tools": "^3.15.3",
Expand Down
17 changes: 7 additions & 10 deletions src/app/pages/component-list/component-list.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {ActivatedRoute} from '@angular/router';
import {Observable} from 'rxjs/Observable';
import {of as observableOf} from 'rxjs/observable/of';
import {ComponentList, ComponentListModule} from './component-list';
import {DocsAppTestingModule} from '../../testing/testing-module';

const CATEGORY_ID = 'forms';
const routeWithParams = new ActivatedRoute();
routeWithParams.params = observableOf({
section: 'components',
id: CATEGORY_ID,
});
const mockActivatedRoute = {
pathFromRoot: Observable.create(observer => {
observer.next({
params: {
section: 'components',
id: CATEGORY_ID,
}
});
observer.complete();
})
pathFromRoot: [routeWithParams]
};

describe('ComponentList', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/component-sidenav/component-sidenav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class ComponentNav implements OnInit, OnDestroy {
/** Set the expansions based on the route url */
setExpansions(params: Params) {
const categories = this.docItems.getCategories(params.section);
for (const category of categories) {
for (const category of (categories || [])) {
if (this.expansions[category.id] === true) {
continue;
}
Expand Down
17 changes: 8 additions & 9 deletions src/app/pages/component-viewer/component-viewer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {ActivatedRoute} from '@angular/router';
import {Observable} from 'rxjs/Observable';
import {of as observableOf} from 'rxjs/observable/of';
import {ComponentViewer, ComponentViewerModule} from './component-viewer';
import {DocsAppTestingModule} from '../../testing/testing-module';

import {EXAMPLE_COMPONENTS} from '@angular/material-examples';
import {MatButtonModule} from '@angular/material';
import {MatButtonModule, MatIconModule} from '@angular/material';
import {NgModule} from '@angular/core';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';

Expand All @@ -14,13 +14,11 @@ const exampleKey = 'button-types';

const mockActivatedRoute = {
snapshot: {},
fragment: Observable.create(observer => {
observer.complete();
}),
params: Observable.create(observer => {
observer.next({id: docItemsId});
observer.complete();
})
fragment: observableOf({}),
parent: {
params: observableOf({})
},
params: observableOf({id: docItemsId})
};

describe('ComponentViewer', () => {
Expand Down Expand Up @@ -53,6 +51,7 @@ describe('ComponentViewer', () => {
@NgModule({
imports: [
MatButtonModule,
MatIconModule,
NoopAnimationsModule,
],
declarations: [EXAMPLE_COMPONENTS[exampleKey].component],
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/footer/footer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Footer', () => {
it('should have a link to angular.io', () => {
const link = fixture
.nativeElement
.querySelector('.docs-footer-links a');
.querySelector('.docs-footer-logo a');
const href = link.getAttribute('href');
const text = link.textContent;
expect(href).toContain('angular.io');
Expand Down
39 changes: 22 additions & 17 deletions src/app/shared/stackblitz/stackblitz-writer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ describe('StackblitzWriter', () => {

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

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

expect(form.elements.length).toBe(3);
expect(form.elements[0].getAttribute('name')).toBe('files[test.ts]');
expect(form.elements[1].getAttribute('name')).toBe('files[test.html]');
expect(form.elements[2].getAttribute('name')).toBe('files[src/detail.ts]');
expect(form.elements[0].getAttribute('name')).toBe('files[app/test.ts]');
expect(form.elements[1].getAttribute('name')).toBe('files[app/test.html]');
expect(form.elements[2].getAttribute('name')).toBe('files[app/src/detail.ts]');
});

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

expect(form.elements.length).toBe(11);
expect(form.elements.length).toBe(14);

// Should have correct tags
expect(form.elements[0].getAttribute('name')).toBe('tags[0]');
expect(form.elements[0].getAttribute('value')).toBe('angular');
expect(form.elements[1].getAttribute('name')).toBe('tags[1]');
expect(form.elements[1].getAttribute('value')).toBe('material');
expect(form.elements[2].getAttribute('name')).toBe('tags[2]');
expect(form.elements[2].getAttribute('value')).toBe('example');

// Should have private and description
// Should bet set as private and have description and dependencies.
expect(form.elements[3].getAttribute('name')).toBe('private');
expect(form.elements[3].getAttribute('value')).toBe('true');
expect(form.elements[4].getAttribute('name')).toBe('description');

// Should have example files
expect(form.elements[5].getAttribute('name')).toBe('files[index.html]');
expect(form.elements[6].getAttribute('name')).toBe('files[systemjs.config.js]');
expect(form.elements[7].getAttribute('name')).toBe('files[main.ts]');

// Should have template files
expect(form.elements[8].getAttribute('name')).toBe('files[test.ts]');
expect(form.elements[9].getAttribute('name')).toBe('files[test.html]');
expect(form.elements[10].getAttribute('name')).toBe('files[src/detail.ts]');
expect(form.elements[5].getAttribute('name')).toBe('dependencies');

// Should have files needed for example.
expect(form.elements[6].getAttribute('name')).toBe('files[index.html]');
expect(form.elements[7].getAttribute('name')).toBe('files[styles.css]');
expect(form.elements[8].getAttribute('name')).toBe('files[polyfills.ts]');
expect(form.elements[9].getAttribute('name')).toBe('files[.angular-cli.json]');
expect(form.elements[10].getAttribute('name')).toBe('files[main.ts]');
expect(form.elements[11].getAttribute('name')).toBe('files[app/test.ts]');
expect(form.elements[12].getAttribute('name')).toBe('files[app/test.html]');
expect(form.elements[13].getAttribute('name')).toBe('files[app/src/detail.ts]');

// TODO(tinagao): Add more test
}));
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/stackblitz/stackblitz-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class StackblitzWriter {
// Replace `bootstrap: [MaterialDocsExample]`
// will be replaced as `bootstrap: [ButtonDemo]`
// This assumes the first component listed in the main component
const componentList = data.componentName.split(',')[0];
const componentList = (data.componentName || '').split(',')[0];
fileContent = fileContent.
replace(/bootstrap: \[MaterialDocsExample\]/g,
`bootstrap: [${componentList}]`);
Expand Down

0 comments on commit fa29148

Please sign in to comment.