940 lines
32 KiB
HTML
940 lines
32 KiB
HTML
|
<html lang="en"><head></head><body>
|
||
|
<form id="mainForm" method="post" action="https://run.stackblitz.com/api/angular/v1?file=src/app/app.component.html" target="_self"><input type="hidden" name="files[src/app/heroes/hero.ts]" value="export interface Hero {
|
||
|
id: number;
|
||
|
name: string;
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[src/app/heroes/heroes.service.ts]" value="import { Injectable } from '@angular/core';
|
||
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
||
|
import { HttpHeaders } from '@angular/common/http';
|
||
|
|
||
|
|
||
|
import { Observable } from 'rxjs';
|
||
|
import { catchError } from 'rxjs/operators';
|
||
|
|
||
|
import { Hero } from './hero';
|
||
|
import { HttpErrorHandler, HandleError } from '../http-error-handler.service';
|
||
|
|
||
|
const httpOptions = {
|
||
|
headers: new HttpHeaders({
|
||
|
'Content-Type': 'application/json',
|
||
|
Authorization: 'my-auth-token'
|
||
|
})
|
||
|
};
|
||
|
|
||
|
@Injectable()
|
||
|
export class HeroesService {
|
||
|
heroesUrl = 'api/heroes'; // URL to web api
|
||
|
private handleError: HandleError;
|
||
|
|
||
|
constructor(
|
||
|
private http: HttpClient,
|
||
|
httpErrorHandler: HttpErrorHandler) {
|
||
|
this.handleError = httpErrorHandler.createHandleError('HeroesService');
|
||
|
}
|
||
|
|
||
|
/** GET heroes from the server */
|
||
|
getHeroes(): Observable<Hero[]> {
|
||
|
return this.http.get<Hero[]>(this.heroesUrl)
|
||
|
.pipe(
|
||
|
catchError(this.handleError('getHeroes', []))
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/* GET heroes whose name contains search term */
|
||
|
searchHeroes(term: string): Observable<Hero[]> {
|
||
|
term = term.trim();
|
||
|
|
||
|
// Add safe, URL encoded search parameter if there is a search term
|
||
|
const options = term ?
|
||
|
{ params: new HttpParams().set('name', term) } : {};
|
||
|
|
||
|
return this.http.get<Hero[]>(this.heroesUrl, options)
|
||
|
.pipe(
|
||
|
catchError(this.handleError<Hero[]>('searchHeroes', []))
|
||
|
);
|
||
|
}
|
||
|
|
||
|
//////// Save methods //////////
|
||
|
|
||
|
/** POST: add a new hero to the database */
|
||
|
addHero(hero: Hero): Observable<Hero> {
|
||
|
return this.http.post<Hero>(this.heroesUrl, hero, httpOptions)
|
||
|
.pipe(
|
||
|
catchError(this.handleError('addHero', hero))
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/** DELETE: delete the hero from the server */
|
||
|
deleteHero(id: number): Observable<{}> {
|
||
|
const url = `${this.heroesUrl}/${id}`; // DELETE api/heroes/42
|
||
|
return this.http.delete(url, httpOptions)
|
||
|
.pipe(
|
||
|
catchError(this.handleError('deleteHero'))
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/** PUT: update the hero on the server. Returns the updated hero upon success. */
|
||
|
updateHero(hero: Hero): Observable<Hero> {
|
||
|
httpOptions.headers =
|
||
|
httpOptions.headers.set('Authorization', 'my-new-auth-token');
|
||
|
|
||
|
return this.http.put<Hero>(this.heroesUrl, hero, httpOptions)
|
||
|
.pipe(
|
||
|
catchError(this.handleError('updateHero', hero))
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[src/app/heroes/heroes.service.spec.ts]" value="import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
||
|
|
||
|
// Other imports
|
||
|
import { TestBed } from '@angular/core/testing';
|
||
|
import { HttpClient, HttpResponse } from '@angular/common/http';
|
||
|
|
||
|
import { Hero } from './hero';
|
||
|
import { HeroesService } from './heroes.service';
|
||
|
import { HttpErrorHandler } from '../http-error-handler.service';
|
||
|
import { MessageService } from '../message.service';
|
||
|
|
||
|
describe('HeroesService', () => {
|
||
|
let httpClient: HttpClient;
|
||
|
let httpTestingController: HttpTestingController;
|
||
|
let heroService: HeroesService;
|
||
|
|
||
|
beforeEach(() => {
|
||
|
TestBed.configureTestingModule({
|
||
|
// Import the HttpClient mocking services
|
||
|
imports: [ HttpClientTestingModule ],
|
||
|
// Provide the service-under-test and its dependencies
|
||
|
providers: [
|
||
|
HeroesService,
|
||
|
HttpErrorHandler,
|
||
|
MessageService
|
||
|
]
|
||
|
});
|
||
|
|
||
|
// Inject the http, test controller, and service-under-test
|
||
|
// as they will be referenced by each test.
|
||
|
httpClient = TestBed.inject(HttpClient);
|
||
|
httpTestingController = TestBed.inject(HttpTestingController);
|
||
|
heroService = TestBed.inject(HeroesService);
|
||
|
});
|
||
|
|
||
|
afterEach(() => {
|
||
|
// After every test, assert that there are no more pending requests.
|
||
|
httpTestingController.verify();
|
||
|
});
|
||
|
|
||
|
/// HeroService method tests begin ///
|
||
|
|
||
|
describe('#getHeroes', () => {
|
||
|
let expectedHeroes: Hero[];
|
||
|
|
||
|
beforeEach(() => {
|
||
|
heroService = TestBed.inject(HeroesService);
|
||
|
expectedHeroes = [
|
||
|
{ id: 1, name: 'A' },
|
||
|
{ id: 2, name: 'B' },
|
||
|
] as Hero[];
|
||
|
});
|
||
|
|
||
|
it('should return expected heroes (called once)', () => {
|
||
|
|
||
|
heroService.getHeroes().subscribe(
|
||
|
heroes => expect(heroes).toEqual(expectedHeroes, 'should return expected heroes'),
|
||
|
fail
|
||
|
);
|
||
|
|
||
|
// HeroService should have made one request to GET heroes from expected URL
|
||
|
const req = httpTestingController.expectOne(heroService.heroesUrl);
|
||
|
expect(req.request.method).toEqual('GET');
|
||
|
|
||
|
// Respond with the mock heroes
|
||
|
req.flush(expectedHeroes);
|
||
|
});
|
||
|
|
||
|
it('should be OK returning no heroes', () => {
|
||
|
|
||
|
heroService.getHeroes().subscribe(
|
||
|
heroes => expect(heroes.length).toEqual(0, 'should have empty heroes array'),
|
||
|
fail
|
||
|
);
|
||
|
|
||
|
const req = httpTestingController.expectOne(heroService.heroesUrl);
|
||
|
req.flush([]); // Respond with no heroes
|
||
|
});
|
||
|
|
||
|
// This service reports the error but finds a way to let the app keep going.
|
||
|
it('should turn 404 into an empty heroes result', () => {
|
||
|
|
||
|
heroService.getHeroes().subscribe(
|
||
|
heroes => expect(heroes.length).toEqual(0, 'should return empty heroes array'),
|
||
|
fail
|
||
|
);
|
||
|
|
||
|
const req = httpTestingController.expectOne(heroService.heroesUrl);
|
||
|
|
||
|
// respond with a 404 and the error message in the body
|
||
|
const msg = 'deliberate 404 error';
|
||
|
req.flush(msg, {status: 404, statusText: 'Not Found'});
|
||
|
});
|
||
|
|
||
|
it('should return expected heroes (called multiple times)', () => {
|
||
|
|
||
|
heroService.getHeroes().subscribe();
|
||
|
heroService.getHeroes().subscribe();
|
||
|
heroService.getHeroes().subscribe(
|
||
|
heroes => expect(heroes).toEqual(expectedHeroes, 'should return expected heroes'),
|
||
|
fail
|
||
|
);
|
||
|
|
||
|
const requests = httpTestingController.match(heroService.heroesUrl);
|
||
|
expect(requests.length).toEqual(3, 'calls to getHeroes()');
|
||
|
|
||
|
// Respond to each request with different mock hero results
|
||
|
requests[0].flush([]);
|
||
|
requests[1].flush([{id: 1, name: 'bob'}]);
|
||
|
requests[2].flush(expectedHeroes);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('#updateHero', () => {
|
||
|
// Expecting the query form of URL so should not 404 when id not found
|
||
|
const makeUrl = (id: number) => `${heroService.heroesUrl}/?id=${id}`;
|
||
|
|
||
|
it('should update a hero and return it', () => {
|
||
|
|
||
|
const updateHero: Hero = { id: 1, name: 'A' };
|
||
|
|
||
|
heroService.updateHero(updateHero).subscribe(
|
||
|
data => expect(data).toEqual(updateHero, 'should return the hero'),
|
||
|
fail
|
||
|
);
|
||
|
|
||
|
// HeroService should have made one request to PUT hero
|
||
|
const req = httpTestingController.expectOne(heroService.heroesUrl);
|
||
|
expect(req.request.method).toEqual('PUT');
|
||
|
expect(req.request.body).toEqual(updateHero);
|
||
|
|
||
|
// Expect server to return the hero after PUT
|
||
|
const expectedResponse = new HttpResponse(
|
||
|
{ status: 200, statusText: 'OK', body: updateHero });
|
||
|
req.event(expectedResponse);
|
||
|
});
|
||
|
|
||
|
// This service reports the error but finds a way to let the app keep going.
|
||
|
it('should turn 404 error into return of the update hero', () => {
|
||
|
const updateHero: Hero = { id: 1, name: 'A' };
|
||
|
|
||
|
heroService.updateHero(updateHero).subscribe(
|
||
|
data => expect(data).toEqual(updateHero, 'should return the update hero'),
|
||
|
fail
|
||
|
);
|
||
|
|
||
|
const req = httpTestingController.expectOne(heroService.heroesUrl);
|
||
|
|
||
|
// respond with a 404 and the error message in the body
|
||
|
const msg = 'deliberate 404 error';
|
||
|
req.flush(msg, {status: 404, statusText: 'Not Found'});
|
||
|
});
|
||
|
});
|
||
|
|
||
|
// TODO: test other HeroService methods
|
||
|
});
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[src/app/http-error-handler.service.ts]" value="import { Injectable } from '@angular/core';
|
||
|
import { HttpErrorResponse } from '@angular/common/http';
|
||
|
|
||
|
import { Observable, of } from 'rxjs';
|
||
|
|
||
|
import { MessageService } from './message.service';
|
||
|
|
||
|
/** Type of the handleError function returned by HttpErrorHandler.createHandleError */
|
||
|
export type HandleError =
|
||
|
<T> (operation?: string, result?: T) => (error: HttpErrorResponse) => Observable<T>;
|
||
|
|
||
|
/** Handles HttpClient errors */
|
||
|
@Injectable()
|
||
|
export class HttpErrorHandler {
|
||
|
constructor(private messageService: MessageService) { }
|
||
|
|
||
|
/** Create curried handleError function that already knows the service name */
|
||
|
createHandleError = (serviceName = '') => {
|
||
|
return <T>(operation = 'operation', result = {} as T) =>
|
||
|
this.handleError(serviceName, operation, result);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns a function that handles Http operation failures.
|
||
|
* This error handler lets the app continue to run as if no error occurred.
|
||
|
* @param serviceName = name of the data service that attempted the operation
|
||
|
* @param operation - name of the operation that failed
|
||
|
* @param result - optional value to return as the observable result
|
||
|
*/
|
||
|
handleError<T>(serviceName = '', operation = 'operation', result = {} as T) {
|
||
|
|
||
|
return (error: HttpErrorResponse): Observable<T> => {
|
||
|
// TODO: send the error to remote logging infrastructure
|
||
|
console.error(error); // log to console instead
|
||
|
|
||
|
const message = (error.error instanceof ErrorEvent) ?
|
||
|
error.error.message :
|
||
|
`server returned code ${error.status} with body "${error.error}"`;
|
||
|
|
||
|
// TODO: better job of transforming error for user consumption
|
||
|
this.messageService.add(`${serviceName}: ${operation} failed: ${message}`);
|
||
|
|
||
|
// Let the app keep running by returning a safe result.
|
||
|
return of( result );
|
||
|
};
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[src/app/message.service.ts]" value="import { Injectable } from '@angular/core';
|
||
|
|
||
|
@Injectable()
|
||
|
export class MessageService {
|
||
|
messages: string[] = [];
|
||
|
|
||
|
add(message: string) {
|
||
|
this.messages.push(message);
|
||
|
}
|
||
|
|
||
|
clear() {
|
||
|
this.messages = [];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[src/testing/global-jasmine.ts]" value="import jasmineRequire from 'jasmine-core/lib/jasmine-core/jasmine.js';
|
||
|
|
||
|
(window as any).jasmineRequire = jasmineRequire;
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[src/testing/http-client.spec.ts]" value="// Http testing module and mocking controller
|
||
|
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
||
|
|
||
|
// Other imports
|
||
|
import { TestBed } from '@angular/core/testing';
|
||
|
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
||
|
|
||
|
import { HttpHeaders } from '@angular/common/http';
|
||
|
|
||
|
interface Data {
|
||
|
name: string;
|
||
|
}
|
||
|
|
||
|
const testUrl = '/data';
|
||
|
|
||
|
describe('HttpClient testing', () => {
|
||
|
let httpClient: HttpClient;
|
||
|
let httpTestingController: HttpTestingController;
|
||
|
|
||
|
beforeEach(() => {
|
||
|
TestBed.configureTestingModule({
|
||
|
imports: [ HttpClientTestingModule ]
|
||
|
});
|
||
|
|
||
|
// Inject the http service and test controller for each test
|
||
|
httpClient = TestBed.inject(HttpClient);
|
||
|
httpTestingController = TestBed.inject(HttpTestingController);
|
||
|
});
|
||
|
afterEach(() => {
|
||
|
// After every test, assert that there are no more pending requests.
|
||
|
httpTestingController.verify();
|
||
|
});
|
||
|
/// Tests begin ///
|
||
|
it('can test HttpClient.get', () => {
|
||
|
const testData: Data = {name: 'Test Data'};
|
||
|
|
||
|
// Make an HTTP GET request
|
||
|
httpClient.get<Data>(testUrl)
|
||
|
.subscribe(data =>
|
||
|
// When observable resolves, result should match test data
|
||
|
expect(data).toEqual(testData)
|
||
|
);
|
||
|
|
||
|
// The following `expectOne()` will match the request's URL.
|
||
|
// If no requests or multiple requests matched that URL
|
||
|
// `expectOne()` would throw.
|
||
|
const req = httpTestingController.expectOne('/data');
|
||
|
|
||
|
// Assert that the request is a GET.
|
||
|
expect(req.request.method).toEqual('GET');
|
||
|
|
||
|
// Respond with mock data, causing Observable to resolve.
|
||
|
// Subscribe callback asserts that correct data was returned.
|
||
|
req.flush(testData);
|
||
|
|
||
|
// Finally, assert that there are no outstanding requests.
|
||
|
httpTestingController.verify();
|
||
|
});
|
||
|
|
||
|
it('can test HttpClient.get with matching header', () => {
|
||
|
const testData: Data = {name: 'Test Data'};
|
||
|
|
||
|
// Make an HTTP GET request with specific header
|
||
|
httpClient.get<Data>(testUrl, {
|
||
|
headers: new HttpHeaders({Authorization: 'my-auth-token'})
|
||
|
})
|
||
|
.subscribe(data =>
|
||
|
expect(data).toEqual(testData)
|
||
|
);
|
||
|
|
||
|
// Find request with a predicate function.
|
||
|
// Expect one request with an authorization header
|
||
|
const req = httpTestingController.expectOne(
|
||
|
request => request.headers.has('Authorization')
|
||
|
);
|
||
|
req.flush(testData);
|
||
|
});
|
||
|
|
||
|
it('can test multiple requests', () => {
|
||
|
const testData: Data[] = [
|
||
|
{ name: 'bob' }, { name: 'carol' },
|
||
|
{ name: 'ted' }, { name: 'alice' }
|
||
|
];
|
||
|
|
||
|
// Make three requests in a row
|
||
|
httpClient.get<Data[]>(testUrl)
|
||
|
.subscribe(d => expect(d.length).toEqual(0, 'should have no data'));
|
||
|
|
||
|
httpClient.get<Data[]>(testUrl)
|
||
|
.subscribe(d => expect(d).toEqual([testData[0]], 'should be one element array'));
|
||
|
|
||
|
httpClient.get<Data[]>(testUrl)
|
||
|
.subscribe(d => expect(d).toEqual(testData, 'should be expected data'));
|
||
|
|
||
|
// get all pending requests that match the given URL
|
||
|
const requests = httpTestingController.match(testUrl);
|
||
|
expect(requests.length).toEqual(3);
|
||
|
|
||
|
// Respond to each request with different results
|
||
|
requests[0].flush([]);
|
||
|
requests[1].flush([testData[0]]);
|
||
|
requests[2].flush(testData);
|
||
|
});
|
||
|
|
||
|
it('can test for 404 error', () => {
|
||
|
const emsg = 'deliberate 404 error';
|
||
|
|
||
|
httpClient.get<Data[]>(testUrl).subscribe(
|
||
|
data => fail('should have failed with the 404 error'),
|
||
|
(error: HttpErrorResponse) => {
|
||
|
expect(error.status).toEqual(404, 'status');
|
||
|
expect(error.error).toEqual(emsg, 'message');
|
||
|
}
|
||
|
);
|
||
|
|
||
|
const req = httpTestingController.expectOne(testUrl);
|
||
|
|
||
|
// Respond with mock error
|
||
|
req.flush(emsg, { status: 404, statusText: 'Not Found' });
|
||
|
});
|
||
|
|
||
|
it('can test for network error', () => {
|
||
|
const emsg = 'simulated network error';
|
||
|
|
||
|
httpClient.get<Data[]>(testUrl).subscribe(
|
||
|
data => fail('should have failed with the network error'),
|
||
|
(error: HttpErrorResponse) => {
|
||
|
expect(error.error.message).toEqual(emsg, 'message');
|
||
|
}
|
||
|
);
|
||
|
|
||
|
const req = httpTestingController.expectOne(testUrl);
|
||
|
|
||
|
// Create mock ErrorEvent, raised when something goes wrong at the network level.
|
||
|
// Connection timeout, DNS error, offline, etc
|
||
|
const mockError = new ErrorEvent('Network error', {
|
||
|
message: emsg,
|
||
|
// The rest of this is optional and not used.
|
||
|
// Just showing that you could provide this too.
|
||
|
filename: 'HeroService.ts',
|
||
|
lineno: 42,
|
||
|
colno: 21
|
||
|
});
|
||
|
|
||
|
// Respond with mock error
|
||
|
req.error(mockError);
|
||
|
});
|
||
|
|
||
|
it('httpTestingController.verify should fail if HTTP response not simulated', () => {
|
||
|
// Sends request
|
||
|
httpClient.get('some/api').subscribe();
|
||
|
|
||
|
// verify() should fail because haven't handled the pending request.
|
||
|
expect(() => httpTestingController.verify()).toThrow();
|
||
|
|
||
|
// Now get and flush the request so that afterEach() doesn't fail
|
||
|
const req = httpTestingController.expectOne('some/api');
|
||
|
req.flush(null);
|
||
|
});
|
||
|
|
||
|
// Proves that verify in afterEach() really would catch error
|
||
|
// if test doesn't simulate the HTTP response.
|
||
|
//
|
||
|
// Must disable this test because can't catch an error in an afterEach().
|
||
|
// Uncomment if you want to confirm that afterEach() does the job.
|
||
|
// it('afterEach() should fail when HTTP response not simulated',() => {
|
||
|
// // Sends request which is never handled by this test
|
||
|
// httpClient.get('some/api').subscribe();
|
||
|
// });
|
||
|
});
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[src/styles.css]" value="/* Global Styles */
|
||
|
* {
|
||
|
font-family: Arial, Helvetica, sans-serif;
|
||
|
}
|
||
|
h1 {
|
||
|
color: #264D73;
|
||
|
font-size: 2.5rem;
|
||
|
}
|
||
|
h2, h3 {
|
||
|
color: #444;
|
||
|
font-weight: lighter;
|
||
|
}
|
||
|
h3 {
|
||
|
font-size: 1.3rem;
|
||
|
}
|
||
|
body {
|
||
|
padding: .5rem;
|
||
|
max-width: 1000px;
|
||
|
margin: auto;
|
||
|
}
|
||
|
@media (min-width: 600px) {
|
||
|
body {
|
||
|
padding: 2rem;
|
||
|
}
|
||
|
}
|
||
|
body, input[text] {
|
||
|
color: #333;
|
||
|
font-family: Cambria, Georgia, serif;
|
||
|
}
|
||
|
a {
|
||
|
cursor: pointer;
|
||
|
}
|
||
|
button {
|
||
|
background-color: #eee;
|
||
|
border: none;
|
||
|
border-radius: 4px;
|
||
|
cursor: pointer;
|
||
|
color: black;
|
||
|
font-size: 1.2rem;
|
||
|
padding: 1rem;
|
||
|
margin-right: 1rem;
|
||
|
margin-bottom: 1rem;
|
||
|
}
|
||
|
button:hover {
|
||
|
background-color: black;
|
||
|
color: white;
|
||
|
}
|
||
|
button:disabled {
|
||
|
background-color: #eee;
|
||
|
color: #aaa;
|
||
|
cursor: auto;
|
||
|
}
|
||
|
|
||
|
/* Navigation link styles */
|
||
|
nav a {
|
||
|
padding: 5px 10px;
|
||
|
text-decoration: none;
|
||
|
margin-right: 10px;
|
||
|
margin-top: 10px;
|
||
|
display: inline-block;
|
||
|
background-color: #e8e8e8;
|
||
|
color: #3d3d3d;
|
||
|
border-radius: 4px;
|
||
|
}
|
||
|
|
||
|
nav a:hover {
|
||
|
color: white;
|
||
|
background-color: #42545C;
|
||
|
}
|
||
|
nav a.active {
|
||
|
background-color: black;
|
||
|
color: white;
|
||
|
}
|
||
|
hr {
|
||
|
margin: 1.5rem 0;
|
||
|
}
|
||
|
input[type="text"] {
|
||
|
box-sizing: border-box;
|
||
|
width: 100%;
|
||
|
padding: .5rem;
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[src/test.css]" value="@import "~jasmine-core/lib/jasmine-core/jasmine.css"
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[src/main.ts]" value="import './testing/global-jasmine';
|
||
|
import 'jasmine-core/lib/jasmine-core/jasmine-html.js';
|
||
|
import 'jasmine-core/lib/jasmine-core/boot.js';
|
||
|
|
||
|
declare var jasmine;
|
||
|
|
||
|
import './polyfills';
|
||
|
|
||
|
import 'zone.js/testing';
|
||
|
|
||
|
import { getTestBed } from '@angular/core/testing';
|
||
|
import {
|
||
|
BrowserDynamicTestingModule,
|
||
|
platformBrowserDynamicTesting
|
||
|
} from '@angular/platform-browser-dynamic/testing';
|
||
|
|
||
|
// Import spec files individually for Stackblitz
|
||
|
import './app/heroes/heroes.service.spec.ts';
|
||
|
import './testing/http-client.spec.ts';
|
||
|
|
||
|
//
|
||
|
bootstrap();
|
||
|
|
||
|
//
|
||
|
function bootstrap() {
|
||
|
if ((window as any).jasmineRef) {
|
||
|
location.reload();
|
||
|
return;
|
||
|
} else {
|
||
|
window.onload(undefined);
|
||
|
(window as any).jasmineRef = jasmine.getEnv();
|
||
|
}
|
||
|
|
||
|
// First, initialize the Angular testing environment.
|
||
|
getTestBed().initTestEnvironment(
|
||
|
BrowserDynamicTestingModule,
|
||
|
platformBrowserDynamicTesting()
|
||
|
);
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[src/index.html]" value="<!--
|
||
|
Intentionally empty placeholder for Stackblitz.
|
||
|
Do not need index.html in zip-download either as you should run tests with `npm test`
|
||
|
-->
|
||
|
|
||
|
|
||
|
<!--
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
-->"><input type="hidden" name="files[src/environments/environment.prod.ts]" value="export const environment = {
|
||
|
production: true
|
||
|
};
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[src/environments/environment.ts]" value="// This file can be replaced during build by using the `fileReplacements` array.
|
||
|
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
|
||
|
// The list of file replacements can be found in `angular.json`.
|
||
|
|
||
|
export const environment = {
|
||
|
production: false
|
||
|
};
|
||
|
|
||
|
/*
|
||
|
* For easier debugging in development mode, you can import the following file
|
||
|
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
|
||
|
*
|
||
|
* This import should be commented out in production mode because it will have a negative impact
|
||
|
* on performance if an error is thrown.
|
||
|
*/
|
||
|
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[angular.json]" value="{
|
||
|
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||
|
"version": 1,
|
||
|
"newProjectRoot": "projects",
|
||
|
"projects": {
|
||
|
"angular.io-example": {
|
||
|
"projectType": "application",
|
||
|
"schematics": {
|
||
|
"@schematics/angular:application": {
|
||
|
"strict": true
|
||
|
}
|
||
|
},
|
||
|
"root": "",
|
||
|
"sourceRoot": "src",
|
||
|
"prefix": "app",
|
||
|
"architect": {
|
||
|
"build": {
|
||
|
"builder": "@angular-devkit/build-angular:browser",
|
||
|
"options": {
|
||
|
"outputPath": "dist",
|
||
|
"index": "src/index.html",
|
||
|
"main": "src/main.ts",
|
||
|
"polyfills": "src/polyfills.ts",
|
||
|
"tsConfig": "tsconfig.app.json",
|
||
|
"aot": true,
|
||
|
"assets": [
|
||
|
"src/favicon.ico",
|
||
|
"src/assets"
|
||
|
],
|
||
|
"styles": [
|
||
|
"src/styles.css",
|
||
|
"src/test.css"
|
||
|
],
|
||
|
"scripts": []
|
||
|
},
|
||
|
"configurations": {
|
||
|
"production": {
|
||
|
"fileReplacements": [
|
||
|
{
|
||
|
"replace": "src/environments/environment.ts",
|
||
|
"with": "src/environments/environment.prod.ts"
|
||
|
}
|
||
|
],
|
||
|
"optimization": true,
|
||
|
"outputHashing": "all",
|
||
|
"sourceMap": false,
|
||
|
"namedChunks": false,
|
||
|
"extractLicenses": true,
|
||
|
"vendorChunk": false,
|
||
|
"buildOptimizer": true,
|
||
|
"budgets": [
|
||
|
{
|
||
|
"type": "initial",
|
||
|
"maximumWarning": "500kb",
|
||
|
"maximumError": "1mb"
|
||
|
},
|
||
|
{
|
||
|
"type": "anyComponentStyle",
|
||
|
"maximumWarning": "2kb",
|
||
|
"maximumError": "4kb"
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
"serve": {
|
||
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||
|
"options": {
|
||
|
"browserTarget": "angular.io-example:build"
|
||
|
},
|
||
|
"configurations": {
|
||
|
"production": {
|
||
|
"browserTarget": "angular.io-example:build:production"
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
"extract-i18n": {
|
||
|
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||
|
"options": {
|
||
|
"browserTarget": "angular.io-example:build"
|
||
|
}
|
||
|
},
|
||
|
"test": {
|
||
|
"builder": "@angular-devkit/build-angular:karma",
|
||
|
"options": {
|
||
|
"main": "src/test.ts",
|
||
|
"polyfills": "src/polyfills.ts",
|
||
|
"tsConfig": "tsconfig.spec.json",
|
||
|
"karmaConfig": "karma.conf.js",
|
||
|
"assets": [
|
||
|
"src/favicon.ico",
|
||
|
"src/assets"
|
||
|
],
|
||
|
"styles": [
|
||
|
"src/styles.css"
|
||
|
],
|
||
|
"scripts": []
|
||
|
}
|
||
|
},
|
||
|
"lint": {
|
||
|
"builder": "@angular-devkit/build-angular:tslint",
|
||
|
"options": {
|
||
|
"tsConfig": [
|
||
|
"tsconfig.app.json",
|
||
|
"tsconfig.spec.json",
|
||
|
"e2e/tsconfig.json"
|
||
|
],
|
||
|
"exclude": [
|
||
|
"**/node_modules/**"
|
||
|
]
|
||
|
}
|
||
|
},
|
||
|
"e2e": {
|
||
|
"builder": "@angular-devkit/build-angular:protractor",
|
||
|
"options": {
|
||
|
"protractorConfig": "e2e/protractor.conf.js",
|
||
|
"devServerTarget": "angular.io-example:serve"
|
||
|
},
|
||
|
"configurations": {
|
||
|
"production": {
|
||
|
"devServerTarget": "angular.io-example:serve:production"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
"defaultProject": "angular.io-example"
|
||
|
}
|
||
|
"><input type="hidden" name="files[src/polyfills.ts]" value="/**
|
||
|
* This file includes polyfills needed by Angular and is loaded before the app.
|
||
|
* You can add your own extra polyfills to this file.
|
||
|
*
|
||
|
* This file is divided into 2 sections:
|
||
|
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
|
||
|
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
|
||
|
* file.
|
||
|
*
|
||
|
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
|
||
|
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
|
||
|
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
|
||
|
*
|
||
|
* Learn more in https://angular.io/guide/browser-support
|
||
|
*/
|
||
|
|
||
|
/***************************************************************************************************
|
||
|
* BROWSER POLYFILLS
|
||
|
*/
|
||
|
|
||
|
/** IE11 requires the following for NgClass support on SVG elements */
|
||
|
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
||
|
|
||
|
/**
|
||
|
* Web Animations `@angular/platform-browser/animations`
|
||
|
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
|
||
|
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
|
||
|
*/
|
||
|
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
||
|
|
||
|
/**
|
||
|
* By default, zone.js will patch all possible macroTask and DomEvents
|
||
|
* user can disable parts of macroTask/DomEvents patch by setting following flags
|
||
|
* because those flags need to be set before `zone.js` being loaded, and webpack
|
||
|
* will put import in the top of bundle, so user need to create a separate file
|
||
|
* in this directory (for example: zone-flags.ts), and put the following flags
|
||
|
* into that file, and then add the following code before importing zone.js.
|
||
|
* import './zone-flags';
|
||
|
*
|
||
|
* The flags allowed in zone-flags.ts are listed here.
|
||
|
*
|
||
|
* The following flags will work for all browsers.
|
||
|
*
|
||
|
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch
|
||
|
* requestAnimationFrame
|
||
|
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
|
||
|
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch
|
||
|
* specified eventNames
|
||
|
*
|
||
|
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
|
||
|
* with the following flag, it will bypass `zone.js` patch for IE/Edge
|
||
|
*
|
||
|
* (window as any).__Zone_enable_cross_context_check = true;
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
/***************************************************************************************************
|
||
|
* Zone JS is required by default for Angular itself.
|
||
|
*/
|
||
|
import 'zone.js'; // Included with Angular CLI.
|
||
|
|
||
|
/***************************************************************************************************
|
||
|
* APPLICATION IMPORTS
|
||
|
*/
|
||
|
|
||
|
|
||
|
/*
|
||
|
Copyright Google LLC. All Rights Reserved.
|
||
|
Use of this source code is governed by an MIT-style license that
|
||
|
can be found in the LICENSE file at https://angular.io/license
|
||
|
*/"><input type="hidden" name="files[tsconfig.json]" value="{
|
||
|
"compileOnSave": false,
|
||
|
"compilerOptions": {
|
||
|
"baseUrl": "./",
|
||
|
"outDir": "./dist/out-tsc",
|
||
|
"forceConsistentCasingInFileNames": true,
|
||
|
"noImplicitReturns": true,
|
||
|
"noFallthroughCasesInSwitch": true,
|
||
|
"sourceMap": true,
|
||
|
"declaration": false,
|
||
|
"downlevelIteration": true,
|
||
|
"experimentalDecorators": true,
|
||
|
"moduleResolution": "node",
|
||
|
"importHelpers": true,
|
||
|
"target": "es2015",
|
||
|
"module": "es2020",
|
||
|
"lib": [
|
||
|
"es2018",
|
||
|
"dom"
|
||
|
]
|
||
|
},
|
||
|
"angularCompilerOptions": {
|
||
|
"strictInjectionParameters": true,
|
||
|
"strictInputAccessModifiers": true,
|
||
|
"strictTemplates": true,
|
||
|
"enableIvy": true
|
||
|
}
|
||
|
}"><input type="hidden" name="tags[0]" value="angular"><input type="hidden" name="tags[1]" value="example"><input type="hidden" name="tags[2]" value="http"><input type="hidden" name="tags[3]" value="testing"><input type="hidden" name="description" value="Angular Example - Http Guide Testing"><input type="hidden" name="dependencies" value="{"@angular/animations":"~11.0.1","@angular/common":"~11.0.1","@angular/compiler":"~11.0.1","@angular/core":"~11.0.1","@angular/forms":"~11.0.1","@angular/platform-browser":"~11.0.1","@angular/platform-browser-dynamic":"~11.0.1","@angular/router":"~11.0.1","angular-in-memory-web-api":"~0.11.0","rxjs":"~6.6.0","tslib":"^2.0.0","zone.js":"~0.11.4","jasmine-core":"~3.6.0","jasmine-marbles":"~0.6.0"}"></form>
|
||
|
<script>
|
||
|
var embedded = 'ctl=1';
|
||
|
var isEmbedded = window.location.search.indexOf(embedded) > -1;
|
||
|
|
||
|
if (isEmbedded) {
|
||
|
var form = document.getElementById('mainForm');
|
||
|
var action = form.action;
|
||
|
var actionHasParams = action.indexOf('?') > -1;
|
||
|
var symbol = actionHasParams ? '&' : '?'
|
||
|
form.action = form.action + symbol + embedded;
|
||
|
}
|
||
|
document.getElementById("mainForm").submit();
|
||
|
</script>
|
||
|
</body></html>
|