parent
e8d0265c1e
commit
02d98ed823
aio
content/examples
http/src/app
testing
e2e/src
src
app
dashboard
demo
model
shared
twain
testing
tools/examples
@ -6,33 +6,35 @@ import { HeroesService } from './heroes.service';
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'app-heroes',
|
selector: 'app-heroes',
|
||||||
templateUrl: './heroes.component.html',
|
templateUrl: './heroes.component.html',
|
||||||
providers: [ HeroesService ],
|
providers: [HeroesService],
|
||||||
styleUrls: ['./heroes.component.css']
|
styleUrls: ['./heroes.component.css']
|
||||||
})
|
})
|
||||||
export class HeroesComponent implements OnInit {
|
export class HeroesComponent implements OnInit {
|
||||||
heroes: Hero[];
|
heroes: Hero[];
|
||||||
editHero: Hero; // the hero currently being edited
|
editHero: Hero; // the hero currently being edited
|
||||||
|
|
||||||
constructor(private heroesService: HeroesService) { }
|
constructor(private heroesService: HeroesService) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.getHeroes();
|
this.getHeroes();
|
||||||
}
|
}
|
||||||
|
|
||||||
getHeroes(): void {
|
getHeroes(): void {
|
||||||
this.heroesService.getHeroes()
|
this.heroesService.getHeroes().subscribe(heroes => (this.heroes = heroes));
|
||||||
.subscribe(heroes => this.heroes = heroes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add(name: string): void {
|
add(name: string): void {
|
||||||
this.editHero = undefined;
|
this.editHero = undefined;
|
||||||
name = name.trim();
|
name = name.trim();
|
||||||
if (!name) { return; }
|
if (!name) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// The server will generate the id for this new hero
|
// The server will generate the id for this new hero
|
||||||
const newHero: Hero = { name } as Hero;
|
const newHero: Hero = { name } as Hero;
|
||||||
// #docregion add-hero-subscribe
|
// #docregion add-hero-subscribe
|
||||||
this.heroesService.addHero(newHero)
|
this.heroesService
|
||||||
|
.addHero(newHero)
|
||||||
.subscribe(hero => this.heroes.push(hero));
|
.subscribe(hero => this.heroes.push(hero));
|
||||||
// #enddocregion add-hero-subscribe
|
// #enddocregion add-hero-subscribe
|
||||||
}
|
}
|
||||||
@ -50,26 +52,28 @@ export class HeroesComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
edit(hero) {
|
edit(hero: Hero) {
|
||||||
this.editHero = hero;
|
this.editHero = hero;
|
||||||
}
|
}
|
||||||
|
|
||||||
search(searchTerm: string) {
|
search(searchTerm: string) {
|
||||||
this.editHero = undefined;
|
this.editHero = undefined;
|
||||||
if (searchTerm) {
|
if (searchTerm) {
|
||||||
this.heroesService.searchHeroes(searchTerm)
|
this.heroesService
|
||||||
.subscribe(heroes => this.heroes = heroes);
|
.searchHeroes(searchTerm)
|
||||||
|
.subscribe(heroes => (this.heroes = heroes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
if (this.editHero) {
|
if (this.editHero) {
|
||||||
this.heroesService.updateHero(this.editHero)
|
this.heroesService.updateHero(this.editHero).subscribe(hero => {
|
||||||
.subscribe(hero => {
|
// replace the hero in the heroes list with update from server
|
||||||
// replace the hero in the heroes list with update from server
|
const ix = hero ? this.heroes.findIndex(h => h.id === hero.id) : -1;
|
||||||
const ix = hero ? this.heroes.findIndex(h => h.id === hero.id) : -1;
|
if (ix > -1) {
|
||||||
if (ix > -1) { this.heroes[ix] = hero; }
|
this.heroes[ix] = hero;
|
||||||
});
|
}
|
||||||
|
});
|
||||||
this.editHero = undefined;
|
this.editHero = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ export class PackageSearchService {
|
|||||||
// TODO: Add error handling
|
// TODO: Add error handling
|
||||||
return this.http.get(searchUrl, options).pipe(
|
return this.http.get(searchUrl, options).pipe(
|
||||||
map((data: any) => {
|
map((data: any) => {
|
||||||
return data.results.map(entry => ({
|
return data.results.map((entry: any) => ({
|
||||||
name: entry.name[0],
|
name: entry.name[0],
|
||||||
version: entry.version[0],
|
version: entry.version[0],
|
||||||
description: entry.description[0]
|
description: entry.description[0]
|
||||||
|
35
aio/content/examples/testing/e2e/src/app.e2e-spec.ts
Normal file
35
aio/content/examples/testing/e2e/src/app.e2e-spec.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
'use strict'; // necessary for es6 output in node
|
||||||
|
|
||||||
|
import { browser, element, by, ElementFinder } from 'protractor';
|
||||||
|
|
||||||
|
describe('Testing Example', () => {
|
||||||
|
const expectedViewNames = ['Dashboard', 'Heroes', 'About'];
|
||||||
|
|
||||||
|
beforeAll(() => browser.get(''));
|
||||||
|
|
||||||
|
function getPageElts() {
|
||||||
|
let navElts = element.all(by.css('app-root nav a'));
|
||||||
|
|
||||||
|
return {
|
||||||
|
navElts: navElts,
|
||||||
|
|
||||||
|
appDashboard: element(by.css('app-root app-dashboard')),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
it('has title', async() => {
|
||||||
|
expect(await browser.getTitle()).toEqual('App Under Test');
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`has views ${expectedViewNames}`, async () => {
|
||||||
|
let viewNames = getPageElts().navElts.map(async(el: ElementFinder) => await el.getText());
|
||||||
|
|
||||||
|
expect(viewNames).toEqual(expectedViewNames);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('has dashboard as the active view', () => {
|
||||||
|
let page = getPageElts();
|
||||||
|
|
||||||
|
expect(page.appDashboard.isPresent()).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -20,7 +20,7 @@ describe('DashboardHeroComponent class only', () => {
|
|||||||
const hero: Hero = { id: 42, name: 'Test' };
|
const hero: Hero = { id: 42, name: 'Test' };
|
||||||
comp.hero = hero;
|
comp.hero = hero;
|
||||||
|
|
||||||
comp.selected.subscribe(selectedHero => expect(selectedHero).toBe(hero));
|
comp.selected.subscribe((selectedHero: Hero) => expect(selectedHero).toBe(hero));
|
||||||
comp.click();
|
comp.click();
|
||||||
});
|
});
|
||||||
// #enddocregion class-only
|
// #enddocregion class-only
|
||||||
@ -95,7 +95,7 @@ describe('DashboardHeroComponent when tested directly', () => {
|
|||||||
// #docregion click-test-3
|
// #docregion click-test-3
|
||||||
it('should raise selected event when clicked (click helper)', () => {
|
it('should raise selected event when clicked (click helper)', () => {
|
||||||
let selectedHero: Hero;
|
let selectedHero: Hero;
|
||||||
comp.selected.subscribe(hero => selectedHero = hero);
|
comp.selected.subscribe((hero: Hero) => selectedHero = hero);
|
||||||
|
|
||||||
click(heroDe); // click helper with DebugElement
|
click(heroDe); // click helper with DebugElement
|
||||||
click(heroEl); // click helper with native element
|
click(heroEl); // click helper with native element
|
||||||
|
@ -19,7 +19,7 @@ export class Hero {
|
|||||||
// #docregion ValueService
|
// #docregion ValueService
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ValueService {
|
export class ValueService {
|
||||||
protected value = 'real value';
|
value = 'real value';
|
||||||
|
|
||||||
getValue() { return this.value; }
|
getValue() { return this.value; }
|
||||||
setValue(value: string) { this.value = value; }
|
setValue(value: string) { this.value = value; }
|
||||||
|
@ -2,7 +2,3 @@ export interface Hero {
|
|||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SystemJS bug:
|
|
||||||
// TS file must export something real in JS, not just interfaces
|
|
||||||
export const _dummy = undefined;
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Component, AfterViewInit, ViewChild } from '@angular/core';
|
import { Component, AfterViewInit, ViewChild, ElementRef } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'sample-canvas',
|
selector: 'sample-canvas',
|
||||||
@ -6,7 +6,7 @@ import { Component, AfterViewInit, ViewChild } from '@angular/core';
|
|||||||
})
|
})
|
||||||
export class CanvasComponent implements AfterViewInit {
|
export class CanvasComponent implements AfterViewInit {
|
||||||
blobSize: number;
|
blobSize: number;
|
||||||
@ViewChild('sampleCanvas', {static: false}) sampleCanvas;
|
@ViewChild('sampleCanvas', {static: false}) sampleCanvas: ElementRef;
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import { FormsModule } from '@angular/forms';
|
|||||||
|
|
||||||
import { HighlightDirective } from './highlight.directive';
|
import { HighlightDirective } from './highlight.directive';
|
||||||
import { TitleCasePipe } from './title-case.pipe';
|
import { TitleCasePipe } from './title-case.pipe';
|
||||||
|
import { CanvasComponent } from './canvas.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [ CommonModule ],
|
imports: [ CommonModule ],
|
||||||
@ -12,8 +13,9 @@ import { TitleCasePipe } from './title-case.pipe';
|
|||||||
// SharedModule importers won't have to import FormsModule too
|
// SharedModule importers won't have to import FormsModule too
|
||||||
FormsModule,
|
FormsModule,
|
||||||
HighlightDirective,
|
HighlightDirective,
|
||||||
TitleCasePipe
|
TitleCasePipe,
|
||||||
|
CanvasComponent
|
||||||
],
|
],
|
||||||
declarations: [ HighlightDirective, TitleCasePipe ]
|
declarations: [ HighlightDirective, TitleCasePipe, CanvasComponent ]
|
||||||
})
|
})
|
||||||
export class SharedModule { }
|
export class SharedModule { }
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
||||||
|
|
||||||
import { Observable, of, throwError } from 'rxjs';
|
import { Observable, of, throwError, Observer } from 'rxjs';
|
||||||
import { concat, map, retryWhen, switchMap, take, tap } from 'rxjs/operators';
|
import { concat, map, retryWhen, switchMap, take, tap } from 'rxjs/operators';
|
||||||
|
|
||||||
import { Quote } from './quote';
|
import { Quote } from './quote';
|
||||||
@ -14,7 +14,7 @@ export class TwainService {
|
|||||||
private nextId = 1;
|
private nextId = 1;
|
||||||
|
|
||||||
getQuote(): Observable<string> {
|
getQuote(): Observable<string> {
|
||||||
return Observable.create(observer => observer.next(this.nextId++)).pipe(
|
return Observable.create((observer: Observer<number>) => observer.next(this.nextId++)).pipe(
|
||||||
|
|
||||||
// tap((id: number) => console.log(id)),
|
// tap((id: number) => console.log(id)),
|
||||||
// tap((id: number) => { throw new Error('Simulated server error'); }),
|
// tap((id: number) => { throw new Error('Simulated server error'); }),
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
import jasmineRequire from 'jasmine-core/lib/jasmine-core/jasmine.js';
|
const jasmineRequire = require('jasmine-core/lib/jasmine-core/jasmine.js');
|
||||||
|
|
||||||
window['jasmineRequire'] = jasmineRequire;
|
window['jasmineRequire'] = jasmineRequire;
|
||||||
|
@ -36,8 +36,8 @@ BOILERPLATE_PATHS['service-worker'] = [...cliRelativePath, 'angular.json', 'pack
|
|||||||
BOILERPLATE_PATHS.testing = [
|
BOILERPLATE_PATHS.testing = [
|
||||||
...cliRelativePath,
|
...cliRelativePath,
|
||||||
'angular.json',
|
'angular.json',
|
||||||
'src/tsconfig.app.json',
|
'tsconfig.app.json',
|
||||||
'src/tsconfig.spec.json'
|
'tsconfig.spec.json'
|
||||||
];
|
];
|
||||||
|
|
||||||
BOILERPLATE_PATHS.universal = [...cliRelativePath, 'angular.json', 'package.json'];
|
BOILERPLATE_PATHS.universal = [...cliRelativePath, 'angular.json', 'package.json'];
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
"@types/node": "~8.9.4",
|
"@types/node": "~8.9.4",
|
||||||
"codelyzer": "~5.0.0",
|
"codelyzer": "~5.0.0",
|
||||||
"jasmine-core": "~2.99.1",
|
"jasmine-core": "~2.99.1",
|
||||||
"jasmine-marbles": "^0.5.0",
|
"jasmine-marbles": "^0.6.0",
|
||||||
"jasmine-spec-reporter": "~4.2.1",
|
"jasmine-spec-reporter": "~4.2.1",
|
||||||
"karma": "~4.1.0",
|
"karma": "~4.1.0",
|
||||||
"karma-chrome-launcher": "~2.2.0",
|
"karma-chrome-launcher": "~2.2.0",
|
||||||
|
@ -66,7 +66,7 @@ import 'core-js/es7/reflect';
|
|||||||
* Zone JS is required by default for Angular itself.
|
* Zone JS is required by default for Angular itself.
|
||||||
*/
|
*/
|
||||||
import 'zone.js/dist/zone'; // Included with Angular CLI.
|
import 'zone.js/dist/zone'; // Included with Angular CLI.
|
||||||
|
import 'zone.js/dist/zone-patch-canvas';
|
||||||
|
|
||||||
/***************************************************************************************************
|
/***************************************************************************************************
|
||||||
* APPLICATION IMPORTS
|
* APPLICATION IMPORTS
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
"@types/node": "~8.9.4",
|
"@types/node": "~8.9.4",
|
||||||
"codelyzer": "~5.0.0",
|
"codelyzer": "~5.0.0",
|
||||||
"jasmine-core": "~2.99.1",
|
"jasmine-core": "~2.99.1",
|
||||||
"jasmine-marbles": "^0.5.0",
|
"jasmine-marbles": "^0.6.0",
|
||||||
"jasmine-spec-reporter": "~4.2.1",
|
"jasmine-spec-reporter": "~4.2.1",
|
||||||
"karma": "~4.1.0",
|
"karma": "~4.1.0",
|
||||||
"karma-chrome-launcher": "~2.2.0",
|
"karma-chrome-launcher": "~2.2.0",
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
"exclude": [
|
"exclude": [
|
||||||
"src/test.ts",
|
"src/test.ts",
|
||||||
"src/**/*.spec.ts",
|
"src/**/*.spec.ts",
|
||||||
|
"src/**/*-specs.ts",
|
||||||
"src/**/*.avoid.ts",
|
"src/**/*.avoid.ts",
|
||||||
"src/**/*.0.ts",
|
"src/**/*.0.ts",
|
||||||
"src/**/*.1.ts",
|
"src/**/*.1.ts",
|
||||||
@ -19,7 +20,8 @@
|
|||||||
"src/**/*.4.ts",
|
"src/**/*.4.ts",
|
||||||
"src/**/*.5.ts",
|
"src/**/*.5.ts",
|
||||||
"src/**/*.6.ts",
|
"src/**/*.6.ts",
|
||||||
"src/**/*.7.ts"
|
"src/**/*.7.ts",
|
||||||
|
"src/**/testing"
|
||||||
],
|
],
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
"enableIvy": true
|
"enableIvy": true
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
"@types/node": "~8.9.4",
|
"@types/node": "~8.9.4",
|
||||||
"codelyzer": "~5.0.0",
|
"codelyzer": "~5.0.0",
|
||||||
"jasmine-core": "~2.99.1",
|
"jasmine-core": "~2.99.1",
|
||||||
"jasmine-marbles": "^0.5.0",
|
"jasmine-marbles": "^0.6.0",
|
||||||
"jasmine-spec-reporter": "~4.2.1",
|
"jasmine-spec-reporter": "~4.2.1",
|
||||||
"karma": "~4.1.0",
|
"karma": "~4.1.0",
|
||||||
"karma-chrome-launcher": "~2.2.0",
|
"karma-chrome-launcher": "~2.2.0",
|
||||||
|
@ -23,7 +23,8 @@
|
|||||||
"src/assets"
|
"src/assets"
|
||||||
],
|
],
|
||||||
"styles": [
|
"styles": [
|
||||||
"src/styles.css"
|
"src/styles.css",
|
||||||
|
"src/test.css"
|
||||||
],
|
],
|
||||||
"scripts": []
|
"scripts": []
|
||||||
},
|
},
|
||||||
@ -83,8 +84,7 @@
|
|||||||
"src/assets"
|
"src/assets"
|
||||||
],
|
],
|
||||||
"styles": [
|
"styles": [
|
||||||
"src/styles.css",
|
"src/styles.css"
|
||||||
"src/test.css"
|
|
||||||
],
|
],
|
||||||
"scripts": []
|
"scripts": []
|
||||||
}
|
}
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "../out-tsc/app",
|
|
||||||
"types": []
|
|
||||||
},
|
|
||||||
"exclude": [
|
|
||||||
"test.ts",
|
|
||||||
"**/*.spec.ts",
|
|
||||||
"**/*.avoid.ts",
|
|
||||||
"**/*.0.ts",
|
|
||||||
"**/*.1.ts",
|
|
||||||
"**/*.1b.ts",
|
|
||||||
"**/*.2.ts",
|
|
||||||
"**/*.3.ts",
|
|
||||||
"**/*.4.ts",
|
|
||||||
"**/*.5.ts",
|
|
||||||
"**/*.6.ts",
|
|
||||||
"**/*.7.ts",
|
|
||||||
"**/testing"
|
|
||||||
]
|
|
||||||
}
|
|
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"extends": "../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../out-tsc/app",
|
||||||
|
"types": []
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*.ts"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"src/test.ts",
|
||||||
|
"src/**/*.spec.ts",
|
||||||
|
"src/**/*-specs.ts",
|
||||||
|
"src/**/*.avoid.ts",
|
||||||
|
"src/**/*.0.ts",
|
||||||
|
"src/**/*.1.ts",
|
||||||
|
"src/**/*.1b.ts",
|
||||||
|
"src/**/*.2.ts",
|
||||||
|
"src/**/*.3.ts",
|
||||||
|
"src/**/*.4.ts",
|
||||||
|
"src/**/*.5.ts",
|
||||||
|
"src/**/*.6.ts",
|
||||||
|
"src/**/*.7.ts",
|
||||||
|
"src/**/testing"
|
||||||
|
]
|
||||||
|
}
|
@ -12,8 +12,8 @@
|
|||||||
"polyfills.ts"
|
"polyfills.ts"
|
||||||
],
|
],
|
||||||
"include": [
|
"include": [
|
||||||
"**/*.spec.ts",
|
"src/**/*.spec.ts",
|
||||||
"**/*.d.ts",
|
"src/**/*.d.ts",
|
||||||
"**/testing"
|
"src/testing"
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -61,7 +61,7 @@
|
|||||||
"concurrently": "^3.0.0",
|
"concurrently": "^3.0.0",
|
||||||
"http-server": "^0.11.1",
|
"http-server": "^0.11.1",
|
||||||
"jasmine-core": "~3.4.0",
|
"jasmine-core": "~3.4.0",
|
||||||
"jasmine-marbles": "^0.5.0",
|
"jasmine-marbles": "^0.6.0",
|
||||||
"jasmine-spec-reporter": "~4.2.1",
|
"jasmine-spec-reporter": "~4.2.1",
|
||||||
"karma": "~4.1.0",
|
"karma": "~4.1.0",
|
||||||
"karma-chrome-launcher": "~2.2.0",
|
"karma-chrome-launcher": "~2.2.0",
|
||||||
|
@ -4264,10 +4264,10 @@ jasmine-core@~2.8.0:
|
|||||||
version "2.8.0"
|
version "2.8.0"
|
||||||
resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-2.8.0.tgz#bcc979ae1f9fd05701e45e52e65d3a5d63f1a24e"
|
resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-2.8.0.tgz#bcc979ae1f9fd05701e45e52e65d3a5d63f1a24e"
|
||||||
|
|
||||||
jasmine-marbles@^0.5.0:
|
jasmine-marbles@^0.6.0:
|
||||||
version "0.5.0"
|
version "0.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/jasmine-marbles/-/jasmine-marbles-0.5.0.tgz#5d4c51082fcf619bb8dbc85583cb11718a32b200"
|
resolved "https://registry.yarnpkg.com/jasmine-marbles/-/jasmine-marbles-0.6.0.tgz#f78dc1a3bc452976de10ee8b47c73d616532a954"
|
||||||
integrity sha512-hkSYy7VJpcxaKE48s/CasVpGyheElp5ZegguFi5kpYAaUWsyOko6RnMZS1kv14ThMtlJVNqCW5z16f1q6HqbEg==
|
integrity sha512-1uzgjEesEeCb+r+v46qn5x326TiGqk5SUZa+A3O+XnMCjG/pGcUOhL9Xsg5L7gLC6RFHyWGTkB5fei4rcvIOiQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
lodash "^4.5.0"
|
lodash "^4.5.0"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user