Skip to content

Commit 03d055d

Browse files
feat: TT-217 Add FT in EntryFieldsComponent component to get the new changes, add the flag to validate the current entry and last entry, add tests of the Feature Toggle - update-entries
1 parent cfa91aa commit 03d055d

File tree

2 files changed

+72
-6
lines changed

2 files changed

+72
-6
lines changed

src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Subscription } from 'rxjs';
1+
import { Subscription, of } from 'rxjs';
22
import { LoadActiveEntry, EntryActionTypes, UpdateEntry } from './../../store/entry.actions';
33
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
44
import {waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing';
@@ -15,6 +15,8 @@ import { formatDate } from '@angular/common';
1515
import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker';
1616
import * as moment from 'moment';
1717
import { DATE_FORMAT_YEAR } from 'src/environments/environment';
18+
import { FeatureManagerService } from './../../../shared/feature-toggles/feature-toggle-manager.service';
19+
1820

1921
describe('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,38 @@ describe('EntryFieldsComponent', () => {
425429
expect(component.loadActiveEntrySubscription.unsubscribe).toHaveBeenCalled();
426430
expect(component.actionSetDateSubscription.unsubscribe).toHaveBeenCalled();
427431
});
432+
433+
it('The flag "update_last_entry_if_overlap" is added to the "newData" when feature flag "update-entries" is enabled for user', () => {
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+
443+
component.isFeatureToggleActivated();
444+
445+
const expected = { update_last_entry_if_overlap: true };
446+
447+
expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
448+
});
449+
450+
it('The flag "update_last_entry_if_overlap" is not added to the "newData" when feature flag "update-entries" is disable for user', () => {
451+
spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(false));
452+
453+
const mockEntry = { ...entry,
454+
start_date : moment().format(DATE_FORMAT_YEAR),
455+
start_hour : moment().format('HH:mm'),
456+
update_last_entry_if_overlap: false
457+
};
458+
component.newData = mockEntry;
459+
460+
component.isFeatureToggleActivated();
461+
462+
const expected = { update_last_entry_if_overlap: false };
463+
464+
expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
465+
});
428466
});

src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
2-
import { EntryActionTypes, LoadActiveEntry } from './../../store/entry.actions';
3-
import { filter } from 'rxjs/operators';
2+
import { EntryActionTypes, LoadActiveEntry, UpdateCurrentOrLastEntry, UpdateEntry } from './../../store/entry.actions';
3+
import { filter, map } from 'rxjs/operators';
44
import { Component, OnDestroy, OnInit } from '@angular/core';
55
import { FormBuilder, FormGroup } from '@angular/forms';
66
import { Store, ActionsSubject, select } from '@ngrx/store';
@@ -15,7 +15,11 @@ import { ToastrService } from 'ngx-toastr';
1515
import { formatDate } from '@angular/common';
1616
import { getTimeEntriesDataSource } from '../../store/entry.selectors';
1717
import { DATE_FORMAT } from 'src/environments/environment';
18-
import { Subscription } from 'rxjs';
18+
import { Subscription, Observable } from 'rxjs';
19+
20+
import { FeatureManagerService } from './../../../shared/feature-toggles/feature-toggle-manager.service';
21+
import { AzureAdB2CService } from 'src/app/modules/login/services/azure.ad.b2c.service';
22+
1923

2024
type Merged = TechnologyState & ProjectState & ActivityState;
2125

@@ -35,12 +39,16 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
3539
loadActivitiesSubscription: Subscription;
3640
loadActiveEntrySubscription: Subscription;
3741
actionSetDateSubscription: Subscription;
42+
isEnableToggleSubscription: Subscription;
43+
isTestUser: boolean;
3844

3945
constructor(
4046
private formBuilder: FormBuilder,
4147
private store: Store<Merged>,
4248
private actionsSubject$: ActionsSubject,
43-
private toastrService: ToastrService
49+
private toastrService: ToastrService,
50+
private azureService: AzureAdB2CService,
51+
private featureManagerService: FeatureManagerService
4452
) {
4553
this.entryForm = this.formBuilder.group({
4654
description: '',
@@ -60,6 +68,11 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
6068
this.activities = action.payload;
6169
this.store.dispatch(new LoadActiveEntry());
6270
});
71+
72+
this.isEnableToggleSubscription = this.isFeatureToggleActivated().subscribe((flag) => {
73+
this.isTestUser = flag;
74+
});
75+
6376
this.loadActiveEntrySubscription = this.actionsSubject$
6477
.pipe(
6578
filter(
@@ -145,10 +158,20 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
145158
return;
146159
}
147160
this.entryForm.patchValue({ start_date: newHourEntered });
148-
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
161+
if (this.isTestUser) {
162+
this.newData.owner_id = this.getOwnerId();
163+
this.newData.update_last_entry_if_overlap = true;
164+
this.store.dispatch(new entryActions.UpdateEntry({ ...this.newData, ...this.entryForm.value }));
165+
} else {
166+
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
167+
}
149168
this.showTimeInbuttons = false;
150169
}
151170

171+
getOwnerId(){
172+
return this.azureService.getUserId();
173+
}
174+
152175
private getLastEntry() {
153176
const lastEntry$ = this.store.pipe(select(getTimeEntriesDataSource));
154177
lastEntry$.subscribe((entry) => {
@@ -178,4 +201,9 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
178201
this.loadActiveEntrySubscription.unsubscribe();
179202
this.actionSetDateSubscription.unsubscribe();
180203
}
204+
205+
isFeatureToggleActivated(): Observable<boolean> {
206+
return this.featureManagerService.isToggleEnabledForUser('update-entries')
207+
.pipe(map((enabled: boolean) => enabled));
208+
}
181209
}

0 commit comments

Comments
 (0)