1- import { Subscription , of } from 'rxjs' ;
1+ import { Subscription } from 'rxjs' ;
22import { LoadActiveEntry , EntryActionTypes } from './../../store/entry.actions' ;
33import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions' ;
44import { waitForAsync , ComponentFixture , TestBed } from '@angular/core/testing' ;
@@ -15,21 +15,15 @@ import { formatDate } from '@angular/common';
1515import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker' ;
1616import * as moment from 'moment' ;
1717import { DATE_FORMAT_YEAR } from 'src/environments/environment' ;
18- import { CookieService } from 'ngx-cookie-service' ;
19- import { FeatureToggleGeneralService } from './../../../shared/feature-toggles/feature-toggle-general/feature-toggle-general.service' ;
20- import { FeatureToggle } from 'src/environments/enum' ;
21-
2218
2319describe ( 'EntryFieldsComponent' , ( ) => {
2420 type Merged = TechnologyState & ProjectState ;
2521 let component : EntryFieldsComponent ;
2622 let fixture : ComponentFixture < EntryFieldsComponent > ;
2723 let store : MockStore < Merged > ;
28- let cookieService : CookieService ;
2924 let mockTechnologySelector ;
3025 let mockProjectsSelector ;
3126 let entryForm ;
32- let featureToggleGeneralService : FeatureToggleGeneralService ;
3327 const actionSub : ActionsSubject = new ActionsSubject ( ) ;
3428 const toastrServiceStub = {
3529 error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { } ,
@@ -105,7 +99,11 @@ describe('EntryFieldsComponent', () => {
10599 description : 'description for active entry' ,
106100 uri : 'abc' ,
107101 start_date : moment ( mockDate ) . format ( DATE_FORMAT_YEAR ) ,
108- start_hour : moment ( mockDate ) . format ( 'HH:mm' ) ,
102+ start_hour : moment ( mockDate ) . format ( 'HH:mm' )
103+ } ;
104+
105+ const mockEntryOverlap = {
106+ update_last_entry_if_overlap : true
109107 } ;
110108
111109 beforeEach ( waitForAsync ( ( ) => {
@@ -122,8 +120,6 @@ describe('EntryFieldsComponent', () => {
122120 entryForm = TestBed . inject ( FormBuilder ) ;
123121 mockTechnologySelector = store . overrideSelector ( allTechnologies , state . technologies ) ;
124122 mockProjectsSelector = store . overrideSelector ( getCustomerProjects , state . projects ) ;
125- featureToggleGeneralService = TestBed . inject ( FeatureToggleGeneralService ) ;
126- cookieService = TestBed . inject ( CookieService ) ;
127123 } ) ) ;
128124
129125 beforeEach ( ( ) => {
@@ -260,6 +256,7 @@ describe('EntryFieldsComponent', () => {
260256 } ) ;
261257
262258 it ( 'when a start hour is updated, then dispatch UpdateActiveEntry' , ( ) => {
259+ component . newData = mockEntryOverlap ;
263260 component . activeEntry = entry ;
264261 component . setDataToUpdate ( entry ) ;
265262 const updatedTime = moment ( mockDate ) . format ( 'HH:mm' ) ;
@@ -268,11 +265,13 @@ describe('EntryFieldsComponent', () => {
268265 spyOn ( store , 'dispatch' ) ;
269266
270267 component . onUpdateStartHour ( ) ;
268+
271269 expect ( store . dispatch ) . toHaveBeenCalled ( ) ;
272270 expect ( component . showTimeInbuttons ) . toEqual ( false ) ;
273271 } ) ;
274272
275273 it ( 'When start_time is updated, component.last_entry is equal to time entry in the position 1' , waitForAsync ( ( ) => {
274+ component . newData = mockEntryOverlap ;
276275 component . activeEntry = entry ;
277276 component . setDataToUpdate ( entry ) ;
278277 const updatedTime = moment ( mockDate ) . format ( 'HH:mm' ) ;
@@ -284,6 +283,7 @@ describe('EntryFieldsComponent', () => {
284283 } ) ) ;
285284
286285 it ( 'When start_time is updated for a time entry. UpdateCurrentOrLastEntry action is dispatched' , ( ) => {
286+ component . newData = mockEntryOverlap ;
287287 component . activeEntry = entry ;
288288 component . setDataToUpdate ( entry ) ;
289289 const updatedTime = moment ( mockDate ) . subtract ( 4 , 'hours' ) . format ( 'HH:mm' ) ;
@@ -440,124 +440,6 @@ describe('EntryFieldsComponent', () => {
440440 expect ( component . actionSetDateSubscription . unsubscribe ) . toHaveBeenCalled ( ) ;
441441 } ) ;
442442
443- it ( 'when feature-toggle "update-entries" enable for the user, the updateEntry function is executes to update the entries' , ( ) => {
444- spyOn ( store , 'dispatch' ) ;
445- const expected = { update_last_entry_if_overlap : true } ;
446- const mockEntry = {
447- ...entry ,
448- start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
449- start_hour : moment ( ) . format ( 'HH:mm' )
450- } ;
451- const lastMockEntry = {
452- ...entry ,
453- end_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
454- end_hour : moment ( ) . format ( 'HH:mm' )
455- } ;
456- const hourInTheFuture = moment ( ) . format ( 'HH:mm' ) ;
457- component . newData = mockEntry ;
458- component . activeEntry = mockEntry ;
459- component . lastEntry = lastMockEntry ;
460- component . isFeatureToggleActive = true ;
461- component . entryForm . patchValue ( { start_hour : hourInTheFuture } ) ;
462-
463- component . onUpdateStartHour ( ) ;
464-
465- expect ( component . newData . update_last_entry_if_overlap ) . toEqual ( expected . update_last_entry_if_overlap ) ;
466- expect ( store . dispatch ) . toHaveBeenCalled ( ) ;
467- } ) ;
468-
469- it ( 'Set true in isCookieFeatureToggleActive when feature-toggle "feature-toggle-in-cookies" is enable for user' , ( ) => {
470- const expectedValue = true ;
471- spyOn ( featureToggleGeneralService , 'isActivated' ) . and . returnValue ( of ( true ) ) ;
472-
473- component . ngOnInit ( ) ;
474-
475- expect ( component . isCookieFeatureToggleActive ) . toEqual ( expectedValue ) ;
476- } ) ;
477-
478- it ( 'Set false in isCookieFeatureToggleActive when feature-toggle "feature-toggle-in-cookies" is not enable for user' , ( ) => {
479- const expectedValue = false ;
480- spyOn ( featureToggleGeneralService , 'isActivated' ) . and . returnValue ( of ( false ) ) ;
481-
482- component . ngOnInit ( ) ;
483-
484- expect ( component . isCookieFeatureToggleActive ) . toEqual ( expectedValue ) ;
485- } ) ;
486-
487-
488- it ( 'Call cookieService.get() when isCookieFeatureToggleActive is True' , ( ) => {
489- const expectedValue = true ;
490- component . isCookieFeatureToggleActive = expectedValue ;
491- spyOn ( cookieService , 'get' ) . and . returnValue ( `${ expectedValue } ` ) ;
492-
493- component . ngOnInit ( ) ;
494-
495- expect ( cookieService . get ) . toHaveBeenCalledWith ( FeatureToggle . UPDATE_ENTRIES ) ;
496- } ) ;
497-
498- it ( 'Call featureToggleGeneralService.isActivated() when isCookieFeatureToggleActive is False' , ( ) => {
499- const expectedValue = false ;
500- spyOn ( featureToggleGeneralService , 'isActivated' ) . and . returnValue ( of ( expectedValue ) ) ;
501-
502- component . ngOnInit ( ) ;
503-
504- expect ( featureToggleGeneralService . isActivated ) . toHaveBeenCalledWith ( FeatureToggle . UPDATE_ENTRIES ) ;
505- } ) ;
506-
507- it ( 'Set True in isFeatureToggleActive when cookieService.get() return "true" and isCookieFeatureToggleActive is true' , ( ) => {
508- const expectedValue = true ;
509- component . isCookieFeatureToggleActive = expectedValue ;
510- spyOn ( cookieService , 'get' ) . and . returnValue ( `${ expectedValue } ` ) ;
511-
512- component . ngOnInit ( ) ;
513-
514- expect ( component . isFeatureToggleActive ) . toEqual ( expectedValue ) ;
515- } ) ;
516-
517- it ( 'Set True in isFeatureToggleActive when cookieService.get() return "false" and isCookieFeatureToggleActive is true' , ( ) => {
518- const expectedValue = false ;
519- component . isCookieFeatureToggleActive = ! expectedValue ;
520- spyOn ( cookieService , 'get' ) . and . returnValue ( `${ expectedValue } ` ) ;
521-
522- component . ngOnInit ( ) ;
523-
524- expect ( component . isFeatureToggleActive ) . toEqual ( expectedValue ) ;
525- } ) ;
526-
527- it ( 'Set True in isFeatureToggleActive when featureToggleGeneralService.isActivated() return true' , ( ) => {
528- const expectedValue = true ;
529- spyOn ( featureToggleGeneralService , 'isActivated' ) . and . callFake (
530- ( featureToggle ) => featureToggle === FeatureToggle . COOKIES ? of ( false ) : of ( true ) ) ;
531-
532- component . ngOnInit ( ) ;
533-
534- expect ( featureToggleGeneralService . isActivated ) . toHaveBeenCalledWith ( FeatureToggle . UPDATE_ENTRIES ) ;
535- expect ( component . isFeatureToggleActive ) . toEqual ( expectedValue ) ;
536- } ) ;
537-
538- it ( 'Set False in isFeatureToggleActive when featureToggleGeneralService.isActivated() return false and isCookieFeatureToggleActive is false' , ( ) => {
539- const expectedValue = false ;
540- spyOn ( featureToggleGeneralService , 'isActivated' ) . and . returnValue ( of ( expectedValue ) ) ;
541-
542- component . ngOnInit ( ) ;
543-
544- expect ( component . isFeatureToggleActive ) . toEqual ( expectedValue ) ;
545- } ) ;
546-
547- it ( 'when FT "update-entries" disable for the user,the UpdateCurrentOrLastEntry function is called to update the entries' , ( ) => {
548- spyOn ( featureToggleGeneralService , 'isActivated' ) . and . returnValue ( of ( false ) ) ;
549-
550- const mockEntry = {
551- ...entry ,
552- start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
553- start_hour : moment ( ) . format ( 'HH:mm' )
554- } ;
555- component . newData = mockEntry ;
556- featureToggleGeneralService . isActivated ( FeatureToggle . UPDATE_ENTRIES ) . subscribe ( ( ) => {
557- expect ( featureToggleGeneralService . isActivated ) . toHaveBeenCalled ( ) ;
558- } ) ;
559- } ) ;
560-
561443 it ( 'when a activity is not register in DB should show activatefocus in select activity' , ( ) => {
562444 const activitiesMock = [ {
563445 id : 'xyz' ,
0 commit comments