1
- import { Subscription } from 'rxjs' ;
1
+ import { Subscription , of , Observable } from 'rxjs' ;
2
2
import { LoadActiveEntry , EntryActionTypes , UpdateEntry } from './../../store/entry.actions' ;
3
3
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions' ;
4
4
import { waitForAsync , ComponentFixture , TestBed } from '@angular/core/testing' ;
@@ -15,6 +15,8 @@ import { formatDate } from '@angular/common';
15
15
import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker' ;
16
16
import * as moment from 'moment' ;
17
17
import { DATE_FORMAT_YEAR } from 'src/environments/environment' ;
18
+ import { FeatureManagerService } from './../../../shared/feature-toggles/feature-toggle-manager.service' ;
19
+
18
20
19
21
describe ( 'EntryFieldsComponent' , ( ) => {
20
22
type Merged = TechnologyState & ProjectState ;
@@ -24,6 +26,7 @@ describe('EntryFieldsComponent', () => {
24
26
let mockTechnologySelector ;
25
27
let mockProjectsSelector ;
26
28
let entryForm ;
29
+ let featureManagerService : FeatureManagerService ;
27
30
const actionSub : ActionsSubject = new ActionsSubject ( ) ;
28
31
const toastrServiceStub = {
29
32
error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { } ,
@@ -114,6 +117,7 @@ describe('EntryFieldsComponent', () => {
114
117
entryForm = TestBed . inject ( FormBuilder ) ;
115
118
mockTechnologySelector = store . overrideSelector ( allTechnologies , state . technologies ) ;
116
119
mockProjectsSelector = store . overrideSelector ( getCustomerProjects , state . projects ) ;
120
+ featureManagerService = TestBed . inject ( FeatureManagerService ) ;
117
121
} ) ) ;
118
122
119
123
beforeEach ( ( ) => {
@@ -425,4 +429,46 @@ describe('EntryFieldsComponent', () => {
425
429
expect ( component . loadActiveEntrySubscription . unsubscribe ) . toHaveBeenCalled ( ) ;
426
430
expect ( component . actionSetDateSubscription . unsubscribe ) . toHaveBeenCalled ( ) ;
427
431
} ) ;
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
+ } ) ;
428
472
} ) ;
473
+
474
+
0 commit comments