Skip to content

Commit

Permalink
Finished issue #6 (#7)
Browse files Browse the repository at this point in the history
* Unit test passed, e2e failed

* Basic draft of e2e test

* Finished basic unit test and e2e test
  • Loading branch information
Vincent Zheng authored and bfwg committed Jun 27, 2017
1 parent a8a27fe commit ae95829
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 20 deletions.
2 changes: 1 addition & 1 deletion frontend/e2e/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ describe('web-ui App', () => {

it('should display message saying app works', () => {
page.navigateTo();
expect(page.getParagraphText()).toEqual('app works!');
expect(page.getParagraphText()).toContain('ANGULAR-SPRING-JWT-STARTER');
});
});
2 changes: 1 addition & 1 deletion frontend/e2e/app.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export class WebUiPage {
}

getParagraphText() {
return element(by.css('app-root h1')).getText();
return element(by.css('app-root app-header span')).getText();
}
}
6 changes: 5 additions & 1 deletion frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ export const routes: Routes = [
canActivate: [LoginGuard]
},
{
path: '**',
path:'404',
component: NotFoundComponent
},
{
path: '**',
redirectTo: '/404'
}
];

Expand Down
66 changes: 55 additions & 11 deletions frontend/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,76 @@
import { TestBed, async } from '@angular/core/testing';

import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import { HomeComponent } from './home';
import { LoginComponent } from './login';

import { LoginGuard } from './guard';
import { NotFoundComponent } from './not-found';
import {
HeaderComponent,
ApiCardComponent,
FooterComponent,
GithubComponent,
} from './component';

import {
MaterialModule
} from '@angular/material';


import {
ApiService,
AuthService,
UserService,
FooService,
ConfigService
} from './service';

import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
AppComponent,
HeaderComponent,
FooterComponent,
],
imports: [
RouterTestingModule,
MaterialModule.forRoot(),
//FormsModule,
//ReactiveFormsModule,
//HttpModule,

],
providers: [
ApiService,
AuthService,
UserService,
FooService,
ConfigService
]
}).compileComponents();
}));

it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
let fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));

it(`should have as title 'app works!'`, async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app works!');
}));
// it(`should have as title 'app works!'`, async(() => {
// let fixture = TestBed.createComponent(AppComponent);
// const app = fixture.debugElement.componentInstance;
// expect(app.title).toEqual('app works!');
// }));

it('should render title in a h1 tag', async(() => {
const fixture = TestBed.createComponent(AppComponent);
it('should render title in a span tag', async(() => {
let fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('app works!');
expect(compiled.querySelector('span').textContent).toContain('Angular-Spring-JWT-Starter');
}));
});
30 changes: 28 additions & 2 deletions frontend/src/app/home/home.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { HomeComponent } from './home.component';
import { ApiCardComponent, GithubComponent } from '../component';
import {
MaterialModule
} from '@angular/material';

import {
ApiService,
AuthService,
UserService,
FooService,
ConfigService
} from '../service';

describe('HomeComponent', () => {
let component: HomeComponent;
let fixture: ComponentFixture<HomeComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HomeComponent ]
declarations: [
HomeComponent,
ApiCardComponent,
GithubComponent
],
imports: [
MaterialModule.forRoot(),
],
providers: [
ApiService,
AuthService,
UserService,
FooService,
ConfigService
]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
33 changes: 31 additions & 2 deletions frontend/src/app/login/login.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { LoginComponent } from './login.component';
import { RouterTestingModule } from '@angular/router/testing';
import { ApiCardComponent, GithubComponent } from '../component';
import {
MaterialModule
} from '@angular/material';

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

import {
ApiService,
AuthService,
UserService,
FooService,
ConfigService
} from '../service';

describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoginComponent ]
declarations: [LoginComponent],
imports: [
MaterialModule.forRoot(),
FormsModule,
ReactiveFormsModule,
RouterTestingModule,
],
providers:
[
UserService,
ApiService,
ConfigService,
AuthService,

]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/app/not-found/not-found.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ describe('NotFoundComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NotFoundComponent ]
declarations: [NotFoundComponent]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand All @@ -22,4 +22,11 @@ describe('NotFoundComponent', () => {
it('should be created', () => {
expect(component).toBeTruthy();
});

it('<h1> tag should contains \'Page Not Found\'', () => {
let fixture = TestBed.createComponent(NotFoundComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Page Not Found');
});
});

0 comments on commit ae95829

Please sign in to comment.