1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| import {TestBed, async, ComponentFixture} from "@angular/core/testing"; import {DebugElement, Component, NO_ERRORS_SCHEMA} from "@angular/core";
import {SessionListComponent} from "./session-list.component"; import {AuthService} from "../../user/auth.service"; import {VoterService} from "./voter.service"; import {ISession} from "../shared/event.model"; import {By} from '@angular/platform-browser' import { DurationPipe } from '../shared/duration.pipe'
describe('SessionListComponent', () => { let fixture: ComponentFixture<SessionListComponent>, component: SessionListComponent, element: HTMLElement, debugEl: DebugElement
beforeEach(async(() => { let mockAuthService = { isAuthenticated: () => true, currentUser: { userName: 'Joe' } } let mockVoterService = { userHasVoted: () => true }
TestBed.configureTestingModule({ imports: [], declarations: [ SessionListComponent, DurationPipe, ], providers: [ { provide: AuthService, useValue: mockAuthService }, { provide: VoterService, useValue: mockVoterService }, ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents();
}));
beforeEach(() => { fixture = TestBed.createComponent(SessionListComponent); component = fixture.componentInstance; debugEl = fixture.debugElement; element = fixture.nativeElement; })
describe('initial display', () => { it('should have the correct session title', () => { component.sessions = [{ id: 3, name: 'Session 1', presenter: 'Joe', duration: 1, level: 'beginner', abstract: 'abstract', voters: ['john', 'bob'] }];
component.filterBy = 'all' component.sortBy = 'name' component.eventId = 4;
component.ngOnChanges(); fixture.detectChanges()
expect(element.querySelector('[well-title]').textContent).toContain('Session 1') expect(debugEl.query(By.css('[well-title]')).nativeElement.textContent).toContain('Session 1') }) })
});
|