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
Next Next commit
refactor: TT-295 removal unnecessary feature toggles
  • Loading branch information
kevinjlope authored and Edgar Guaman committed Aug 3, 2021
commit 591e75a4820b8d03c48eff130fc9204dc689d4ff
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
this.toastrService.error('You cannot start a time-entry in the future');
return;
}

this.saveEntry.emit({ entry, shouldRestartEntry: this.shouldRestartEntry });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ describe('FeatureToggleGeneralService', () => {
params.map((param) => {
it(`isActivated should return a boolean ${param.bool}`, () => {
const toggleName = FeatureToggle.SWITCH_GROUP;
// tslint:disable-next-line: no-shadowed-variable
featureManagerService.isToggleEnabledForUser = (toggleName) => of(param.bool);
featureManagerService.isToggleEnabledForUser = (toggleNameV) => of(param.bool);

featureToggleGeneralService.isActivated(toggleName).subscribe((enabled) => {
expect(enabled).toBe(param.bool);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Subscription, of } from 'rxjs';
import { Subscription } from 'rxjs';
import { LoadActiveEntry, EntryActionTypes } from './../../store/entry.actions';
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
Expand All @@ -15,21 +15,15 @@ import { formatDate } from '@angular/common';
import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker';
import * as moment from 'moment';
import { DATE_FORMAT_YEAR } from 'src/environments/environment';
import { CookieService } from 'ngx-cookie-service';
import { FeatureToggleGeneralService } from './../../../shared/feature-toggles/feature-toggle-general/feature-toggle-general.service';
import { FeatureToggle } from 'src/environments/enum';


describe('EntryFieldsComponent', () => {
type Merged = TechnologyState & ProjectState;
let component: EntryFieldsComponent;
let fixture: ComponentFixture<EntryFieldsComponent>;
let store: MockStore<Merged>;
let cookieService: CookieService;
let mockTechnologySelector;
let mockProjectsSelector;
let entryForm;
let featureToggleGeneralService: FeatureToggleGeneralService;
const actionSub: ActionsSubject = new ActionsSubject();
const toastrServiceStub = {
error: (message?: string, title?: string, override?: Partial<IndividualConfig>) => { },
Expand Down Expand Up @@ -122,8 +116,6 @@ describe('EntryFieldsComponent', () => {
entryForm = TestBed.inject(FormBuilder);
mockTechnologySelector = store.overrideSelector(allTechnologies, state.technologies);
mockProjectsSelector = store.overrideSelector(getCustomerProjects, state.projects);
featureToggleGeneralService = TestBed.inject(FeatureToggleGeneralService);
cookieService = TestBed.inject(CookieService);
}));

beforeEach(() => {
Expand Down Expand Up @@ -440,124 +432,6 @@ describe('EntryFieldsComponent', () => {
expect(component.actionSetDateSubscription.unsubscribe).toHaveBeenCalled();
});

it('when feature-toggle "update-entries" enable for the user, the updateEntry function is executes to update the entries', () => {
spyOn(store, 'dispatch');
const expected = { update_last_entry_if_overlap: true };
const mockEntry = {
...entry,
start_date: moment().format(DATE_FORMAT_YEAR),
start_hour: moment().format('HH:mm')
};
const lastMockEntry = {
...entry,
end_date: moment().format(DATE_FORMAT_YEAR),
end_hour: moment().format('HH:mm')
};
const hourInTheFuture = moment().format('HH:mm');
component.newData = mockEntry;
component.activeEntry = mockEntry;
component.lastEntry = lastMockEntry;
component.isFeatureToggleActive = true;
component.entryForm.patchValue({ start_hour: hourInTheFuture });

component.onUpdateStartHour();

expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
expect(store.dispatch).toHaveBeenCalled();
});

it('Set true in isCookieFeatureToggleActive when feature-toggle "feature-toggle-in-cookies" is enable for user', () => {
const expectedValue = true;
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(true));

component.ngOnInit();

expect(component.isCookieFeatureToggleActive).toEqual(expectedValue);
});

it('Set false in isCookieFeatureToggleActive when feature-toggle "feature-toggle-in-cookies" is not enable for user', () => {
const expectedValue = false;
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(false));

component.ngOnInit();

expect(component.isCookieFeatureToggleActive).toEqual(expectedValue);
});


it('Call cookieService.get() when isCookieFeatureToggleActive is True', () => {
const expectedValue = true;
component.isCookieFeatureToggleActive = expectedValue;
spyOn(cookieService, 'get').and.returnValue(`${expectedValue}`);

component.ngOnInit();

expect(cookieService.get).toHaveBeenCalledWith(FeatureToggle.UPDATE_ENTRIES);
});

it('Call featureToggleGeneralService.isActivated() when isCookieFeatureToggleActive is False', () => {
const expectedValue = false;
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(expectedValue));

component.ngOnInit();

expect(featureToggleGeneralService.isActivated).toHaveBeenCalledWith(FeatureToggle.UPDATE_ENTRIES);
});

it('Set True in isFeatureToggleActive when cookieService.get() return "true" and isCookieFeatureToggleActive is true', () => {
const expectedValue = true;
component.isCookieFeatureToggleActive = expectedValue;
spyOn(cookieService, 'get').and.returnValue(`${expectedValue}`);

component.ngOnInit();

expect(component.isFeatureToggleActive).toEqual(expectedValue);
});

it('Set True in isFeatureToggleActive when cookieService.get() return "false" and isCookieFeatureToggleActive is true', () => {
const expectedValue = false;
component.isCookieFeatureToggleActive = !expectedValue;
spyOn(cookieService, 'get').and.returnValue(`${expectedValue}`);

component.ngOnInit();

expect(component.isFeatureToggleActive).toEqual(expectedValue);
});

it('Set True in isFeatureToggleActive when featureToggleGeneralService.isActivated() return true', () => {
const expectedValue = true;
spyOn(featureToggleGeneralService, 'isActivated').and.callFake(
(featureToggle) => featureToggle === FeatureToggle.COOKIES ? of(false) : of(true) );

component.ngOnInit();

expect(featureToggleGeneralService.isActivated).toHaveBeenCalledWith(FeatureToggle.UPDATE_ENTRIES);
expect(component.isFeatureToggleActive).toEqual(expectedValue);
});

it('Set False in isFeatureToggleActive when featureToggleGeneralService.isActivated() return false and isCookieFeatureToggleActive is false', () => {
const expectedValue = false;
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(expectedValue));

component.ngOnInit();

expect(component.isFeatureToggleActive).toEqual(expectedValue);
});

it('when FT "update-entries" disable for the user,the UpdateCurrentOrLastEntry function is called to update the entries', () => {
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(false));

const mockEntry = {
...entry,
start_date: moment().format(DATE_FORMAT_YEAR),
start_hour: moment().format('HH:mm')
};
component.newData = mockEntry;
featureToggleGeneralService.isActivated(FeatureToggle.UPDATE_ENTRIES).subscribe(() => {
expect(featureToggleGeneralService.isActivated).toHaveBeenCalled();
});
});

it('when a activity is not register in DB should show activatefocus in select activity', () => {
const activitiesMock = [{
id: 'xyz',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { FeatureToggleGeneralService } from './../../../shared/feature-toggles/feature-toggle-general/feature-toggle-general.service';
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
import { EntryActionTypes, LoadActiveEntry, UpdateCurrentOrLastEntry, UpdateEntry, UpdateEntryRunning } from './../../store/entry.actions';
import { EntryActionTypes, LoadActiveEntry } from './../../store/entry.actions';
import { filter} from 'rxjs/operators';
import { Component, OnDestroy, OnInit, ElementRef, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
Expand All @@ -17,8 +16,6 @@ import { formatDate } from '@angular/common';
import { getTimeEntriesDataSource } from '../../store/entry.selectors';
import { DATE_FORMAT } from 'src/environments/environment';
import { Subscription, } from 'rxjs';
import { FeatureToggle } from './../../../../../environments/enum';
import { CookieService } from 'ngx-cookie-service';

type Merged = TechnologyState & ProjectState & ActivityState;

Expand Down Expand Up @@ -48,8 +45,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
private store: Store<Merged>,
private actionsSubject$: ActionsSubject,
private toastrService: ToastrService,
private featureToggleGeneralService: FeatureToggleGeneralService,
private cookiesService: CookieService,
) {
this.entryForm = this.formBuilder.group({
description: '',
Expand All @@ -70,17 +65,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
this.store.dispatch(new LoadActiveEntry());
});

this.featureToggleGeneralService.isActivated(FeatureToggle.COOKIES).subscribe((flag) => {
this.isCookieFeatureToggleActive = flag;
});

if (this.isCookieFeatureToggleActive){
this.isFeatureToggleActive = this.cookiesService.get(FeatureToggle.UPDATE_ENTRIES) === 'true' ? true : false;
}else{
this.featureToggleGeneralService.isActivated(FeatureToggle.UPDATE_ENTRIES).subscribe((flag) => {
this.isFeatureToggleActive = flag;
});
}
this.loadActiveEntrySubscription = this.actionsSubject$
.pipe(
filter(
Expand Down Expand Up @@ -176,13 +160,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
return;
}
this.entryForm.patchValue({ start_date: newHourEntered });
if (this.isFeatureToggleActive) {
this.newData.update_last_entry_if_overlap = true;
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));

} else {
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
}
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
this.showTimeInbuttons = false;
}

Expand Down
2 changes: 0 additions & 2 deletions src/environments/enum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export enum FeatureToggle {
SWITCH_GROUP = 'switch-group',
UPDATE_ENTRIES = 'update-entries',
COOKIES = 'feature-toggle-in-cookies',
TIME_TRACKER_CALENDAR = 'time-tracker-calendar'
}