Skip to content

Commit 703bd8b

Browse files
committed
Use MockNgRedux for testing
1 parent 1703b3e commit 703bd8b

File tree

6 files changed

+19
-32
lines changed

6 files changed

+19
-32
lines changed

src/app/components/status-dialog/status-dialog.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Component, OnInit, ViewChild } from '@angular/core';
22
import { DialogboxComponent } from '../dialogbox/dialogbox.component';
3-
import { select } from '@angular-redux/store';
4-
import { Observable } from 'rxjs';
53
import { API_ERRORS } from '../../shared/http/error-handling';
64
import { StatusDialogService } from './status-dialog.service';
75
import { NotificationService } from '../notifications/notification.service';

src/app/components/topnavbar/topnavbar.component.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
33
import { TopNavBarComponent } from './topnavbar.component';
44
import { TopNavBarModule } from './topnavbar.module';
55
import { RouterTestingModule } from '@angular/router/testing';
6-
import createSpy = jasmine.createSpy;
76
import { AuthService } from '../../shared/services/auth.service';
87
import { MockAuthService } from '../../shared/testing/mock-helper.spec';
98

src/app/shared/guards/load.guard.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22

3-
import createSpy = jasmine.createSpy;
43
import { Injector, ReflectiveInjector } from '@angular/core';
54
import { LoadGuard } from './load.guard';
65
import { AuthService } from '../services/auth.service';

src/app/shared/services/hoverfly.service.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { API_ERRORS } from '../http/error-handling';
1616
import { NotificationService } from '../../components/notifications/notification.service';
1717
import { MockNotificationService } from '../testing/mock-helper.spec';
1818
import { mockErrorResponse } from '../testing/http-helper.spec';
19+
import { MockNgRedux } from '@angular-redux/store/testing';
1920

2021
describe('Service: Hoverfly', () => {
2122

@@ -27,7 +28,7 @@ describe('Service: Hoverfly', () => {
2728
let notifyService: MockNotificationService;
2829

2930
beforeEach(() => {
30-
ngRedux = new NgRedux<AppState>(null);
31+
ngRedux = MockNgRedux.getInstance();
3132
spyOn(ngRedux, 'dispatch');
3233
injector = ReflectiveInjector.resolveAndCreate([
3334
{ provide: NgRedux, useValue: ngRedux },

src/app/shared/testing/redux-helper.spec.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/app/views/dashboard/dashboard.component.spec.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { async, ComponentFixture, ComponentFixtureAutoDetect, fakeAsync, TestBed
55
import { DashboardModule } from './dashboard.module';
66
import createSpy = jasmine.createSpy;
77
import { HoverflyService } from '../../shared/services/hoverfly.service';
8-
import { NgRedux } from '@angular-redux/store';
98
import { fromJS } from 'immutable';
109
import { Subscription } from 'rxjs';
1110
import { By } from '@angular/platform-browser';
12-
import { createMockRedux } from '../../shared/testing/redux-helper.spec';
1311
import { click } from '../../shared/testing/click-helper.spec';
12+
import { MockNgRedux, NgReduxTestingModule } from '@angular-redux/store/testing';
1413

1514

1615
const mockState: Map<any, any> = fromJS(
@@ -33,26 +32,30 @@ describe('Component: Dashboard', () => {
3332
let component: DashboardComponent;
3433
let fixture: ComponentFixture<DashboardComponent>;
3534

36-
const configureTestModule = function (state: Map<any, any>) {
35+
const configureTestModule = function () {
3736
return TestBed.configureTestingModule({
3837
imports: [
39-
DashboardModule
38+
DashboardModule,
39+
NgReduxTestingModule
4040
],
4141
providers: [
42-
{ provide: NgRedux, useValue: createMockRedux(state) },
4342
{ provide: HoverflyService, useClass: MockHoverflyService },
4443
{ provide: ComponentFixtureAutoDetect, useValue: true }
4544
]
4645
})
4746
.compileComponents();
4847
};
4948

50-
beforeEach(async(() => configureTestModule(mockState)));
49+
beforeEach(async(() => configureTestModule()));
5150

5251
beforeEach(() => {
52+
const hoverflyStub = MockNgRedux.getSelectorStub([ 'hoverfly', 'hoverfly' ]);
53+
hoverflyStub.next(mockState);
54+
hoverflyStub.complete();
5355
fixture = TestBed.createComponent(DashboardComponent);
5456
component = fixture.componentInstance;
5557
hoverflyService = TestBed.get(HoverflyService);
58+
MockNgRedux.reset();
5659
});
5760

5861
it('should create the dashboard', () => {
@@ -86,7 +89,10 @@ describe('Component: Dashboard', () => {
8689
}
8790
});
8891

89-
configureTestModule(stateWithMiddleware).then(() => {
92+
configureTestModule().then(() => {
93+
const hoverflyStub = MockNgRedux.getSelectorStub([ 'hoverfly', 'hoverfly' ]);
94+
hoverflyStub.next(stateWithMiddleware);
95+
hoverflyStub.complete();
9096
fixture = TestBed.createComponent(DashboardComponent);
9197

9298
const binaryField = fixture.debugElement.query(By.css('#hoverfly-middleware-details-binary code'));
@@ -134,7 +140,10 @@ describe('Component: Dashboard', () => {
134140
}
135141
});
136142

137-
configureTestModule(stateWithMiddleware).then(() => {
143+
configureTestModule().then(() => {
144+
const hoverflyStub = MockNgRedux.getSelectorStub([ 'hoverfly', 'hoverfly' ]);
145+
hoverflyStub.next(stateWithMiddleware);
146+
hoverflyStub.complete();
138147
fixture = TestBed.createComponent(DashboardComponent);
139148

140149
const counters = fixture.debugElement.query(By.css('#hoverfly-counters'));

0 commit comments

Comments
 (0)