From 91fe4e5781afec606f6d42819202330ce20ad64d Mon Sep 17 00:00:00 2001 From: Kevin Lopez Date: Thu, 22 Jul 2021 11:28:48 -0500 Subject: [PATCH] refactor: TT-295 removal unnecessary feature toggles --- .../details-fields.component.ts | 1 - .../feature-toggle-general.service.spec.ts | 3 +- .../entry-fields.component.spec.ts | 128 +----------------- .../entry-fields/entry-fields.component.ts | 26 +--- src/environments/enum.ts | 2 - 5 files changed, 4 insertions(+), 156 deletions(-) diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.ts b/src/app/modules/shared/components/details-fields/details-fields.component.ts index 82b99a121..b1d72909d 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.ts @@ -312,7 +312,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 }); } diff --git a/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.spec.ts b/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.spec.ts index 8deac72e0..b865897a3 100644 --- a/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.spec.ts +++ b/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.spec.ts @@ -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); diff --git a/src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts b/src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts index 45fed5730..57d2da186 100644 --- a/src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts +++ b/src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts @@ -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'; @@ -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; let store: MockStore; - 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) => { }, @@ -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(() => { @@ -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', diff --git a/src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts b/src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts index 9dcad89d9..bf427963f 100644 --- a/src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts +++ b/src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts @@ -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'; @@ -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; @@ -48,8 +45,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy { private store: Store, private actionsSubject$: ActionsSubject, private toastrService: ToastrService, - private featureToggleGeneralService: FeatureToggleGeneralService, - private cookiesService: CookieService, ) { this.entryForm = this.formBuilder.group({ description: '', @@ -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( @@ -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; } diff --git a/src/environments/enum.ts b/src/environments/enum.ts index 2bfaebb69..907327f21 100644 --- a/src/environments/enum.ts +++ b/src/environments/enum.ts @@ -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' }