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 e36b97433..0a1b6f7da 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 @@ -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 }); } 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..72339a2cd 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 = () => 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..32ef74547 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) => { }, @@ -105,7 +99,11 @@ describe('EntryFieldsComponent', () => { description: 'description for active entry', uri: 'abc', start_date: moment(mockDate).format(DATE_FORMAT_YEAR), - start_hour: moment(mockDate).format('HH:mm'), + start_hour: moment(mockDate).format('HH:mm') + }; + + const mockEntryOverlap = { + update_last_entry_if_overlap: true }; beforeEach(waitForAsync(() => { @@ -122,8 +120,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(() => { @@ -260,6 +256,7 @@ describe('EntryFieldsComponent', () => { }); it('when a start hour is updated, then dispatch UpdateActiveEntry', () => { + component.newData = mockEntryOverlap; component.activeEntry = entry; component.setDataToUpdate(entry); const updatedTime = moment(mockDate).format('HH:mm'); @@ -268,11 +265,13 @@ describe('EntryFieldsComponent', () => { spyOn(store, 'dispatch'); component.onUpdateStartHour(); + expect(store.dispatch).toHaveBeenCalled(); expect(component.showTimeInbuttons).toEqual(false); }); it('When start_time is updated, component.last_entry is equal to time entry in the position 1', waitForAsync(() => { + component.newData = mockEntryOverlap; component.activeEntry = entry; component.setDataToUpdate(entry); const updatedTime = moment(mockDate).format('HH:mm'); @@ -284,6 +283,7 @@ describe('EntryFieldsComponent', () => { })); it('When start_time is updated for a time entry. UpdateCurrentOrLastEntry action is dispatched', () => { + component.newData = mockEntryOverlap; component.activeEntry = entry; component.setDataToUpdate(entry); const updatedTime = moment(mockDate).subtract(4, 'hours').format('HH:mm'); @@ -440,124 +440,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..e1c164b2f 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( @@ -110,7 +94,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy { uri: this.activeEntry.uri, activity_id: this.activeEntry.activity_id, start_date: this.activeEntry.start_date, - start_hour: formatDate(this.activeEntry.start_date, 'HH:mm', 'en'), + start_hour: formatDate(this.activeEntry.start_date, 'HH:mm', 'en') }; this.activateFocus(); }); @@ -176,13 +160,8 @@ 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.newData.update_last_entry_if_overlap = true; + this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value })); this.showTimeInbuttons = false; } diff --git a/src/app/modules/time-clock/store/entry.effects.spec.ts b/src/app/modules/time-clock/store/entry.effects.spec.ts index c8769ccaf..6fd6d4f78 100644 --- a/src/app/modules/time-clock/store/entry.effects.spec.ts +++ b/src/app/modules/time-clock/store/entry.effects.spec.ts @@ -121,7 +121,11 @@ describe('TimeEntryActionEffects', () => { it('returns a LOAD_ACTIVE_ENTRY_SUCCESS when the entry that is running it is in the same day', async () => { actions$ = of({ type: EntryActionTypes.LOAD_ACTIVE_ENTRY }); const serviceSpy = spyOn(service, 'loadActiveEntry'); - serviceSpy.and.returnValue(of(entry)); + const mockEntry = { + ...entry, + start_date: new Date() + }; + serviceSpy.and.returnValue(of(mockEntry)); effects.loadActiveEntry$.subscribe(action => { expect(action.type).toEqual(EntryActionTypes.LOAD_ACTIVE_ENTRY_SUCCESS); @@ -355,8 +359,11 @@ describe('TimeEntryActionEffects', () => { it('should update last entry when UPDATE_CURRENT_OR_LAST_ENTRY is executed', async () => { actions$ = of({ type: EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY, payload: entry }); - spyOn(service, 'loadEntries').and.returnValue(of([entry, entry])); - + const lastEntryMock: Entry = { + ...entry, + end_date: moment(entry.start_date).add(4, 'h').toDate(), + }; + spyOn(service, 'loadEntries').and.returnValue(of([entry, lastEntryMock])); effects.updateCurrentOrLastEntry$.subscribe(action => { expect(action.type).toEqual(EntryActionTypes.UPDATE_ENTRY); }); 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' }