proper license and ng test

This commit is contained in:
Tair Sabirgaliev 2017-02-24 06:38:09 +06:00
parent 5a64d67404
commit 26edcdf6bc
4 changed files with 42 additions and 6 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "angular2-product-app", "name": "angular2-product-app",
"version": "0.0.0", "version": "0.0.0",
"license": "MIT", "license": "Apache-2.0",
"angular-cli": {}, "angular-cli": {},
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",

View file

@ -1,9 +1,9 @@
<div id="content-area" class="col-md-9" role="main"> <div id="content-area" class="col-md-9" role="main">
<div id="content"> <div id="content">
<h1>Angular2 Product (Beta)</h1> <h1>{{title}}</h1>
<h2><span>Products</span></h2> <h2><span>Products</span></h2>
<button type="button" (click)="logout()">Sign Out</button> <button type="button" (click)="logout()">Sign Out</button>
<button type="button" (click)="reloadData()">Reload</button> <button type="button" id="reload-data" (click)="reloadData()">Reload</button>
<table class="table" [hidden]="!products.length"> <table class="table" [hidden]="!products.length">
<thead> <thead>
<tr> <tr>

View file

@ -1,9 +1,32 @@
import { TestBed, async } from '@angular/core/testing'; import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { KeycloakService } from './keycloak/keycloak.service';
import {
HttpModule,
XHRBackend,
ResponseOptions,
Response,
RequestMethod
} from '@angular/http';
import {
MockBackend,
MockConnection
} from '@angular/http/testing/mock_backend';
describe('AppComponent', () => { describe('AppComponent', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [HttpModule],
providers: [
{
provide: XHRBackend,
useClass: MockBackend
},
{
provide: KeycloakService
}
],
declarations: [ declarations: [
AppComponent AppComponent
], ],
@ -17,16 +40,27 @@ describe('AppComponent', () => {
expect(app).toBeTruthy(); expect(app).toBeTruthy();
})); }));
it(`should have as title 'app works!'`, async(() => { it(`should have as title 'Angular2 Product'`, async(() => {
const fixture = TestBed.createComponent(AppComponent); const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance; const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app works!'); expect(app.title).toEqual('Angular2 Product');
})); }));
it('should render title in a h1 tag', async(() => { it('should render title in a h1 tag', async(() => {
const fixture = TestBed.createComponent(AppComponent); const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges(); fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement; const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('app works!'); expect(compiled.querySelector('h1').textContent).toContain('Angular2 Product');
}));
it('should render product list', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.componentInstance.products = ['iphone', 'ipad', 'ipod'];
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('table thead tr th').textContent).toContain('Product Listing');
expect(compiled.querySelectorAll('table tbody tr td')[0].textContent).toContain('iphone');
expect(compiled.querySelectorAll('table tbody tr td')[1].textContent).toContain('ipad');
expect(compiled.querySelectorAll('table tbody tr td')[2].textContent).toContain('ipod');
})); }));
}); });

View file

@ -13,6 +13,8 @@ import { environment } from '../environments/environment';
styleUrls: ['./app.component.css'] styleUrls: ['./app.component.css']
}) })
export class AppComponent { export class AppComponent {
title = 'Angular2 Product';
products: string[] = []; products: string[] = [];
constructor(private http: Http, private kc: KeycloakService) {} constructor(private http: Http, private kc: KeycloakService) {}