Skip to content

Commit 3e3548c

Browse files
author
ijz953
committed
docs: adding event list component tests
1 parent 5939a05 commit 3e3548c

File tree

2 files changed

+19
-63
lines changed

2 files changed

+19
-63
lines changed

projects/ngrx.io/content/marketing/events.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"endDate": "10-03-2018"
2727
},
2828
{
29-
"name": "AngularMix - Use the discount code \"RYAN\" or \"ROBERTS\" to receive $50 off your registration!",
29+
"name": "AngularMix",
3030
"url": "http://www.angularmix.com",
3131
"location": "Orlando, Florida",
3232
"startDate": "10-10-2018",
Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,29 @@
1-
import { ReflectiveInjector } from '@angular/core';
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
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+
}
410

5-
// Testing the component class behaviors, independent of its template
6-
// Let e2e tests verify how it displays.
711
describe('EventListComponent', () => {
812

13+
let fixture: ComponentFixture<EventListComponent>;
914
let component: EventListComponent;
10-
let injector: ReflectiveInjector;
1115

1216
beforeEach(() => {
13-
injector = ReflectiveInjector.resolveAndCreate([
14-
EventListComponent
15-
]);
16-
});
17+
TestBed.configureTestingModule({
18+
declarations: [ EventListComponent ],
19+
providers: [{ provide: EventService, useClass: TestEventService }]
20+
});
1721

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;
6524
});
6625

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+
});
7329
});

0 commit comments

Comments
 (0)