From c9edc2400be9e91bf3d3e8710bebd415b2541e8e Mon Sep 17 00:00:00 2001 From: Juan Gabriel Guzman Date: Tue, 23 Jun 2020 07:39:51 -0500 Subject: [PATCH] test: #385 Adding unit tests for restarting entry related actions --- .../time-clock/store/entry.actions.spec.ts | 42 ++++++++++++------- .../modules/time-clock/store/entry.effects.ts | 2 +- .../pages/time-entries.component.html | 4 +- .../pages/time-entries.component.ts | 1 - 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/app/modules/time-clock/store/entry.actions.spec.ts b/src/app/modules/time-clock/store/entry.actions.spec.ts index 8debb2bb2..54f198bc2 100644 --- a/src/app/modules/time-clock/store/entry.actions.spec.ts +++ b/src/app/modules/time-clock/store/entry.actions.spec.ts @@ -1,8 +1,19 @@ import * as actions from './entry.actions'; import * as moment from 'moment'; import { TimeEntriesTimeRange } from '../models/time-entries-time-range'; +import { Entry } from '../../shared/models'; describe('Actions for Entries', () => { + let entry: Entry; + beforeEach(() => { + entry = { + id: '1', + start_date: new Date(), + end_date: new Date(), + activity_id: '', + technologies: ['abc', 'abc'], + }; + }); it('SwitchTimeEntry type is EntryActionTypes.SWITCH_TIME_ENTRY', () => { @@ -66,13 +77,7 @@ describe('Actions for Entries', () => { }); it('UpdateEntrySuccess type is EntryActionTypes.UDPATE_ENTRY_SUCCESS', () => { - const updateActiveEntrySuccess = new actions.UpdateEntrySuccess({ - id: '1', - start_date: new Date(), - end_date: new Date(), - activity_id: '', - technologies: ['abc', 'abc'], - }); + const updateActiveEntrySuccess = new actions.UpdateEntrySuccess(entry); expect(updateActiveEntrySuccess.type).toEqual(actions.EntryActionTypes.UPDATE_ENTRY_SUCCESS); }); @@ -82,13 +87,7 @@ describe('Actions for Entries', () => { }); it('UpdateActiveEntry type is EntryActionTypes.UDPATE_ENTRY_FAIL', () => { - const action = new actions.UpdateEntryRunning({ - id: '1', - start_date: new Date(), - end_date: new Date(), - activity_id: '', - technologies: ['abc', 'abc'], - }); + const action = new actions.UpdateEntryRunning(entry); expect(action.type).toEqual(actions.EntryActionTypes.UPDATE_ENTRY_RUNNING); }); @@ -111,4 +110,19 @@ describe('Actions for Entries', () => { const action = new actions.LoadEntriesByTimeRangeFail(); expect(action.type).toEqual(actions.EntryActionTypes.LOAD_ENTRIES_BY_TIME_RANGE_FAIL); }); + + it('RestartEntry type is EntryActionTypes.RESTART_ENTRY', () => { + const action = new actions.RestartEntry(entry); + expect(action.type).toEqual(actions.EntryActionTypes.RESTART_ENTRY); + }); + + it('RestartEntrySuccess type is EntryActionTypes.RESTART_ENTRY_SUCCESS', () => { + const action = new actions.RestartEntrySuccess(entry); + expect(action.type).toEqual(actions.EntryActionTypes.RESTART_ENTRY_SUCCESS); + }); + + it('RestartEntryFail type is EntryActionTypes.RESTART_ENTRY_FAIL', () => { + const action = new actions.RestartEntryFail('error'); + expect(action.type).toEqual(actions.EntryActionTypes.RESTART_ENTRY_FAIL); + }); }); diff --git a/src/app/modules/time-clock/store/entry.effects.ts b/src/app/modules/time-clock/store/entry.effects.ts index 315e450d4..beddc1f8f 100644 --- a/src/app/modules/time-clock/store/entry.effects.ts +++ b/src/app/modules/time-clock/store/entry.effects.ts @@ -209,7 +209,7 @@ export class EntryEffects { }), catchError((error) => { this.toastrService.error( error.error.message, 'This entry could not be restarted'); - return of(new actions.UpdateEntryFail(error)); + return of(new actions.RestartEntryFail(error)); }) ) ) diff --git a/src/app/modules/time-entries/pages/time-entries.component.html b/src/app/modules/time-entries/pages/time-entries.component.html index 93ad8c673..2750771f1 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.html +++ b/src/app/modules/time-entries/pages/time-entries.component.html @@ -66,13 +66,11 @@