Skip to content

Commit b14ee76

Browse files
fix: TT-217 Update test description, change the updateEntry method to updateEntryRunning method and improve name the flag FT
1 parent f128eef commit b14ee76

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Subscription, of } 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';
@@ -430,7 +430,7 @@ describe('EntryFieldsComponent', () => {
430430
expect(component.actionSetDateSubscription.unsubscribe).toHaveBeenCalled();
431431
});
432432

433-
it('The flag "update_last_entry_if_overlap" is added to the "newData" when feature flag "update-entries" is enabled for user', () => {
433+
it('when feature-toggle "update-entries" enable for the user, the updateEntry function is executes to update the entries', () => {
434434
spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(true));
435435

436436
const mockEntry = { ...entry,
@@ -444,7 +444,7 @@ describe('EntryFieldsComponent', () => {
444444
expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
445445
});
446446

447-
it('The flag "update_last_entry_if_overlap" is not added to the "newData" when feature flag "update-entries" is disable for user', () => {
447+
it('when FT "update-entries" disable for the user,the UpdateCurrentOrLastEntry function is called to update the entries', () => {
448448
spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(false));
449449

450450
const mockEntry = { ...entry,
@@ -457,4 +457,25 @@ describe('EntryFieldsComponent', () => {
457457
const expected = { update_last_entry_if_overlap: false };
458458
expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
459459
});
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+
});
472+
473+
// fit('should return the id of the active user', () => {
474+
475+
// const userId = 'user_id';
476+
477+
// expect( component.getOwnerId()).
478+
// });
460479
});
480+
481+

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
3939
loadActiveEntrySubscription: Subscription;
4040
actionSetDateSubscription: Subscription;
4141
isEnableToggleSubscription: Subscription;
42-
isTestUser: boolean;
42+
isFeatureToggleActive: boolean;
4343

4444
constructor(
4545
private formBuilder: FormBuilder,
@@ -69,7 +69,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
6969
});
7070

7171
this.isEnableToggleSubscription = this.isFeatureToggleActivated().subscribe((flag) => {
72-
this.isTestUser = flag;
72+
this.isFeatureToggleActive = flag;
7373
});
7474

7575
this.loadActiveEntrySubscription = this.actionsSubject$
@@ -157,10 +157,10 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
157157
return;
158158
}
159159
this.entryForm.patchValue({ start_date: newHourEntered });
160-
if (this.isTestUser) {
160+
if (this.isFeatureToggleActive) {
161161
this.newData.owner_id = this.getOwnerId();
162162
this.newData.update_last_entry_if_overlap = true;
163-
this.store.dispatch(new entryActions.UpdateEntry({ ...this.newData, ...this.entryForm.value }));
163+
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));
164164
} else {
165165
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
166166
}

0 commit comments

Comments
 (0)