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
Prev Previous commit
TT-70 fix: Fix comments by Jose
  • Loading branch information
PaulRC-ioet committed Dec 17, 2020
commit 8fd8bff49f5cf6a3c79761dccf910d0e55bc4be1
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ describe('EntryFieldsComponent', () => {
expect(component.lastEntry).toBe(state.entries.timeEntriesDataSource.data[1]);
}));

it('When start_time is updated for a time entry. UpdateTwoEntry action is dispatched', () => {
it('When start_time is updated for a time entry. UpdateCurrentOrLastEntry action is dispatched', () => {
component.activeEntry = entry ;
component.setDataToUpdate(entry);
const updatedTime = moment().subtract(4, 'hours').format('HH:mm');
Expand Down Expand Up @@ -367,7 +367,7 @@ describe('EntryFieldsComponent', () => {
expect(store.dispatch).toHaveBeenCalledWith(new LoadActiveEntry());
});

it('when entry has an end_date then update time entry running and load entries', () => {
it('When update current or last entry then the actions updateEntryRunning, LoadEntries and LoadEntriSummary will be dispatched', () => {
spyOn(store, 'dispatch');

const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class EntryFieldsComponent implements OnInit {
return;
}
this.entryForm.patchValue({ start_date: newHourEntered });
this.store.dispatch(new entryActions.UpdateTwoEntries({ ...this.newData, ...this.entryForm.value }));
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
this.showTimeInbuttons = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
).subscribe((action) => {
this.activeEntry = action.payload;
this.setSelectedProject();
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
this.store.dispatch(new entryActions.LoadActiveEntry());
});

}
Expand Down
12 changes: 6 additions & 6 deletions src/app/modules/time-clock/store/entry.actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ describe('Actions for Entries', () => {
expect(action.type).toEqual(actions.EntryActionTypes.RESTART_ENTRY_FAIL);
});

it('UpdateTwoEntries type is EntryActionTypes.UPDATE_TWO_ENTRIES', () => {
const action = new actions.UpdateTwoEntries(entry);
expect(action.type).toEqual(actions.EntryActionTypes.UPDATE_TWO_ENTRIES);
it('UpdateCurrentOrLastEntry type is EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY', () => {
const action = new actions.UpdateCurrentOrLastEntry(entry);
expect(action.type).toEqual(actions.EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY);
});

it('UpdateTwoEntriesFail type is EntryActionTypes.UPDATE_TWO_ENTRIES_FAIL', () => {
const action = new actions.UpdateTwoEntriesFail('error');
expect(action.type).toEqual(actions.EntryActionTypes.UPDATE_TWO_ENTRIES_FAIL);
it('UpdateCurrentOrLastEntryFail type is EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY_FAIL', () => {
const action = new actions.UpdateCurrentOrLastEntryFail('error');
expect(action.type).toEqual(actions.EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY_FAIL);
});
});
16 changes: 8 additions & 8 deletions src/app/modules/time-clock/store/entry.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export enum EntryActionTypes {
UPDATE_ENTRY_RUNNING = '[Entry] UPDATE_ENTRY_RUNNING',
UPDATE_ENTRY = '[Entry] UPDATE_ENTRY',
UPDATE_ENTRY_SUCCESS = '[Entry] UPDATE_ENTRY_SUCCESS',
UPDATE_TWO_ENTRIES = '[Entry] UPDATE_TWO_ENTRIES',
UPDATE_TWO_ENTRIES_FAIL = '[Entry] UPDATE_TWO_ENTRIES_FAIL',
UPDATE_CURRENT_OR_LAST_ENTRY = '[Entry] UPDATE_CURRENT_OR_LAST_ENTRY',
UPDATE_CURRENT_OR_LAST_ENTRY_FAIL = '[Entry] UPDATE_CURRENT_OR_LAST_ENTRY_FAIL',
UPDATE_ENTRY_FAIL = '[Entry] UPDATE_ENTRY_FAIL',
DELETE_ENTRY = '[Entry] DELETE_ENTRY',
DELETE_ENTRY_SUCCESS = '[Entry] DELETE_ENTRY_SUCCESS',
Expand Down Expand Up @@ -185,14 +185,14 @@ export class UpdateEntryFail implements Action {
}
}

export class UpdateTwoEntries implements Action {
public readonly type = EntryActionTypes.UPDATE_TWO_ENTRIES;
export class UpdateCurrentOrLastEntry implements Action {
public readonly type = EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY;

constructor(public payload) {
}
}
export class UpdateTwoEntriesFail implements Action {
public readonly type = EntryActionTypes.UPDATE_TWO_ENTRIES_FAIL;
export class UpdateCurrentOrLastEntryFail implements Action {
public readonly type = EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY_FAIL;

constructor(public error: string) {
}
Expand Down Expand Up @@ -311,5 +311,5 @@ export type EntryActions =
| RestartEntry
| RestartEntrySuccess
| RestartEntryFail
| UpdateTwoEntries
| UpdateTwoEntriesFail;
| UpdateCurrentOrLastEntry
| UpdateCurrentOrLastEntryFail;
39 changes: 32 additions & 7 deletions src/app/modules/time-clock/store/entry.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ describe('TimeEntryActionEffects', () => {
let toastrService;
const entry: Entry = { project_id: 'p-id', start_date: new Date(), id: 'id' };

const dateTest = moment().format('YYYY-MM-DD');
const endHourTest = moment().subtract(5, 'hours').format('HH:mm:ss');
const startHourTest = moment().subtract(3, 'hours').format('HH:mm:ss');
const endDateTest = new Date(`${dateTest}T${endHourTest.trim()}`);
const startDateTest = new Date(`${dateTest}T${startHourTest.trim()}`);

const entryUpdate = {
id: 'id',
project_id: 'p-id',
start_date : startDateTest,
start_hour : moment().subtract(1, 'hours').format('HH:mm'),
};

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
Expand Down Expand Up @@ -340,21 +353,33 @@ describe('TimeEntryActionEffects', () => {
});
});

it('action type is UPDATE_ENTRY when UPDATE_TWO_ENTRIES executed', async () => {
actions$ = of({ type: EntryActionTypes.UPDATE_TWO_ENTRIES, payload: entry });
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]));

effects.updateLastEntryAndNew$.subscribe(action => {
effects.updateCurrentOrLastEntry$.subscribe(action => {
expect(action.type).toEqual(EntryActionTypes.UPDATE_ENTRY);
});
});

it('action type is UPDATE_TWO_ENTRIES_FAIL when service fail in execution', async () => {
actions$ = of({ type: EntryActionTypes.UPDATE_TWO_ENTRIES, payload: entry });
it('should update current entry when UPDATE_CURRENT_OR_LAST_ENTRY is executed', async () => {
const lastEntry: Entry = { project_id: 'p-id', start_date: new Date(), id: 'id', end_date: endDateTest};
actions$ = of({ type: EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY, payload: entryUpdate });
spyOn(service, 'loadEntries').and.returnValue(of([lastEntry, lastEntry]));
spyOn(toastrService, 'success');

effects.updateCurrentOrLastEntry$.subscribe(action => {
expect(toastrService.success).toHaveBeenCalledWith('You change the time-in successfully');
expect(action.type).toEqual(EntryActionTypes.UPDATE_ENTRY_RUNNING);
});
});

it('action type is UPDATE_CURRENT_OR_LAST_ENTRY_FAIL when service fail in execution', async () => {
actions$ = of({ type: EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY, payload: entry });
spyOn(service, 'loadEntries').and.returnValue(throwError({ error: { message: 'fail!' } }));

effects.updateLastEntryAndNew$.subscribe((action) => {
expect(action.type).toEqual(EntryActionTypes.UPDATE_TWO_ENTRIES_FAIL);
effects.updateCurrentOrLastEntry$.subscribe((action) => {
expect(action.type).toEqual(EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY_FAIL);
});
});
});
14 changes: 7 additions & 7 deletions src/app/modules/time-clock/store/entry.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,24 @@ export class EntryEffects {
);

@Effect()
updateLastEntryAndNew$: Observable<Action> = this.actions$.pipe(
ofType(actions.EntryActionTypes.UPDATE_TWO_ENTRIES),
map((action: actions.UpdateTwoEntries) => action.payload),
updateCurrentOrLastEntry$: Observable<Action> = this.actions$.pipe(
ofType(actions.EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY),
map((action: actions.UpdateCurrentOrLastEntry) => action.payload),
switchMap((entry) =>
this.entryService.loadEntries(new Date().getMonth() + 1).pipe(
map((entries) => {
const lastEntry = entries[1];
const isInLastEntry = moment(entry.start_date).isBefore(lastEntry.end_date);
if (isInLastEntry) {
const isStartTimeInLastEntry = moment(entry.start_date).isBefore(lastEntry.end_date);
if (isStartTimeInLastEntry) {
return new actions.UpdateEntry({ id: lastEntry.id, end_date: entry.start_date });
} else {
this.toastrService.success('You change the time in successfully');
this.toastrService.success('You change the time-in successfully');
return new actions.UpdateEntryRunning(entry);
}
}),
catchError((error) => {
this.toastrService.error(error.error.message);
return of(new actions.UpdateTwoEntriesFail('error'));
return of(new actions.UpdateCurrentOrLastEntryFail('error'));
})
)
)
Expand Down
12 changes: 10 additions & 2 deletions src/app/modules/time-clock/store/entry.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,21 @@ describe('entryReducer', () => {
expect(state.isLoading).toEqual(true);
});

it('on UpdateTwoEntries, isLoading is true', () => {
const action = new actions.UpdateTwoEntries(newEntry);
it('on UpdateCurrentOrLastEntry, isLoading is true', () => {
const action = new actions.UpdateCurrentOrLastEntry(newEntry);
const state = entryReducer(initialState, action);

expect(state.isLoading).toEqual(true);
});

it('on UpdateCurrentOrLastEntryFail, isLoading is false and give a message', () => {
const action = new actions.UpdateCurrentOrLastEntryFail('fail');
const state = entryReducer(initialState, action);

expect(state.isLoading).toEqual(false);
expect(state.message).toEqual('Update Current or Last Entry Fail');
});

it('on UpdateActiveEntrySuccess, loading is false', () => {
const action = new actions.UpdateEntrySuccess(entry);

Expand Down
6 changes: 3 additions & 3 deletions src/app/modules/time-clock/store/entry.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,18 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
};
}

case EntryActionTypes.UPDATE_TWO_ENTRIES: {
case EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY: {
return {
...state,
isLoading: true,
};
}

case EntryActionTypes.UPDATE_TWO_ENTRIES_FAIL: {
case EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY_FAIL: {
return {
...state,
isLoading: false,
message: 'Update Two Entries Fail',
message: 'Update Current or Last Entry Fail',
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
const isEditingEntryEqualToActiveEntry = this.entryId === this.activeTimeEntry.id;
const isStartDateGreaterThanActiveEntry = startDateAsLocalDate > activeEntryAsLocalDate;
const isEndDateGreaterThanActiveEntry = endDateAsLocalDate > activeEntryAsLocalDate;
if (!isEditingEntryEqualToActiveEntry && (isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry)) {
const isTimeEntryOverlapping = isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry;
if (!isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping) {
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
} else {
this.doSave(event);
Expand Down