Skip to content

Commit 06f895a

Browse files
committed
TT-70 fix: Fix comments by Jose
1 parent 1e1fd38 commit 06f895a

File tree

10 files changed

+71
-39
lines changed

10 files changed

+71
-39
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ describe('EntryFieldsComponent', () => {
262262
expect(component.lastEntry).toBe(state.entries.timeEntriesDataSource.data[1]);
263263
}));
264264

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

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

373373
const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class EntryFieldsComponent implements OnInit {
147147
return;
148148
}
149149
this.entryForm.patchValue({ start_date: newHourEntered });
150-
this.store.dispatch(new entryActions.UpdateTwoEntries({ ...this.newData, ...this.entryForm.value }));
150+
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
151151
this.showTimeInbuttons = false;
152152
}
153153

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
5454
).subscribe((action) => {
5555
this.activeEntry = action.payload;
5656
this.setSelectedProject();
57-
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
58-
this.store.dispatch(new entryActions.LoadActiveEntry());
5957
});
6058

6159
}

src/app/modules/time-clock/store/entry.actions.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ describe('Actions for Entries', () => {
127127
expect(action.type).toEqual(actions.EntryActionTypes.RESTART_ENTRY_FAIL);
128128
});
129129

130-
it('UpdateTwoEntries type is EntryActionTypes.UPDATE_TWO_ENTRIES', () => {
131-
const action = new actions.UpdateTwoEntries(entry);
132-
expect(action.type).toEqual(actions.EntryActionTypes.UPDATE_TWO_ENTRIES);
130+
it('UpdateCurrentOrLastEntry type is EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY', () => {
131+
const action = new actions.UpdateCurrentOrLastEntry(entry);
132+
expect(action.type).toEqual(actions.EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY);
133133
});
134134

135-
it('UpdateTwoEntriesFail type is EntryActionTypes.UPDATE_TWO_ENTRIES_FAIL', () => {
136-
const action = new actions.UpdateTwoEntriesFail('error');
137-
expect(action.type).toEqual(actions.EntryActionTypes.UPDATE_TWO_ENTRIES_FAIL);
135+
it('UpdateCurrentOrLastEntryFail type is EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY_FAIL', () => {
136+
const action = new actions.UpdateCurrentOrLastEntryFail('error');
137+
expect(action.type).toEqual(actions.EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY_FAIL);
138138
});
139139
});

src/app/modules/time-clock/store/entry.actions.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export enum EntryActionTypes {
2121
UPDATE_ENTRY_RUNNING = '[Entry] UPDATE_ENTRY_RUNNING',
2222
UPDATE_ENTRY = '[Entry] UPDATE_ENTRY',
2323
UPDATE_ENTRY_SUCCESS = '[Entry] UPDATE_ENTRY_SUCCESS',
24-
UPDATE_TWO_ENTRIES = '[Entry] UPDATE_TWO_ENTRIES',
25-
UPDATE_TWO_ENTRIES_FAIL = '[Entry] UPDATE_TWO_ENTRIES_FAIL',
24+
UPDATE_CURRENT_OR_LAST_ENTRY = '[Entry] UPDATE_CURRENT_OR_LAST_ENTRY',
25+
UPDATE_CURRENT_OR_LAST_ENTRY_FAIL = '[Entry] UPDATE_CURRENT_OR_LAST_ENTRY_FAIL',
2626
UPDATE_ENTRY_FAIL = '[Entry] UPDATE_ENTRY_FAIL',
2727
DELETE_ENTRY = '[Entry] DELETE_ENTRY',
2828
DELETE_ENTRY_SUCCESS = '[Entry] DELETE_ENTRY_SUCCESS',
@@ -185,14 +185,14 @@ export class UpdateEntryFail implements Action {
185185
}
186186
}
187187

188-
export class UpdateTwoEntries implements Action {
189-
public readonly type = EntryActionTypes.UPDATE_TWO_ENTRIES;
188+
export class UpdateCurrentOrLastEntry implements Action {
189+
public readonly type = EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY;
190190

191191
constructor(public payload) {
192192
}
193193
}
194-
export class UpdateTwoEntriesFail implements Action {
195-
public readonly type = EntryActionTypes.UPDATE_TWO_ENTRIES_FAIL;
194+
export class UpdateCurrentOrLastEntryFail implements Action {
195+
public readonly type = EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY_FAIL;
196196

197197
constructor(public error: string) {
198198
}
@@ -311,5 +311,5 @@ export type EntryActions =
311311
| RestartEntry
312312
| RestartEntrySuccess
313313
| RestartEntryFail
314-
| UpdateTwoEntries
315-
| UpdateTwoEntriesFail;
314+
| UpdateCurrentOrLastEntry
315+
| UpdateCurrentOrLastEntryFail;

src/app/modules/time-clock/store/entry.effects.spec.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ describe('TimeEntryActionEffects', () => {
2222
let toastrService;
2323
const entry: Entry = { project_id: 'p-id', start_date: new Date(), id: 'id' };
2424

25+
const dateTest = moment().format('YYYY-MM-DD');
26+
const endHourTest = moment().subtract(5, 'hours').format('HH:mm:ss');
27+
const startHourTest = moment().subtract(3, 'hours').format('HH:mm:ss');
28+
const endDateTest = new Date(`${dateTest}T${endHourTest.trim()}`);
29+
const startDateTest = new Date(`${dateTest}T${startHourTest.trim()}`);
30+
31+
const entryUpdate = {
32+
id: 'id',
33+
project_id: 'p-id',
34+
start_date : startDateTest,
35+
start_hour : moment().subtract(1, 'hours').format('HH:mm'),
36+
};
37+
2538
beforeEach(() => {
2639
TestBed.configureTestingModule({
2740
providers: [
@@ -340,21 +353,33 @@ describe('TimeEntryActionEffects', () => {
340353
});
341354
});
342355

343-
it('action type is UPDATE_ENTRY when UPDATE_TWO_ENTRIES executed', async () => {
344-
actions$ = of({ type: EntryActionTypes.UPDATE_TWO_ENTRIES, payload: entry });
356+
it('should update last entry when UPDATE_CURRENT_OR_LAST_ENTRY is executed', async () => {
357+
actions$ = of({ type: EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY, payload: entry });
345358
spyOn(service, 'loadEntries').and.returnValue(of([entry, entry]));
346359

347-
effects.updateLastEntryAndNew$.subscribe(action => {
360+
effects.updateCurrentOrLastEntry$.subscribe(action => {
348361
expect(action.type).toEqual(EntryActionTypes.UPDATE_ENTRY);
349362
});
350363
});
351364

352-
it('action type is UPDATE_TWO_ENTRIES_FAIL when service fail in execution', async () => {
353-
actions$ = of({ type: EntryActionTypes.UPDATE_TWO_ENTRIES, payload: entry });
365+
it('should update current entry when UPDATE_CURRENT_OR_LAST_ENTRY is executed', async () => {
366+
const lastEntry: Entry = { project_id: 'p-id', start_date: new Date(), id: 'id', end_date: endDateTest};
367+
actions$ = of({ type: EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY, payload: entryUpdate });
368+
spyOn(service, 'loadEntries').and.returnValue(of([lastEntry, lastEntry]));
369+
spyOn(toastrService, 'success');
370+
371+
effects.updateCurrentOrLastEntry$.subscribe(action => {
372+
expect(toastrService.success).toHaveBeenCalledWith('You change the time-in successfully');
373+
expect(action.type).toEqual(EntryActionTypes.UPDATE_ENTRY_RUNNING);
374+
});
375+
});
376+
377+
it('action type is UPDATE_CURRENT_OR_LAST_ENTRY_FAIL when service fail in execution', async () => {
378+
actions$ = of({ type: EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY, payload: entry });
354379
spyOn(service, 'loadEntries').and.returnValue(throwError({ error: { message: 'fail!' } }));
355380

356-
effects.updateLastEntryAndNew$.subscribe((action) => {
357-
expect(action.type).toEqual(EntryActionTypes.UPDATE_TWO_ENTRIES_FAIL);
381+
effects.updateCurrentOrLastEntry$.subscribe((action) => {
382+
expect(action.type).toEqual(EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY_FAIL);
358383
});
359384
});
360385
});

src/app/modules/time-clock/store/entry.effects.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,24 +221,24 @@ export class EntryEffects {
221221
);
222222

223223
@Effect()
224-
updateLastEntryAndNew$: Observable<Action> = this.actions$.pipe(
225-
ofType(actions.EntryActionTypes.UPDATE_TWO_ENTRIES),
226-
map((action: actions.UpdateTwoEntries) => action.payload),
224+
updateCurrentOrLastEntry$: Observable<Action> = this.actions$.pipe(
225+
ofType(actions.EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY),
226+
map((action: actions.UpdateCurrentOrLastEntry) => action.payload),
227227
switchMap((entry) =>
228228
this.entryService.loadEntries(new Date().getMonth() + 1).pipe(
229229
map((entries) => {
230230
const lastEntry = entries[1];
231-
const isInLastEntry = moment(entry.start_date).isBefore(lastEntry.end_date);
232-
if (isInLastEntry) {
231+
const isStartTimeInLastEntry = moment(entry.start_date).isBefore(lastEntry.end_date);
232+
if (isStartTimeInLastEntry) {
233233
return new actions.UpdateEntry({ id: lastEntry.id, end_date: entry.start_date });
234234
} else {
235-
this.toastrService.success('You change the time in successfully');
235+
this.toastrService.success('You change the time-in successfully');
236236
return new actions.UpdateEntryRunning(entry);
237237
}
238238
}),
239239
catchError((error) => {
240240
this.toastrService.error(error.error.message);
241-
return of(new actions.UpdateTwoEntriesFail('error'));
241+
return of(new actions.UpdateCurrentOrLastEntryFail('error'));
242242
})
243243
)
244244
)

src/app/modules/time-clock/store/entry.reducer.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,21 @@ describe('entryReducer', () => {
199199
expect(state.isLoading).toEqual(true);
200200
});
201201

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

206206
expect(state.isLoading).toEqual(true);
207207
});
208208

209+
it('on UpdateCurrentOrLastEntryFail, isLoading is false and give a message', () => {
210+
const action = new actions.UpdateCurrentOrLastEntryFail('fail');
211+
const state = entryReducer(initialState, action);
212+
213+
expect(state.isLoading).toEqual(false);
214+
expect(state.message).toEqual('Update Current or Last Entry Fail');
215+
});
216+
209217
it('on UpdateActiveEntrySuccess, loading is false', () => {
210218
const action = new actions.UpdateEntrySuccess(entry);
211219

src/app/modules/time-clock/store/entry.reducer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,18 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
206206
};
207207
}
208208

209-
case EntryActionTypes.UPDATE_TWO_ENTRIES: {
209+
case EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY: {
210210
return {
211211
...state,
212212
isLoading: true,
213213
};
214214
}
215215

216-
case EntryActionTypes.UPDATE_TWO_ENTRIES_FAIL: {
216+
case EntryActionTypes.UPDATE_CURRENT_OR_LAST_ENTRY_FAIL: {
217217
return {
218218
...state,
219219
isLoading: false,
220-
message: 'Update Two Entries Fail',
220+
message: 'Update Current or Last Entry Fail',
221221
};
222222
}
223223

src/app/modules/time-entries/pages/time-entries.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
107107
const isEditingEntryEqualToActiveEntry = this.entryId === this.activeTimeEntry.id;
108108
const isStartDateGreaterThanActiveEntry = startDateAsLocalDate > activeEntryAsLocalDate;
109109
const isEndDateGreaterThanActiveEntry = endDateAsLocalDate > activeEntryAsLocalDate;
110-
if (!isEditingEntryEqualToActiveEntry && (isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry)) {
110+
const isTimeEntryOverlapping = isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry;
111+
if (!isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping) {
111112
this.toastrService.error('You are on the clock and this entry overlaps it, try with earlier times.');
112113
} else {
113114
this.doSave(event);

0 commit comments

Comments
 (0)