|
1 | | -import { ReflectiveInjector } from '@angular/core'; |
| 1 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; |
2 | 2 | import { EventListComponent } from './event-list.component'; |
3 | | -import { EventResponse } from './event.model'; |
| 3 | +import { of } from 'rxjs'; |
| 4 | +import { EventService } from './event.service'; |
| 5 | + |
| 6 | +class TestEventService { |
| 7 | + upcomingEvents$ = of(); |
| 8 | + pastEvents$ = of(); |
| 9 | +} |
4 | 10 |
|
5 | | -// Testing the component class behaviors, independent of its template |
6 | | -// Let e2e tests verify how it displays. |
7 | 11 | describe('EventListComponent', () => { |
8 | 12 |
|
| 13 | + let fixture: ComponentFixture<EventListComponent>; |
9 | 14 | let component: EventListComponent; |
10 | | - let injector: ReflectiveInjector; |
11 | 15 |
|
12 | 16 | beforeEach(() => { |
13 | | - injector = ReflectiveInjector.resolveAndCreate([ |
14 | | - EventListComponent |
15 | | - ]); |
16 | | - }); |
| 17 | + TestBed.configureTestingModule({ |
| 18 | + declarations: [ EventListComponent ], |
| 19 | + providers: [{ provide: EventService, useClass: TestEventService }] |
| 20 | + }); |
17 | 21 |
|
18 | | - it('should put each event into the correct bucket and correctly format the date range string', () => { |
19 | | - component = getComponent(); |
20 | | - component.currentDate = new Date('01-02-2019'); |
21 | | - const mockEvents: EventResponse[] = [ |
22 | | - { |
23 | | - name: 'conf1', |
24 | | - url: '', |
25 | | - location: '', |
26 | | - startDate: '06-28-2018', |
27 | | - endDate: '07-01-2018' |
28 | | - }, |
29 | | - { |
30 | | - name: 'conf2', |
31 | | - url: '', |
32 | | - location: '', |
33 | | - startDate: '12-25-2018', |
34 | | - endDate: '01-01-2019' |
35 | | - }, |
36 | | - { |
37 | | - name: 'conf3', |
38 | | - url: '', |
39 | | - location: '', |
40 | | - startDate: '01-01-2019', |
41 | | - endDate: '01-03-2019' |
42 | | - }, |
43 | | - { |
44 | | - name: 'conf4', |
45 | | - url: '', |
46 | | - location: '', |
47 | | - endDate: '04-01-2019' |
48 | | - }, |
49 | | - { |
50 | | - name: 'conf5', |
51 | | - url: '', |
52 | | - location: '', |
53 | | - startDate: '04-02-2019', |
54 | | - endDate: '04-02-2019' |
55 | | - }, |
56 | | - ]; |
57 | | - component.events = mockEvents; |
58 | | - expect(component.pastEvents.length).toEqual(2); |
59 | | - expect(component.upcomingEvents.length).toEqual(3); |
60 | | - expect(component.pastEvents[0].dateRangeString).toEqual('June 28 - July 1, 2018'); |
61 | | - expect(component.pastEvents[1].dateRangeString).toEqual('December 25, 2018 - January 1, 2019'); |
62 | | - expect(component.upcomingEvents[0].dateRangeString).toEqual('January 1 - 3, 2019'); |
63 | | - expect(component.upcomingEvents[1].dateRangeString).toEqual('April 1, 2019'); |
64 | | - expect(component.upcomingEvents[2].dateRangeString).toEqual('April 2, 2019'); |
| 22 | + fixture = TestBed.createComponent(EventListComponent); |
| 23 | + component = fixture.componentInstance; |
65 | 24 | }); |
66 | 25 |
|
67 | | - |
68 | | - //// Test Helpers //// |
69 | | - function getComponent(): EventListComponent { |
70 | | - const comp = injector.get(EventListComponent); |
71 | | - return comp; |
72 | | - } |
| 26 | + it('should create', () => { |
| 27 | + expect(component).toBeTruthy(); |
| 28 | + }); |
73 | 29 | }); |
0 commit comments