Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: TT-217 Update test description, change the updateEntry method to…
… updateEntryRunning method and improve name the flag FT
  • Loading branch information
VanessaIniguezG committed Apr 15, 2021
commit b14ee76d60c3db4b32557cdf4b106b5b561d8dd0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Subscription, of } from 'rxjs';
import { Subscription, of, Observable } from 'rxjs';
import { LoadActiveEntry, EntryActionTypes, UpdateEntry } from './../../store/entry.actions';
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
import {waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing';
Expand Down Expand Up @@ -430,7 +430,7 @@ describe('EntryFieldsComponent', () => {
expect(component.actionSetDateSubscription.unsubscribe).toHaveBeenCalled();
});

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

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

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

const mockEntry = { ...entry,
Expand All @@ -457,4 +457,25 @@ describe('EntryFieldsComponent', () => {
const expected = { update_last_entry_if_overlap: false };
expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
});

const toggleValues = [true, false];
toggleValues.map((toggleValue) => {
it(`when FeatureToggle is ${toggleValue} should return ${toggleValue}`, () => {
spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(toggleValue));

const isFeatureToggleActivated: Observable<boolean> = component.isFeatureToggleActivated();

expect(featureManagerService.isToggleEnabledForUser).toHaveBeenCalled();
isFeatureToggleActivated.subscribe((value) => expect(value).toEqual(toggleValue));
});
});

// fit('should return the id of the active user', () => {

// const userId = 'user_id';

// expect( component.getOwnerId()).
// });
});


Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
loadActiveEntrySubscription: Subscription;
actionSetDateSubscription: Subscription;
isEnableToggleSubscription: Subscription;
isTestUser: boolean;
isFeatureToggleActive: boolean;

constructor(
private formBuilder: FormBuilder,
Expand Down Expand Up @@ -69,7 +69,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
});

this.isEnableToggleSubscription = this.isFeatureToggleActivated().subscribe((flag) => {
this.isTestUser = flag;
this.isFeatureToggleActive = flag;
});

this.loadActiveEntrySubscription = this.actionsSubject$
Expand Down Expand Up @@ -157,10 +157,10 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
return;
}
this.entryForm.patchValue({ start_date: newHourEntered });
if (this.isTestUser) {
if (this.isFeatureToggleActive) {
this.newData.owner_id = this.getOwnerId();
this.newData.update_last_entry_if_overlap = true;
this.store.dispatch(new entryActions.UpdateEntry({ ...this.newData, ...this.entryForm.value }));
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));
} else {
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
}
Expand Down