-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
737 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { provideMockActions } from '@ngrx/effects/testing'; | ||
import { ReplaySubject } from 'rxjs/ReplaySubject'; | ||
|
||
import { UserEffects } from './user.effect'; | ||
import { | ||
UserLoadRequestAction, | ||
UserLoadSuccessAction, | ||
UserLoadErrorAction | ||
} from '../action/user.action'; | ||
import { Subject, of, throwError } from 'rxjs'; | ||
import { UserService } from '../service/user.service'; | ||
import { User } from '../model/user'; | ||
|
||
describe('User Effects', () => { | ||
let effects: UserEffects; | ||
let actions: Subject<any>; | ||
let userService: UserService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [], | ||
providers: [ | ||
UserEffects, | ||
UserService, | ||
provideMockActions(() => actions), | ||
], | ||
}); | ||
|
||
effects = TestBed.get(UserEffects); | ||
userService = TestBed.get(UserService); | ||
}); | ||
|
||
it('should fire a success action', () => { | ||
let user = {}; | ||
spyOn(userService, 'get').and.returnValue(of(user)); | ||
actions = new ReplaySubject(1); | ||
|
||
actions.next(new UserLoadRequestAction()); | ||
|
||
effects.loadUser$.subscribe(result => { | ||
expect(result).toEqual(new UserLoadSuccessAction(user as User)); | ||
}); | ||
}); | ||
|
||
it('should fire an error action', () => { | ||
let err = new Error('404'); | ||
spyOn(userService, 'get').and.returnValue(throwError(err)); | ||
actions = new ReplaySubject(1); | ||
|
||
actions.next(new UserLoadRequestAction()); | ||
|
||
effects.loadUser$.subscribe(result => { | ||
expect(result).toEqual(new UserLoadErrorAction(err)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { provideMockActions } from '@ngrx/effects/testing'; | ||
import { ReplaySubject } from 'rxjs/ReplaySubject'; | ||
|
||
import { VersionEffects } from './version.effect'; | ||
import { | ||
VersionInfoLoadRequestAction, | ||
VersionInfoLoadSuccessAction, | ||
VersionInfoLoadErrorAction | ||
} from '../action/version.action'; | ||
import { Subject, of, throwError } from 'rxjs'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { VersionInfo } from '../model/version'; | ||
|
||
describe('Version Effects', () => { | ||
let effects: VersionEffects; | ||
let actions: Subject<any>; | ||
let httpClient = { | ||
get: () => of({}) | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [], | ||
providers: [ | ||
{ provide: HttpClient, useValue: httpClient }, | ||
VersionEffects, | ||
provideMockActions(() => actions), | ||
], | ||
}); | ||
|
||
effects = TestBed.get(VersionEffects); | ||
httpClient = TestBed.get(HttpClient); | ||
}); | ||
|
||
it('should fire a success action', () => { | ||
let v = {}; | ||
spyOn(httpClient, 'get').and.returnValue(of({})); | ||
actions = new ReplaySubject(1); | ||
|
||
actions.next(new VersionInfoLoadRequestAction()); | ||
|
||
effects.loadVersionInfo$.subscribe(result => { | ||
expect(result).toEqual(new VersionInfoLoadSuccessAction(v as VersionInfo)); | ||
}); | ||
}); | ||
|
||
it('should fire an error action', () => { | ||
let err = new Error('404'); | ||
spyOn(httpClient, 'get').and.returnValue(throwError(err)); | ||
actions = new ReplaySubject(1); | ||
|
||
actions.next(new VersionInfoLoadRequestAction()); | ||
|
||
effects.loadVersionInfo$.subscribe(result => { | ||
expect(result).toEqual(new VersionInfoLoadErrorAction(err)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { CanDeactivateGuard, CanComponentDeactivate } from './can-deactivate.guard'; | ||
import { ActivatedRouteStub } from '../../../testing/activated-route.stub'; | ||
|
||
describe('Can Deactivate Guard Service', () => { | ||
let service: CanDeactivateGuard; | ||
let guarded: CanComponentDeactivate; | ||
let notGuarded: any; | ||
|
||
let activatedRoute: ActivatedRouteStub = new ActivatedRouteStub(); | ||
let child: ActivatedRouteStub = new ActivatedRouteStub(); | ||
child.testParamMap = { form: 'common' }; | ||
activatedRoute.firstChild = child; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [], | ||
providers: [ | ||
CanDeactivateGuard | ||
] | ||
}); | ||
service = TestBed.get(CanDeactivateGuard); | ||
|
||
guarded = { | ||
canDeactivate: (currentRoute, currentState, nextState) => { | ||
return true; | ||
} | ||
}; | ||
notGuarded = {}; | ||
}); | ||
|
||
it('should instantiate', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
|
||
describe('canDeactivate', () => { | ||
it('should check if the component has a canDeactivate method', () => { | ||
spyOn(guarded, 'canDeactivate'); | ||
expect(service.canDeactivate(notGuarded, null, null, null)).toBe(true); | ||
service.canDeactivate(guarded, null, null, null); | ||
expect(guarded.canDeactivate).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should return components result', () => { | ||
spyOn(guarded, 'canDeactivate').and.returnValue(false); | ||
expect(service.canDeactivate(guarded, null, null, null)).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { NgbModalModule, NgbModal } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
import { ModalService } from './modal.service'; | ||
|
||
describe('Modal Service', () => { | ||
let service: ModalService; | ||
let ngbModal: NgbModal; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NgbModalModule.forRoot() | ||
], | ||
providers: [ | ||
ModalService | ||
] | ||
}); | ||
service = TestBed.get(ModalService); | ||
ngbModal = TestBed.get(NgbModal); | ||
}); | ||
|
||
it('should instantiate', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
|
||
describe('modal.open method', () => { | ||
it('should open a new modal', () => { | ||
spyOn(ngbModal, 'open').and.callThrough(); | ||
service.open(`<div></div>`, {}); | ||
expect(ngbModal.open).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not add inputs to a modals scope if not provided a component', () => { | ||
spyOn(ngbModal, 'open').and.callThrough(); | ||
service.open(`<div></div>`, {}, { foo: 'bar' }); | ||
expect(ngbModal.open).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should accept inputs to add to a new modals scope', () => { | ||
spyOn(ngbModal, 'open').and.callFake(() => { | ||
return { | ||
result: Promise.resolve({}), | ||
componentInstance: {} | ||
}; | ||
}); | ||
service.open(`<div></div>`, {}, { foo: 'bar' }); | ||
expect(ngbModal.open).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { provideMockActions } from '@ngrx/effects/testing'; | ||
import { ReplaySubject } from 'rxjs/ReplaySubject'; | ||
|
||
import { MessageEffects } from './message.effect'; | ||
|
||
import { Subject, of, throwError } from 'rxjs'; | ||
import { MessagesLoadRequestAction, MessagesLoadSuccessAction, MessagesLoadErrorAction } from '../action/message.action'; | ||
import { I18nService } from '../service/i18n.service'; | ||
import { StoreModule, combineReducers, Store } from '@ngrx/store'; | ||
import * as fromI18n from '../reducer'; | ||
|
||
xdescribe('I18n Message Effects', () => { | ||
let effects: MessageEffects; | ||
let actions: Subject<any>; | ||
let i18nService: I18nService; | ||
let store: Store<fromI18n.State>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
StoreModule.forRoot({ | ||
core: combineReducers(fromI18n.reducers, { | ||
messages: { | ||
fetching: false, | ||
messages: null, | ||
error: null, | ||
locale: 'en-US' | ||
} | ||
}) | ||
}), | ||
], | ||
providers: [ | ||
{ | ||
provide: I18nService, useValue: { | ||
get: (locale: string) => of({}) | ||
} | ||
}, | ||
MessageEffects, | ||
provideMockActions(() => actions), | ||
], | ||
}); | ||
|
||
effects = TestBed.get(MessageEffects); | ||
i18nService = TestBed.get(I18nService); | ||
store = TestBed.get(Store); | ||
spyOn(store, 'dispatch'); | ||
}); | ||
|
||
it('should fire a success action', () => { | ||
let msgs = {}; | ||
spyOn(i18nService, 'get').and.returnValue(of(msgs)); | ||
spyOn(store, 'select').and.returnValue(of('en_US')); | ||
actions = new ReplaySubject(1); | ||
|
||
actions.next(new MessagesLoadRequestAction()); | ||
|
||
effects.loadMessages$.subscribe(result => { | ||
expect(result).toEqual(new MessagesLoadSuccessAction(msgs)); | ||
}); | ||
}); | ||
|
||
it('should fire an error action', () => { | ||
let err = new Error('404'); | ||
spyOn(i18nService, 'get').and.returnValue(throwError(err)); | ||
spyOn(store, 'select').and.returnValue(of('en_US')); | ||
actions = new ReplaySubject(1); | ||
|
||
actions.next(new MessagesLoadRequestAction()); | ||
|
||
effects.loadMessages$.subscribe(result => { | ||
expect(result).toEqual(new MessagesLoadErrorAction(err)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.