1+ import { EntryActionTypes } from './../../../time-clock/store/entry.actions' ;
12import { TechnologiesComponent } from './../technologies/technologies.component' ;
23import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
34import { provideMockStore , MockStore } from '@ngrx/store/testing' ;
45import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
56import { DatePipe , formatDate } from '@angular/common' ;
7+ import { ActionsSubject } from '@ngrx/store' ;
68
79import { TechnologyState } from '../../store/technology.reducers' ;
810import { allTechnologies } from '../../store/technology.selectors' ;
@@ -24,21 +26,22 @@ describe('DetailsFieldsComponent', () => {
2426 let mockEntriesCreateErrorSelector ;
2527 let entryToEdit ;
2628 let formValues ;
29+ const actionSub : ActionsSubject = new ActionsSubject ( ) ;
2730
2831 const state = {
2932 projects : {
30- projects : [ { id : 'id' , name : 'name' , project_type_id : '' } ] ,
31- customerProjects : [ { id : 'id' , name : 'name' , description : 'description' , project_type_id : '123' } ] ,
33+ projects : [ { id : 'id' , name : 'name' , project_type_id : '' } ] ,
34+ customerProjects : [ { id : 'id' , name : 'name' , description : 'description' , project_type_id : '123' } ] ,
3235 isLoading : false ,
3336 message : '' ,
3437 projectToEdit : undefined ,
3538 } ,
3639 technologies : {
37- technologyList : { items : [ { name : 'java' } ] } ,
40+ technologyList : { items : [ { name : 'java' } ] } ,
3841 isLoading : false ,
3942 } ,
4043 activities : {
41- data : [ { id : 'fc5fab41-a21e-4155-9d05-511b956ebd05' , tenant_id : 'ioet' , deleted : null , name : 'abc' } ] ,
44+ data : [ { id : 'fc5fab41-a21e-4155-9d05-511b956ebd05' , tenant_id : 'ioet' , deleted : null , name : 'abc' } ] ,
4245 isLoading : false ,
4346 message : 'Data fetch successfully!' ,
4447 activityIdToEdit : '' ,
@@ -63,7 +66,7 @@ describe('DetailsFieldsComponent', () => {
6366 beforeEach ( async ( ( ) => {
6467 TestBed . configureTestingModule ( {
6568 declarations : [ DetailsFieldsComponent , TechnologiesComponent ] ,
66- providers : [ provideMockStore ( { initialState : state } ) ] ,
69+ providers : [ provideMockStore ( { initialState : state } ) , { provide : ActionsSubject , useValue : actionSub } ] ,
6770 imports : [ FormsModule , ReactiveFormsModule ] ,
6871 } ) . compileComponents ( ) ;
6972 store = TestBed . inject ( MockStore ) ;
@@ -102,6 +105,24 @@ describe('DetailsFieldsComponent', () => {
102105 expect ( component ) . toBeTruthy ( ) ;
103106 } ) ;
104107
108+ [
109+ { actionType : EntryActionTypes . CREATE_ENTRY_SUCCESS } ,
110+ { actionType : EntryActionTypes . UPDATE_ENTRY_SUCCESS } ,
111+ ] . map ( ( param ) => {
112+ it ( `cleanForm after an action type ${ param . actionType } is received` , ( ) => {
113+ const actionSubject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
114+ const action = {
115+ type : param . actionType ,
116+ } ;
117+ spyOn ( component , 'cleanForm' ) ;
118+
119+ component . ngOnInit ( ) ;
120+ actionSubject . next ( action ) ;
121+
122+ expect ( component . cleanForm ) . toHaveBeenCalled ( ) ;
123+ } ) ;
124+ } ) ;
125+
105126 it ( 'should emit ngOnChange without data' , ( ) => {
106127 component . entryToEdit = null ;
107128 component . ngOnChanges ( ) ;
@@ -231,23 +252,23 @@ describe('DetailsFieldsComponent', () => {
231252 } ) ;
232253
233254 it ( 'when editing entry that is currently running, then the entry should be marked as running' , ( ) => {
234- component . entryToEdit = { ...entryToEdit , running : true } ;
255+ component . entryToEdit = { ...entryToEdit , running : true } ;
235256
236257 fixture . componentInstance . ngOnChanges ( ) ;
237258
238259 expect ( component . isEntryRunning ) . toBeTrue ( ) ;
239260 } ) ;
240261
241262 it ( 'when editing entry that already finished, then the entry should not be marked as running' , ( ) => {
242- component . entryToEdit = { ...entryToEdit , running : false } ;
263+ component . entryToEdit = { ...entryToEdit , running : false } ;
243264
244265 fixture . componentInstance . ngOnChanges ( ) ;
245266
246267 expect ( component . isEntryRunning ) . toBeFalse ( ) ;
247268 } ) ;
248269
249270 it ( 'when editing entry that already finished, then the entry should not be marked as running' , ( ) => {
250- component . entryToEdit = { ...entryToEdit , running : false } ;
271+ component . entryToEdit = { ...entryToEdit , running : false } ;
251272
252273 fixture . componentInstance . ngOnChanges ( ) ;
253274
@@ -259,7 +280,7 @@ describe('DetailsFieldsComponent', () => {
259280 spyOn ( component , 'getElapsedSeconds' ) . and . returnValue ( '10' ) ;
260281 spyOn ( component . saveEntry , 'emit' ) ;
261282
262- component . entryForm . setValue ( { ...formValues , entry_date : '2020-06-11' } ) ;
283+ component . entryForm . setValue ( { ...formValues , entry_date : '2020-06-11' } ) ;
263284 component . onSubmit ( ) ;
264285 const data = {
265286 project_id : '' ,
0 commit comments