Skip to content

Commit f9482ef

Browse files
kevinjlopeEdgar Guamanscastillo-jp
authored
refactor: TT-295 removal unnecessary feature toggles (#706)
* refactor: TT-295 removal unnecessary feature toggles * fix: TT-295 Undefined this.newData.update_last_entry_if_overlap = true; * fix: TT-295 newData undefined resolved * fix: TT-295 Changes in the mockEntryOvelap variable Co-authored-by: Edgar Guaman <[email protected]> Co-authored-by: Sandro Castillo <[email protected]>
1 parent b6a3fa4 commit f9482ef

File tree

5 files changed

+15
-158
lines changed

5 files changed

+15
-158
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
311311
this.toastrService.error('You cannot start a time-entry in the future');
312312
return;
313313
}
314-
315314
this.saveEntry.emit({ entry, shouldRestartEntry: this.shouldRestartEntry });
316315
}
317316

src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ describe('FeatureToggleGeneralService', () => {
2727
params.map((param) => {
2828
it(`isActivated should return a boolean ${param.bool}`, () => {
2929
const toggleName = FeatureToggle.SWITCH_GROUP;
30-
// tslint:disable-next-line: no-shadowed-variable
31-
featureManagerService.isToggleEnabledForUser = (toggleName) => of(param.bool);
30+
featureManagerService.isToggleEnabledForUser = () => of(param.bool);
3231

3332
featureToggleGeneralService.isActivated(toggleName).subscribe((enabled) => {
3433
expect(enabled).toBe(param.bool);

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

Lines changed: 10 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Subscription, of } from 'rxjs';
1+
import { Subscription } from 'rxjs';
22
import { LoadActiveEntry, EntryActionTypes } from './../../store/entry.actions';
33
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
44
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
@@ -15,21 +15,15 @@ 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 { CookieService } from 'ngx-cookie-service';
19-
import { FeatureToggleGeneralService } from './../../../shared/feature-toggles/feature-toggle-general/feature-toggle-general.service';
20-
import { FeatureToggle } from 'src/environments/enum';
21-
2218

2319
describe('EntryFieldsComponent', () => {
2420
type Merged = TechnologyState & ProjectState;
2521
let component: EntryFieldsComponent;
2622
let fixture: ComponentFixture<EntryFieldsComponent>;
2723
let store: MockStore<Merged>;
28-
let cookieService: CookieService;
2924
let mockTechnologySelector;
3025
let mockProjectsSelector;
3126
let entryForm;
32-
let featureToggleGeneralService: FeatureToggleGeneralService;
3327
const actionSub: ActionsSubject = new ActionsSubject();
3428
const toastrServiceStub = {
3529
error: (message?: string, title?: string, override?: Partial<IndividualConfig>) => { },
@@ -105,7 +99,11 @@ describe('EntryFieldsComponent', () => {
10599
description: 'description for active entry',
106100
uri: 'abc',
107101
start_date: moment(mockDate).format(DATE_FORMAT_YEAR),
108-
start_hour: moment(mockDate).format('HH:mm'),
102+
start_hour: moment(mockDate).format('HH:mm')
103+
};
104+
105+
const mockEntryOverlap = {
106+
update_last_entry_if_overlap: true
109107
};
110108

111109
beforeEach(waitForAsync(() => {
@@ -122,8 +120,6 @@ describe('EntryFieldsComponent', () => {
122120
entryForm = TestBed.inject(FormBuilder);
123121
mockTechnologySelector = store.overrideSelector(allTechnologies, state.technologies);
124122
mockProjectsSelector = store.overrideSelector(getCustomerProjects, state.projects);
125-
featureToggleGeneralService = TestBed.inject(FeatureToggleGeneralService);
126-
cookieService = TestBed.inject(CookieService);
127123
}));
128124

129125
beforeEach(() => {
@@ -260,6 +256,7 @@ describe('EntryFieldsComponent', () => {
260256
});
261257

262258
it('when a start hour is updated, then dispatch UpdateActiveEntry', () => {
259+
component.newData = mockEntryOverlap;
263260
component.activeEntry = entry;
264261
component.setDataToUpdate(entry);
265262
const updatedTime = moment(mockDate).format('HH:mm');
@@ -268,11 +265,13 @@ describe('EntryFieldsComponent', () => {
268265
spyOn(store, 'dispatch');
269266

270267
component.onUpdateStartHour();
268+
271269
expect(store.dispatch).toHaveBeenCalled();
272270
expect(component.showTimeInbuttons).toEqual(false);
273271
});
274272

275273
it('When start_time is updated, component.last_entry is equal to time entry in the position 1', waitForAsync(() => {
274+
component.newData = mockEntryOverlap;
276275
component.activeEntry = entry;
277276
component.setDataToUpdate(entry);
278277
const updatedTime = moment(mockDate).format('HH:mm');
@@ -284,6 +283,7 @@ describe('EntryFieldsComponent', () => {
284283
}));
285284

286285
it('When start_time is updated for a time entry. UpdateCurrentOrLastEntry action is dispatched', () => {
286+
component.newData = mockEntryOverlap;
287287
component.activeEntry = entry;
288288
component.setDataToUpdate(entry);
289289
const updatedTime = moment(mockDate).subtract(4, 'hours').format('HH:mm');
@@ -440,124 +440,6 @@ describe('EntryFieldsComponent', () => {
440440
expect(component.actionSetDateSubscription.unsubscribe).toHaveBeenCalled();
441441
});
442442

443-
it('when feature-toggle "update-entries" enable for the user, the updateEntry function is executes to update the entries', () => {
444-
spyOn(store, 'dispatch');
445-
const expected = { update_last_entry_if_overlap: true };
446-
const mockEntry = {
447-
...entry,
448-
start_date: moment().format(DATE_FORMAT_YEAR),
449-
start_hour: moment().format('HH:mm')
450-
};
451-
const lastMockEntry = {
452-
...entry,
453-
end_date: moment().format(DATE_FORMAT_YEAR),
454-
end_hour: moment().format('HH:mm')
455-
};
456-
const hourInTheFuture = moment().format('HH:mm');
457-
component.newData = mockEntry;
458-
component.activeEntry = mockEntry;
459-
component.lastEntry = lastMockEntry;
460-
component.isFeatureToggleActive = true;
461-
component.entryForm.patchValue({ start_hour: hourInTheFuture });
462-
463-
component.onUpdateStartHour();
464-
465-
expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
466-
expect(store.dispatch).toHaveBeenCalled();
467-
});
468-
469-
it('Set true in isCookieFeatureToggleActive when feature-toggle "feature-toggle-in-cookies" is enable for user', () => {
470-
const expectedValue = true;
471-
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(true));
472-
473-
component.ngOnInit();
474-
475-
expect(component.isCookieFeatureToggleActive).toEqual(expectedValue);
476-
});
477-
478-
it('Set false in isCookieFeatureToggleActive when feature-toggle "feature-toggle-in-cookies" is not enable for user', () => {
479-
const expectedValue = false;
480-
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(false));
481-
482-
component.ngOnInit();
483-
484-
expect(component.isCookieFeatureToggleActive).toEqual(expectedValue);
485-
});
486-
487-
488-
it('Call cookieService.get() when isCookieFeatureToggleActive is True', () => {
489-
const expectedValue = true;
490-
component.isCookieFeatureToggleActive = expectedValue;
491-
spyOn(cookieService, 'get').and.returnValue(`${expectedValue}`);
492-
493-
component.ngOnInit();
494-
495-
expect(cookieService.get).toHaveBeenCalledWith(FeatureToggle.UPDATE_ENTRIES);
496-
});
497-
498-
it('Call featureToggleGeneralService.isActivated() when isCookieFeatureToggleActive is False', () => {
499-
const expectedValue = false;
500-
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(expectedValue));
501-
502-
component.ngOnInit();
503-
504-
expect(featureToggleGeneralService.isActivated).toHaveBeenCalledWith(FeatureToggle.UPDATE_ENTRIES);
505-
});
506-
507-
it('Set True in isFeatureToggleActive when cookieService.get() return "true" and isCookieFeatureToggleActive is true', () => {
508-
const expectedValue = true;
509-
component.isCookieFeatureToggleActive = expectedValue;
510-
spyOn(cookieService, 'get').and.returnValue(`${expectedValue}`);
511-
512-
component.ngOnInit();
513-
514-
expect(component.isFeatureToggleActive).toEqual(expectedValue);
515-
});
516-
517-
it('Set True in isFeatureToggleActive when cookieService.get() return "false" and isCookieFeatureToggleActive is true', () => {
518-
const expectedValue = false;
519-
component.isCookieFeatureToggleActive = !expectedValue;
520-
spyOn(cookieService, 'get').and.returnValue(`${expectedValue}`);
521-
522-
component.ngOnInit();
523-
524-
expect(component.isFeatureToggleActive).toEqual(expectedValue);
525-
});
526-
527-
it('Set True in isFeatureToggleActive when featureToggleGeneralService.isActivated() return true', () => {
528-
const expectedValue = true;
529-
spyOn(featureToggleGeneralService, 'isActivated').and.callFake(
530-
(featureToggle) => featureToggle === FeatureToggle.COOKIES ? of(false) : of(true) );
531-
532-
component.ngOnInit();
533-
534-
expect(featureToggleGeneralService.isActivated).toHaveBeenCalledWith(FeatureToggle.UPDATE_ENTRIES);
535-
expect(component.isFeatureToggleActive).toEqual(expectedValue);
536-
});
537-
538-
it('Set False in isFeatureToggleActive when featureToggleGeneralService.isActivated() return false and isCookieFeatureToggleActive is false', () => {
539-
const expectedValue = false;
540-
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(expectedValue));
541-
542-
component.ngOnInit();
543-
544-
expect(component.isFeatureToggleActive).toEqual(expectedValue);
545-
});
546-
547-
it('when FT "update-entries" disable for the user,the UpdateCurrentOrLastEntry function is called to update the entries', () => {
548-
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(false));
549-
550-
const mockEntry = {
551-
...entry,
552-
start_date: moment().format(DATE_FORMAT_YEAR),
553-
start_hour: moment().format('HH:mm')
554-
};
555-
component.newData = mockEntry;
556-
featureToggleGeneralService.isActivated(FeatureToggle.UPDATE_ENTRIES).subscribe(() => {
557-
expect(featureToggleGeneralService.isActivated).toHaveBeenCalled();
558-
});
559-
});
560-
561443
it('when a activity is not register in DB should show activatefocus in select activity', () => {
562444
const activitiesMock = [{
563445
id: 'xyz',

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

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { FeatureToggleGeneralService } from './../../../shared/feature-toggles/feature-toggle-general/feature-toggle-general.service';
21
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
3-
import { EntryActionTypes, LoadActiveEntry, UpdateCurrentOrLastEntry, UpdateEntry, UpdateEntryRunning } from './../../store/entry.actions';
2+
import { EntryActionTypes, LoadActiveEntry } from './../../store/entry.actions';
43
import { filter} from 'rxjs/operators';
54
import { Component, OnDestroy, OnInit, ElementRef, ViewChild } from '@angular/core';
65
import { FormBuilder, FormGroup } from '@angular/forms';
@@ -17,8 +16,6 @@ import { formatDate } from '@angular/common';
1716
import { getTimeEntriesDataSource } from '../../store/entry.selectors';
1817
import { DATE_FORMAT } from 'src/environments/environment';
1918
import { Subscription, } from 'rxjs';
20-
import { FeatureToggle } from './../../../../../environments/enum';
21-
import { CookieService } from 'ngx-cookie-service';
2219

2320
type Merged = TechnologyState & ProjectState & ActivityState;
2421

@@ -48,8 +45,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
4845
private store: Store<Merged>,
4946
private actionsSubject$: ActionsSubject,
5047
private toastrService: ToastrService,
51-
private featureToggleGeneralService: FeatureToggleGeneralService,
52-
private cookiesService: CookieService,
5348
) {
5449
this.entryForm = this.formBuilder.group({
5550
description: '',
@@ -70,17 +65,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
7065
this.store.dispatch(new LoadActiveEntry());
7166
});
7267

73-
this.featureToggleGeneralService.isActivated(FeatureToggle.COOKIES).subscribe((flag) => {
74-
this.isCookieFeatureToggleActive = flag;
75-
});
76-
77-
if (this.isCookieFeatureToggleActive){
78-
this.isFeatureToggleActive = this.cookiesService.get(FeatureToggle.UPDATE_ENTRIES) === 'true' ? true : false;
79-
}else{
80-
this.featureToggleGeneralService.isActivated(FeatureToggle.UPDATE_ENTRIES).subscribe((flag) => {
81-
this.isFeatureToggleActive = flag;
82-
});
83-
}
8468
this.loadActiveEntrySubscription = this.actionsSubject$
8569
.pipe(
8670
filter(
@@ -110,7 +94,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
11094
uri: this.activeEntry.uri,
11195
activity_id: this.activeEntry.activity_id,
11296
start_date: this.activeEntry.start_date,
113-
start_hour: formatDate(this.activeEntry.start_date, 'HH:mm', 'en'),
97+
start_hour: formatDate(this.activeEntry.start_date, 'HH:mm', 'en')
11498
};
11599
this.activateFocus();
116100
});
@@ -176,13 +160,8 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
176160
return;
177161
}
178162
this.entryForm.patchValue({ start_date: newHourEntered });
179-
if (this.isFeatureToggleActive) {
180-
this.newData.update_last_entry_if_overlap = true;
181-
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));
182-
183-
} else {
184-
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
185-
}
163+
this.newData.update_last_entry_if_overlap = true;
164+
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));
186165
this.showTimeInbuttons = false;
187166
}
188167

src/environments/enum.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
export enum FeatureToggle {
22
SWITCH_GROUP = 'switch-group',
3-
UPDATE_ENTRIES = 'update-entries',
4-
COOKIES = 'feature-toggle-in-cookies',
53
TIME_TRACKER_CALENDAR = 'time-tracker-calendar'
64
}

0 commit comments

Comments
 (0)