1- import { Subscription } from 'rxjs' ;
1+ import { Subscription , of , Observable } from 'rxjs' ;
22import { LoadActiveEntry , EntryActionTypes , UpdateEntry } from './../../store/entry.actions' ;
33import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions' ;
44import { waitForAsync , ComponentFixture , TestBed } from '@angular/core/testing' ;
@@ -15,6 +15,8 @@ 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 { FeatureManagerService } from './../../../shared/feature-toggles/feature-toggle-manager.service' ;
19+
1820
1921describe ( 'EntryFieldsComponent' , ( ) => {
2022 type Merged = TechnologyState & ProjectState ;
@@ -24,6 +26,7 @@ describe('EntryFieldsComponent', () => {
2426 let mockTechnologySelector ;
2527 let mockProjectsSelector ;
2628 let entryForm ;
29+ let featureManagerService : FeatureManagerService ;
2730 const actionSub : ActionsSubject = new ActionsSubject ( ) ;
2831 const toastrServiceStub = {
2932 error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { } ,
@@ -114,6 +117,7 @@ describe('EntryFieldsComponent', () => {
114117 entryForm = TestBed . inject ( FormBuilder ) ;
115118 mockTechnologySelector = store . overrideSelector ( allTechnologies , state . technologies ) ;
116119 mockProjectsSelector = store . overrideSelector ( getCustomerProjects , state . projects ) ;
120+ featureManagerService = TestBed . inject ( FeatureManagerService ) ;
117121 } ) ) ;
118122
119123 beforeEach ( ( ) => {
@@ -425,4 +429,46 @@ describe('EntryFieldsComponent', () => {
425429 expect ( component . loadActiveEntrySubscription . unsubscribe ) . toHaveBeenCalled ( ) ;
426430 expect ( component . actionSetDateSubscription . unsubscribe ) . toHaveBeenCalled ( ) ;
427431 } ) ;
432+
433+ it ( 'when feature-toggle "update-entries" enable for the user, the updateEntry function is executes to update the entries' , ( ) => {
434+ spyOn ( featureManagerService , 'isToggleEnabledForUser' ) . and . returnValue ( of ( true ) ) ;
435+
436+ const mockEntry = { ...entry ,
437+ start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
438+ start_hour : moment ( ) . format ( 'HH:mm' ) ,
439+ update_last_entry_if_overlap : true
440+ } ;
441+ component . newData = mockEntry ;
442+ component . isFeatureToggleActivated ( ) ;
443+ const expected = { update_last_entry_if_overlap : true } ;
444+ expect ( component . newData . update_last_entry_if_overlap ) . toEqual ( expected . update_last_entry_if_overlap ) ;
445+ } ) ;
446+
447+ it ( 'when FT "update-entries" disable for the user,the UpdateCurrentOrLastEntry function is called to update the entries' , ( ) => {
448+ spyOn ( featureManagerService , 'isToggleEnabledForUser' ) . and . returnValue ( of ( false ) ) ;
449+
450+ const mockEntry = { ...entry ,
451+ start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
452+ start_hour : moment ( ) . format ( 'HH:mm' ) ,
453+ update_last_entry_if_overlap : false
454+ } ;
455+ component . newData = mockEntry ;
456+ component . isFeatureToggleActivated ( ) ;
457+ const expected = { update_last_entry_if_overlap : false } ;
458+ expect ( component . newData . update_last_entry_if_overlap ) . toEqual ( expected . update_last_entry_if_overlap ) ;
459+ } ) ;
460+
461+ const toggleValues = [ true , false ] ;
462+ toggleValues . map ( ( toggleValue ) => {
463+ it ( `when FeatureToggle is ${ toggleValue } should return ${ toggleValue } ` , ( ) => {
464+ spyOn ( featureManagerService , 'isToggleEnabledForUser' ) . and . returnValue ( of ( toggleValue ) ) ;
465+
466+ const isFeatureToggleActivated : Observable < boolean > = component . isFeatureToggleActivated ( ) ;
467+
468+ expect ( featureManagerService . isToggleEnabledForUser ) . toHaveBeenCalled ( ) ;
469+ isFeatureToggleActivated . subscribe ( ( value ) => expect ( value ) . toEqual ( toggleValue ) ) ;
470+ } ) ;
471+ } ) ;
428472} ) ;
473+
474+
0 commit comments