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
feat: TT-217 Add FT in EntryFieldsComponent component to get the new …
…changes, add the flag to validate the current entry and last entry, add tests of the Feature Toggle - update-entries
  • Loading branch information
VanessaIniguezG committed Apr 13, 2021
commit 03d055ddd23b448ee92bef4c8f4983a2b910fe89
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Subscription } from 'rxjs';
import { Subscription, of } 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 All @@ -15,6 +15,8 @@ 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 { FeatureManagerService } from './../../../shared/feature-toggles/feature-toggle-manager.service';


describe('EntryFieldsComponent', () => {
type Merged = TechnologyState & ProjectState;
Expand All @@ -24,6 +26,7 @@ describe('EntryFieldsComponent', () => {
let mockTechnologySelector;
let mockProjectsSelector;
let entryForm;
let featureManagerService: FeatureManagerService;
const actionSub: ActionsSubject = new ActionsSubject();
const toastrServiceStub = {
error: (message?: string, title?: string, override?: Partial<IndividualConfig>) => { },
Expand Down Expand Up @@ -114,6 +117,7 @@ describe('EntryFieldsComponent', () => {
entryForm = TestBed.inject(FormBuilder);
mockTechnologySelector = store.overrideSelector(allTechnologies, state.technologies);
mockProjectsSelector = store.overrideSelector(getCustomerProjects, state.projects);
featureManagerService = TestBed.inject(FeatureManagerService);
}));

beforeEach(() => {
Expand Down Expand Up @@ -425,4 +429,38 @@ describe('EntryFieldsComponent', () => {
expect(component.loadActiveEntrySubscription.unsubscribe).toHaveBeenCalled();
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', () => {
spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(true));

const mockEntry = { ...entry,
start_date : moment().format(DATE_FORMAT_YEAR),
start_hour : moment().format('HH:mm'),
update_last_entry_if_overlap: true
};
component.newData = mockEntry;

component.isFeatureToggleActivated();

const expected = { update_last_entry_if_overlap: true };

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', () => {
spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(false));

const mockEntry = { ...entry,
start_date : moment().format(DATE_FORMAT_YEAR),
start_hour : moment().format('HH:mm'),
update_last_entry_if_overlap: false
};
component.newData = mockEntry;

component.isFeatureToggleActivated();

const expected = { update_last_entry_if_overlap: false };

expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
import { EntryActionTypes, LoadActiveEntry } from './../../store/entry.actions';
import { filter } from 'rxjs/operators';
import { EntryActionTypes, LoadActiveEntry, UpdateCurrentOrLastEntry, UpdateEntry } from './../../store/entry.actions';
import { filter, map } from 'rxjs/operators';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Store, ActionsSubject, select } from '@ngrx/store';
Expand All @@ -15,7 +15,11 @@ import { ToastrService } from 'ngx-toastr';
import { formatDate } from '@angular/common';
import { getTimeEntriesDataSource } from '../../store/entry.selectors';
import { DATE_FORMAT } from 'src/environments/environment';
import { Subscription } from 'rxjs';
import { Subscription, Observable } from 'rxjs';

import { FeatureManagerService } from './../../../shared/feature-toggles/feature-toggle-manager.service';
import { AzureAdB2CService } from 'src/app/modules/login/services/azure.ad.b2c.service';


type Merged = TechnologyState & ProjectState & ActivityState;

Expand All @@ -35,12 +39,16 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
loadActivitiesSubscription: Subscription;
loadActiveEntrySubscription: Subscription;
actionSetDateSubscription: Subscription;
isEnableToggleSubscription: Subscription;
isTestUser: boolean;

constructor(
private formBuilder: FormBuilder,
private store: Store<Merged>,
private actionsSubject$: ActionsSubject,
private toastrService: ToastrService
private toastrService: ToastrService,
private azureService: AzureAdB2CService,
private featureManagerService: FeatureManagerService
) {
this.entryForm = this.formBuilder.group({
description: '',
Expand All @@ -60,6 +68,11 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
this.activities = action.payload;
this.store.dispatch(new LoadActiveEntry());
});

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

this.loadActiveEntrySubscription = this.actionsSubject$
.pipe(
filter(
Expand Down Expand Up @@ -145,10 +158,20 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
return;
}
this.entryForm.patchValue({ start_date: newHourEntered });
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
if (this.isTestUser) {
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 }));
} else {
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
}
this.showTimeInbuttons = false;
}

getOwnerId(){
return this.azureService.getUserId();
}

private getLastEntry() {
const lastEntry$ = this.store.pipe(select(getTimeEntriesDataSource));
lastEntry$.subscribe((entry) => {
Expand Down Expand Up @@ -178,4 +201,9 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
this.loadActiveEntrySubscription.unsubscribe();
this.actionSetDateSubscription.unsubscribe();
}

isFeatureToggleActivated(): Observable<boolean> {
return this.featureManagerService.isToggleEnabledForUser('update-entries')
.pipe(map((enabled: boolean) => enabled));
}
}