forked from anihalaney/rwa-trivia
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request anihalaney#582 from milansar/BW-756
BW-756 Unit test for Recent Games Component and Recent Games Card Component
- Loading branch information
Showing
18 changed files
with
3,336 additions
and
1,377 deletions.
There are no files selected for viewing
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,8 @@ | ||
module.exports = { | ||
coverageDirectory: '<rootDir>/test/coverage/shared-library', | ||
reporters: ['default', ['jest-stare', { | ||
"resultDir": "test/result/shared-library", | ||
"coverageLink": "./../../coverage/shared-library/index.html" | ||
}]], | ||
}; | ||
|
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 |
---|---|---|
|
@@ -7,13 +7,12 @@ import { provideMockStore, MockStore } from '@ngrx/store/testing'; | |
import { coreState, CoreState, UserActions, ActionWithPayload } from 'shared-library/core/store'; | ||
import { Utils, WindowRef } from 'shared-library/core/services'; | ||
import { MatSnackBarModule } from '@angular/material'; | ||
import { AppState } from '../../../../../../trivia/src/app/store'; | ||
import { TEST_DATA } from 'shared-library/testing/test.data'; | ||
|
||
describe('InviteMailFriendsComponent', () => { | ||
let component: InviteMailFriendsComponent; | ||
let fixture: ComponentFixture<InviteMailFriendsComponent>; | ||
let mockStore: MockStore<AppState>; | ||
let mockStore: MockStore<CoreState>; | ||
let spy: any; | ||
let mockCoreSelector: MemoizedSelector<CoreState, Partial<CoreState>>; | ||
|
||
|
@@ -35,7 +34,7 @@ describe('InviteMailFriendsComponent', () => { | |
}), | ||
UserActions, | ||
Utils, | ||
WindowRef,], | ||
WindowRef, ], | ||
declarations: [InviteMailFriendsComponent] | ||
}); | ||
|
||
|
@@ -112,42 +111,43 @@ describe('InviteMailFriendsComponent', () => { | |
component.invitationForm.controls['email'].setValue('test@test'); | ||
component.onSubscribe(); | ||
expect(component.errorMsg).toBe('Following email is not valid address!'); | ||
}) | ||
}); | ||
|
||
|
||
// tslint:disable-next-line: max-line-length | ||
it(`on Subscribe check if email is invalid then invalid email will add into invalid email list and show error msg should be false `, () => { | ||
component.invitationForm.controls['email'].setValue('test@test'); | ||
component.onSubscribe(); | ||
expect(component.showErrorMsg).toBeTruthy(); | ||
expect(component.invalidEmailList.length).toEqual(1); | ||
}) | ||
}); | ||
|
||
it(`on Subscribe errorMsg message should be set if wrong multiple email inserted `, () => { | ||
component.invitationForm.controls['email'].setValue('test@test,second.mail'); | ||
component.onSubscribe(); | ||
expect(component.errorMsg).toBe('Following emails are not valid address!'); | ||
}) | ||
}); | ||
|
||
|
||
it(`on Subscribe show error message should be true set if invalid single email inserted`, () => { | ||
component.invitationForm.controls['email'].setValue('test@test,second.mail'); | ||
component.onSubscribe(); | ||
expect(component.showErrorMsg).toBeTruthy(); | ||
expect(component.invalidEmailList.length).toEqual(2); | ||
}) | ||
}); | ||
|
||
|
||
it(`on Subscribe invalid email should push on invalidEmailList list should 1`, () => { | ||
component.invitationForm.controls['email'].setValue('test@test,[email protected]'); | ||
component.onSubscribe(); | ||
expect(component.invalidEmailList.length).toEqual(1); | ||
}) | ||
}); | ||
|
||
it(`on Subscribe valid email should push on validEmail list length should be 2`, () => { | ||
component.invitationForm.controls['email'].setValue('test@test,[email protected],[email protected]'); | ||
component.onSubscribe(); | ||
expect(component.validEmail.length).toEqual(2); | ||
}) | ||
}); | ||
|
||
it(`on Subscribe should dispatch action to add user invitation with correct payload `, () => { | ||
component.invitationForm.controls['email'].setValue('[email protected]'); | ||
|
@@ -158,7 +158,7 @@ describe('InviteMailFriendsComponent', () => { | |
const payloadData = { | ||
userId: user.userId, | ||
emails: ['[email protected]'] | ||
} | ||
}; | ||
|
||
spy.and.callFake((action: ActionWithPayload<string>) => { | ||
expect(action.type).toEqual(UserActions.ADD_USER_INVITATION); | ||
|
@@ -167,38 +167,38 @@ describe('InviteMailFriendsComponent', () => { | |
|
||
component.onSubscribe(); | ||
expect(mockStore.dispatch).toHaveBeenCalled(); | ||
}) | ||
}); | ||
|
||
it(`Invitation message should set to showSuccessMsg`, () => { | ||
const userProfileSaveStatus = "Invitation is sent on [email protected]"; | ||
const userProfileSaveStatus = 'Invitation is sent on [email protected]'; | ||
mockCoreSelector.setResult({ userProfileSaveStatus }); | ||
mockStore.refreshState(); | ||
expect(component.showSuccessMsg).toEqual(userProfileSaveStatus); | ||
}); | ||
|
||
it(`Invitation message should not set to showSuccessMsg if it status is 'NONE'`, () => { | ||
const userProfileSaveStatus = "NONE"; | ||
const userProfileSaveStatus = 'NONE'; | ||
mockCoreSelector.setResult({ userProfileSaveStatus }); | ||
mockStore.refreshState(); | ||
expect(component.showSuccessMsg).toBeUndefined(); | ||
}); | ||
|
||
it(`Invitation message should not set to showSuccessMsg if it status is 'IN PROCESS'`, () => { | ||
const userProfileSaveStatus = "IN PROCESS"; | ||
const userProfileSaveStatus = 'IN PROCESS'; | ||
mockCoreSelector.setResult({ userProfileSaveStatus }); | ||
mockStore.refreshState(); | ||
expect(component.showSuccessMsg).toBeUndefined(); | ||
}); | ||
|
||
it(`Invitation message should not set to showSuccessMsg if it status is 'SUCCESS'`, () => { | ||
const userProfileSaveStatus = "SUCCESS"; | ||
const userProfileSaveStatus = 'SUCCESS'; | ||
mockCoreSelector.setResult({ userProfileSaveStatus }); | ||
mockStore.refreshState(); | ||
expect(component.showSuccessMsg).toBeUndefined(); | ||
}); | ||
|
||
it(`Invitation message should not set to showSuccessMsg if it status is 'MAKE FRIEND SUCCESS'`, () => { | ||
const userProfileSaveStatus = "MAKE FRIEND SUCCESS"; | ||
const userProfileSaveStatus = 'MAKE FRIEND SUCCESS'; | ||
mockCoreSelector.setResult({ userProfileSaveStatus }); | ||
mockStore.refreshState(); | ||
expect(component.showSuccessMsg).toBeUndefined(); | ||
|
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
92 changes: 92 additions & 0 deletions
92
...rc/lib/shared/components/recent-games/recent-game-card/recent-game-card.component.spec.ts
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,92 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { RecentGameCardComponent } from './recent-game-card.component'; | ||
import { ReactiveFormsModule, FormsModule } from '@angular/forms'; | ||
import { StoreModule, MemoizedSelector, Store } from '@ngrx/store'; | ||
import { provideMockStore, MockStore } from '@ngrx/store/testing'; | ||
import { coreState, CoreState, UserActions, categoryDictionary } from 'shared-library/core/store'; | ||
import { Utils, WindowRef } from 'shared-library/core/services'; | ||
import { MatSnackBarModule } from '@angular/material'; | ||
import { TEST_DATA } from 'shared-library/testing/test.data'; | ||
import { Game } from 'shared-library/shared/model'; | ||
import { NO_ERRORS_SCHEMA } from '@angular/core'; | ||
|
||
describe('RecentGameCardComponent', () => { | ||
let component: RecentGameCardComponent; | ||
let fixture: ComponentFixture<RecentGameCardComponent>; | ||
let mockStore: MockStore<CoreState>; | ||
let spy: any; | ||
let mockCoreSelector: MemoizedSelector<CoreState, Partial<CoreState>>; | ||
let mockCategorySelector: MemoizedSelector<any, {}>; | ||
|
||
beforeEach(async(() => { | ||
|
||
TestBed.configureTestingModule({ | ||
declarations: [RecentGameCardComponent], | ||
schemas: [NO_ERRORS_SCHEMA], | ||
imports: [ReactiveFormsModule, FormsModule, StoreModule.forRoot({}), MatSnackBarModule], | ||
providers: [provideMockStore({ | ||
initialState: {}, | ||
selectors: [ | ||
{ | ||
selector: coreState, | ||
value: {} | ||
}, | ||
{ | ||
selector: categoryDictionary, | ||
value: {} | ||
} | ||
] | ||
}), | ||
UserActions, | ||
Utils, | ||
WindowRef,], | ||
|
||
}); | ||
|
||
fixture = TestBed.createComponent(RecentGameCardComponent); | ||
mockStore = TestBed.get(Store); | ||
component = fixture.componentInstance; | ||
|
||
component.user = TEST_DATA.userList[0]; | ||
const dbModel = TEST_DATA.game[0]; | ||
component.game = Game.getViewModel(dbModel); | ||
|
||
mockCoreSelector = mockStore.overrideSelector<CoreState, Partial<CoreState>>(coreState, {}); | ||
mockCategorySelector = mockStore.overrideSelector(categoryDictionary, {}); | ||
spy = spyOn(mockStore, 'dispatch'); | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('Category dictionary should be set when store emit Category dictionary', () => { | ||
const categoryDict = TEST_DATA.categoryDictionary; | ||
mockCategorySelector.setResult(categoryDict); | ||
mockStore.refreshState(); | ||
expect(component.categoryDict).toBe(categoryDict); | ||
}); | ||
|
||
it('on component load should call getOppnonentID function', () => { | ||
spy = spyOn(component, 'getOpponentId'); | ||
component.ngOnInit(); | ||
expect(component.getOpponentId).toHaveBeenCalled(); | ||
}); | ||
|
||
it('call to getOpponentId function should return correct opponent Id for passed game', () => { | ||
const dbModel = TEST_DATA.game[0]; | ||
const opponentId = dbModel.playerIds[1]; | ||
const game = Game.getViewModel(dbModel); | ||
expect(component.getOpponentId(game)).toBe(opponentId); | ||
}); | ||
|
||
it('User dictionary should be set when store emit user dictionary', () => { | ||
const userDict = TEST_DATA.userDict; | ||
mockCoreSelector.setResult({ userDict: userDict }); | ||
mockStore.refreshState(); | ||
expect(component.userDict).toBe(userDict); | ||
}); | ||
|
||
|
||
}); |
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.