1
1
import { EntryActionTypes } from './../../../time-clock/store/entry.actions' ;
2
2
import { TechnologiesComponent } from './../technologies/technologies.component' ;
3
3
import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
4
- import { provideMockStore , MockStore } from '@ngrx/store/testing' ;
4
+ import { MockStore , provideMockStore } from '@ngrx/store/testing' ;
5
5
import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
6
6
import { DatePipe , formatDate } from '@angular/common' ;
7
7
import { ActionsSubject } from '@ngrx/store' ;
@@ -13,7 +13,8 @@ import { ProjectState } from '../../../customer-management/components/projects/c
13
13
import { getCustomerProjects } from '../../../customer-management/components/projects/components/store/project.selectors' ;
14
14
import { EntryState } from '../../../time-clock/store/entry.reducer' ;
15
15
import * as entryActions from '../../../time-clock/store/entry.actions' ;
16
- import { getUpdateError , getCreateError } from 'src/app/modules/time-clock/store/entry.selectors' ;
16
+ import { getCreateError , getUpdateError } from 'src/app/modules/time-clock/store/entry.selectors' ;
17
+ import { SaveEntryEvent } from './save-entry-event' ;
17
18
18
19
describe ( 'DetailsFieldsComponent' , ( ) => {
19
20
type Merged = TechnologyState & ProjectState & EntryState ;
@@ -30,18 +31,18 @@ describe('DetailsFieldsComponent', () => {
30
31
31
32
const state = {
32
33
projects : {
33
- projects : [ { id : 'id' , name : 'name' , project_type_id : '' } ] ,
34
- customerProjects : [ { id : 'id' , name : 'name' , description : 'description' , project_type_id : '123' } ] ,
34
+ projects : [ { id : 'id' , name : 'name' , project_type_id : '' } ] ,
35
+ customerProjects : [ { id : 'id' , name : 'name' , description : 'description' , project_type_id : '123' } ] ,
35
36
isLoading : false ,
36
37
message : '' ,
37
38
projectToEdit : undefined ,
38
39
} ,
39
40
technologies : {
40
- technologyList : { items : [ { name : 'java' } ] } ,
41
+ technologyList : { items : [ { name : 'java' } ] } ,
41
42
isLoading : false ,
42
43
} ,
43
44
activities : {
44
- data : [ { id : 'fc5fab41-a21e-4155-9d05-511b956ebd05' , tenant_id : 'ioet' , deleted : null , name : 'abc' } ] ,
45
+ data : [ { id : 'fc5fab41-a21e-4155-9d05-511b956ebd05' , tenant_id : 'ioet' , deleted : null , name : 'abc' } ] ,
45
46
isLoading : false ,
46
47
message : 'Data fetch successfully!' ,
47
48
activityIdToEdit : '' ,
@@ -66,7 +67,7 @@ describe('DetailsFieldsComponent', () => {
66
67
beforeEach ( async ( ( ) => {
67
68
TestBed . configureTestingModule ( {
68
69
declarations : [ DetailsFieldsComponent , TechnologiesComponent ] ,
69
- providers : [ provideMockStore ( { initialState : state } ) , { provide : ActionsSubject , useValue : actionSub } ] ,
70
+ providers : [ provideMockStore ( { initialState : state } ) , { provide : ActionsSubject , useValue : actionSub } ] ,
70
71
imports : [ FormsModule , ReactiveFormsModule ] ,
71
72
} ) . compileComponents ( ) ;
72
73
store = TestBed . inject ( MockStore ) ;
@@ -106,8 +107,8 @@ describe('DetailsFieldsComponent', () => {
106
107
} ) ;
107
108
108
109
[
109
- { actionType : EntryActionTypes . CREATE_ENTRY_SUCCESS } ,
110
- { actionType : EntryActionTypes . UPDATE_ENTRY_SUCCESS } ,
110
+ { actionType : EntryActionTypes . CREATE_ENTRY_SUCCESS } ,
111
+ { actionType : EntryActionTypes . UPDATE_ENTRY_SUCCESS } ,
111
112
] . map ( ( param ) => {
112
113
it ( `cleanForm after an action type ${ param . actionType } is received` , ( ) => {
113
114
const actionSubject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
@@ -217,84 +218,91 @@ describe('DetailsFieldsComponent', () => {
217
218
technology : '' ,
218
219
} ) ;
219
220
component . onSubmit ( ) ;
220
- const data = {
221
- project_id : '' ,
222
- activity_id : '' ,
223
- technologies : [ ] ,
224
- description : '' ,
225
- start_date : '2020-02-05T00:00:11' ,
226
- end_date : '2020-02-05T00:01:01' ,
227
- uri : '' ,
221
+ const data : SaveEntryEvent = {
222
+ entry : {
223
+ project_id : '' ,
224
+ activity_id : '' ,
225
+ technologies : [ ] ,
226
+ description : '' ,
227
+ start_date : '2020-02-05T00:00:11' ,
228
+ end_date : '2020-02-05T00:01:01' ,
229
+ uri : ''
230
+ } ,
231
+ shouldRestartEntry : false
228
232
} ;
229
233
expect ( component . saveEntry . emit ) . toHaveBeenCalledWith ( data ) ;
230
234
} ) ;
231
235
232
236
it ( 'when the current entry is not running, then the end hour input should be rendered' , ( ) => {
233
- component . isEntryRunning = false ;
237
+ component . goingToWorkOnThis = false ;
234
238
fixture . detectChanges ( ) ;
235
239
236
240
const endHourInput = fixture . debugElement . nativeElement . querySelector ( '#end_hour' ) ;
237
241
expect ( endHourInput ) . toBeDefined ( ) ;
238
242
} ) ;
239
243
240
244
it ( 'when the current entry is running, then the end hour input should not be rendered' , ( ) => {
241
- component . isEntryRunning = true ;
245
+ component . goingToWorkOnThis = true ;
242
246
fixture . detectChanges ( ) ;
243
247
244
248
const endHourInput = fixture . debugElement . nativeElement . querySelector ( '#end_hour' ) ;
245
249
expect ( endHourInput ) . toBeNull ( ) ;
246
250
} ) ;
247
251
248
- it ( 'when creating a new entry, then the new entry should be marked as not running ' , ( ) => {
252
+ it ( 'when creating a new entry, then the new entry should be marked as not run ' , ( ) => {
249
253
component . entryToEdit = null ;
250
254
251
- expect ( component . isEntryRunning ) . toBeFalse ( ) ;
255
+ expect ( component . goingToWorkOnThis ) . toBeFalse ( ) ;
252
256
} ) ;
253
257
254
- it ( 'when editing entry that is currently running, then the entry should be marked as running ' , ( ) => {
255
- component . entryToEdit = { ...entryToEdit , running : true } ;
258
+ it ( 'when editing entry that is currently running, then the entry should be marked as I am working on this ' , ( ) => {
259
+ component . entryToEdit = { ...entryToEdit , running : true } ;
256
260
257
261
fixture . componentInstance . ngOnChanges ( ) ;
258
262
259
- expect ( component . isEntryRunning ) . toBeTrue ( ) ;
263
+ expect ( component . goingToWorkOnThis ) . toBeTrue ( ) ;
260
264
} ) ;
261
265
262
266
it ( 'when editing entry that already finished, then the entry should not be marked as running' , ( ) => {
263
- component . entryToEdit = { ...entryToEdit , running : false } ;
267
+ component . entryToEdit = { ...entryToEdit , running : false } ;
264
268
265
269
fixture . componentInstance . ngOnChanges ( ) ;
266
270
267
- expect ( component . isEntryRunning ) . toBeFalse ( ) ;
271
+ expect ( component . goingToWorkOnThis ) . toBeFalse ( ) ;
268
272
} ) ;
269
273
270
274
it ( 'when editing entry that already finished, then the entry should not be marked as running' , ( ) => {
271
- component . entryToEdit = { ...entryToEdit , running : false } ;
275
+ component . entryToEdit = { ...entryToEdit , running : false } ;
272
276
273
277
fixture . componentInstance . ngOnChanges ( ) ;
274
278
275
- expect ( component . isEntryRunning ) . toBeFalse ( ) ;
279
+ expect ( component . goingToWorkOnThis ) . toBeFalse ( ) ;
276
280
} ) ;
277
281
278
282
it ( 'when submitting a entry that is currently running, the end date should not be sent ' , ( ) => {
279
- component . isEntryRunning = true ;
283
+ component . goingToWorkOnThis = true ;
280
284
spyOn ( component , 'getElapsedSeconds' ) . and . returnValue ( '10' ) ;
281
285
spyOn ( component . saveEntry , 'emit' ) ;
282
286
283
- component . entryForm . setValue ( { ...formValues , entry_date : '2020-06-11' } ) ;
287
+ component . entryForm . setValue ( { ...formValues , entry_date : '2020-06-11' } ) ;
284
288
component . onSubmit ( ) ;
285
- const data = {
286
- project_id : '' ,
287
- activity_id : '' ,
288
- technologies : [ ] ,
289
- description : '' ,
290
- start_date : '2020-06-11T00:00:10' ,
291
- uri : 'ticketUri' ,
289
+ const data : SaveEntryEvent = {
290
+ entry : {
291
+ project_id : '' ,
292
+ activity_id : '' ,
293
+ technologies : [ ] ,
294
+ description : '' ,
295
+ start_date : '2020-06-11T00:00:10' ,
296
+ uri : 'ticketUri' ,
297
+ } ,
298
+ shouldRestartEntry : false
292
299
} ;
293
300
294
- expect ( component . saveEntry . emit ) . toHaveBeenCalledWith ( data ) ;
301
+ expect ( component . saveEntry . emit
302
+ ) . toHaveBeenCalledWith ( data ) ;
295
303
} ) ;
296
304
297
- it ( 'when disabling current entry is running , then the end hour should be set to the current time' , ( ) => {
305
+ it ( 'when disabling going to work on this , then the end hour should be set to the current time' , ( ) => {
298
306
const datePipe : DatePipe = new DatePipe ( 'en' ) ;
299
307
const currentTime = datePipe . transform ( new Date ( ) , 'HH:mm' ) ;
300
308
@@ -305,4 +313,15 @@ describe('DetailsFieldsComponent', () => {
305
313
const endHourInput : HTMLInputElement = fixture . debugElement . nativeElement . querySelector ( '#end_hour' ) ;
306
314
expect ( endHourInput . value ) . toEqual ( currentTime ) ;
307
315
} ) ;
316
+
317
+ it ( 'given going to work on this and the entry is not currently running, when submitting form then the entry should be restarted' , ( ) => {
318
+ component . goingToWorkOnThis = false ;
319
+ component . entryToEdit = { ...entryToEdit , running : false } ;
320
+
321
+ const checkIsEntryRunning : HTMLInputElement = fixture . debugElement . nativeElement . querySelector ( '#isEntryRunning' ) ;
322
+ checkIsEntryRunning . click ( ) ;
323
+ fixture . detectChanges ( ) ;
324
+
325
+ expect ( component . shouldRestartEntry ) . toBeTrue ( ) ;
326
+ } ) ;
308
327
} ) ;
0 commit comments