11import { EntryActionTypes } from './../../../time-clock/store/entry.actions' ;
22import { TechnologiesComponent } from './../technologies/technologies.component' ;
33import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
4- import { provideMockStore , MockStore } from '@ngrx/store/testing' ;
4+ import { MockStore , provideMockStore } from '@ngrx/store/testing' ;
55import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
66import { DatePipe , formatDate } from '@angular/common' ;
77import { ActionsSubject } from '@ngrx/store' ;
@@ -13,7 +13,8 @@ import { ProjectState } from '../../../customer-management/components/projects/c
1313import { getCustomerProjects } from '../../../customer-management/components/projects/components/store/project.selectors' ;
1414import { EntryState } from '../../../time-clock/store/entry.reducer' ;
1515import * 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' ;
1718
1819describe ( 'DetailsFieldsComponent' , ( ) => {
1920 type Merged = TechnologyState & ProjectState & EntryState ;
@@ -30,18 +31,18 @@ describe('DetailsFieldsComponent', () => {
3031
3132 const state = {
3233 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' } ] ,
3536 isLoading : false ,
3637 message : '' ,
3738 projectToEdit : undefined ,
3839 } ,
3940 technologies : {
40- technologyList : { items : [ { name : 'java' } ] } ,
41+ technologyList : { items : [ { name : 'java' } ] } ,
4142 isLoading : false ,
4243 } ,
4344 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' } ] ,
4546 isLoading : false ,
4647 message : 'Data fetch successfully!' ,
4748 activityIdToEdit : '' ,
@@ -66,7 +67,7 @@ describe('DetailsFieldsComponent', () => {
6667 beforeEach ( async ( ( ) => {
6768 TestBed . configureTestingModule ( {
6869 declarations : [ DetailsFieldsComponent , TechnologiesComponent ] ,
69- providers : [ provideMockStore ( { initialState : state } ) , { provide : ActionsSubject , useValue : actionSub } ] ,
70+ providers : [ provideMockStore ( { initialState : state } ) , { provide : ActionsSubject , useValue : actionSub } ] ,
7071 imports : [ FormsModule , ReactiveFormsModule ] ,
7172 } ) . compileComponents ( ) ;
7273 store = TestBed . inject ( MockStore ) ;
@@ -106,8 +107,8 @@ describe('DetailsFieldsComponent', () => {
106107 } ) ;
107108
108109 [
109- { actionType : EntryActionTypes . CREATE_ENTRY_SUCCESS } ,
110- { actionType : EntryActionTypes . UPDATE_ENTRY_SUCCESS } ,
110+ { actionType : EntryActionTypes . CREATE_ENTRY_SUCCESS } ,
111+ { actionType : EntryActionTypes . UPDATE_ENTRY_SUCCESS } ,
111112 ] . map ( ( param ) => {
112113 it ( `cleanForm after an action type ${ param . actionType } is received` , ( ) => {
113114 const actionSubject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
@@ -217,84 +218,91 @@ describe('DetailsFieldsComponent', () => {
217218 technology : '' ,
218219 } ) ;
219220 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
228232 } ;
229233 expect ( component . saveEntry . emit ) . toHaveBeenCalledWith ( data ) ;
230234 } ) ;
231235
232236 it ( 'when the current entry is not running, then the end hour input should be rendered' , ( ) => {
233- component . isEntryRunning = false ;
237+ component . goingToWorkOnThis = false ;
234238 fixture . detectChanges ( ) ;
235239
236240 const endHourInput = fixture . debugElement . nativeElement . querySelector ( '#end_hour' ) ;
237241 expect ( endHourInput ) . toBeDefined ( ) ;
238242 } ) ;
239243
240244 it ( 'when the current entry is running, then the end hour input should not be rendered' , ( ) => {
241- component . isEntryRunning = true ;
245+ component . goingToWorkOnThis = true ;
242246 fixture . detectChanges ( ) ;
243247
244248 const endHourInput = fixture . debugElement . nativeElement . querySelector ( '#end_hour' ) ;
245249 expect ( endHourInput ) . toBeNull ( ) ;
246250 } ) ;
247251
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 ' , ( ) => {
249253 component . entryToEdit = null ;
250254
251- expect ( component . isEntryRunning ) . toBeFalse ( ) ;
255+ expect ( component . goingToWorkOnThis ) . toBeFalse ( ) ;
252256 } ) ;
253257
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 } ;
256260
257261 fixture . componentInstance . ngOnChanges ( ) ;
258262
259- expect ( component . isEntryRunning ) . toBeTrue ( ) ;
263+ expect ( component . goingToWorkOnThis ) . toBeTrue ( ) ;
260264 } ) ;
261265
262266 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 } ;
264268
265269 fixture . componentInstance . ngOnChanges ( ) ;
266270
267- expect ( component . isEntryRunning ) . toBeFalse ( ) ;
271+ expect ( component . goingToWorkOnThis ) . toBeFalse ( ) ;
268272 } ) ;
269273
270274 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 } ;
272276
273277 fixture . componentInstance . ngOnChanges ( ) ;
274278
275- expect ( component . isEntryRunning ) . toBeFalse ( ) ;
279+ expect ( component . goingToWorkOnThis ) . toBeFalse ( ) ;
276280 } ) ;
277281
278282 it ( 'when submitting a entry that is currently running, the end date should not be sent ' , ( ) => {
279- component . isEntryRunning = true ;
283+ component . goingToWorkOnThis = true ;
280284 spyOn ( component , 'getElapsedSeconds' ) . and . returnValue ( '10' ) ;
281285 spyOn ( component . saveEntry , 'emit' ) ;
282286
283- component . entryForm . setValue ( { ...formValues , entry_date : '2020-06-11' } ) ;
287+ component . entryForm . setValue ( { ...formValues , entry_date : '2020-06-11' } ) ;
284288 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
292299 } ;
293300
294- expect ( component . saveEntry . emit ) . toHaveBeenCalledWith ( data ) ;
301+ expect ( component . saveEntry . emit
302+ ) . toHaveBeenCalledWith ( data ) ;
295303 } ) ;
296304
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' , ( ) => {
298306 const datePipe : DatePipe = new DatePipe ( 'en' ) ;
299307 const currentTime = datePipe . transform ( new Date ( ) , 'HH:mm' ) ;
300308
@@ -305,4 +313,15 @@ describe('DetailsFieldsComponent', () => {
305313 const endHourInput : HTMLInputElement = fixture . debugElement . nativeElement . querySelector ( '#end_hour' ) ;
306314 expect ( endHourInput . value ) . toEqual ( currentTime ) ;
307315 } ) ;
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+ } ) ;
308327} ) ;
0 commit comments