Skip to content

Commit d88991c

Browse files
Merge 86032d5 into 133aef1
2 parents 133aef1 + 86032d5 commit d88991c

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Subscription } from 'rxjs';
1+
import { Subscription, of, Observable } 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,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+

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

Lines changed: 24 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,8 @@ 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+
import { FeatureManagerService } from './../../../shared/feature-toggles/feature-toggle-manager.service';
1920

2021
type Merged = TechnologyState & ProjectState & ActivityState;
2122

@@ -35,12 +36,15 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
3536
loadActivitiesSubscription: Subscription;
3637
loadActiveEntrySubscription: Subscription;
3738
actionSetDateSubscription: Subscription;
39+
isEnableToggleSubscription: Subscription;
40+
isFeatureToggleActive: boolean;
3841

3942
constructor(
4043
private formBuilder: FormBuilder,
4144
private store: Store<Merged>,
4245
private actionsSubject$: ActionsSubject,
43-
private toastrService: ToastrService
46+
private toastrService: ToastrService,
47+
private featureManagerService: FeatureManagerService
4448
) {
4549
this.entryForm = this.formBuilder.group({
4650
description: '',
@@ -60,6 +64,11 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
6064
this.activities = action.payload;
6165
this.store.dispatch(new LoadActiveEntry());
6266
});
67+
68+
this.isEnableToggleSubscription = this.isFeatureToggleActivated().subscribe((flag) => {
69+
this.isFeatureToggleActive = flag;
70+
});
71+
6372
this.loadActiveEntrySubscription = this.actionsSubject$
6473
.pipe(
6574
filter(
@@ -145,7 +154,12 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
145154
return;
146155
}
147156
this.entryForm.patchValue({ start_date: newHourEntered });
148-
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
157+
if (this.isFeatureToggleActive) {
158+
this.newData.update_last_entry_if_overlap = true;
159+
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));
160+
} else {
161+
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
162+
}
149163
this.showTimeInbuttons = false;
150164
}
151165

@@ -178,4 +192,9 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
178192
this.loadActiveEntrySubscription.unsubscribe();
179193
this.actionSetDateSubscription.unsubscribe();
180194
}
195+
196+
isFeatureToggleActivated(): Observable<boolean> {
197+
return this.featureManagerService.isToggleEnabledForUser('update-entries')
198+
.pipe(map((enabled: boolean) => enabled));
199+
}
181200
}

0 commit comments

Comments
 (0)