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
test: #385 Adding unit tests for restarting entry related actions
  • Loading branch information
Juan Gabriel Guzman committed Jun 23, 2020
commit c9edc2400be9e91bf3d3e8710bebd415b2541e8e
42 changes: 28 additions & 14 deletions src/app/modules/time-clock/store/entry.actions.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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);
});

Expand All @@ -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);
});

Expand All @@ -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);
});
});
2 changes: 1 addition & 1 deletion src/app/modules/time-clock/store/entry.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
})
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ <h5 class="modal-title" id="exampleModalLongTitle">{{ entryId ? 'Edit Entry' : '
<app-details-fields
[entryToEdit]="entry"
(saveEntry)="saveEntry($event)"
> Active TE: {{activeTimeEntry | json}}
>
</app-details-fields>
</div>
</div>
</div>

Active TE: {{activeTimeEntry | json}}
</div>

<app-dialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class TimeEntriesComponent implements OnInit {
}

doSave(event: SaveEntryEvent) {
console.log(event);
event.entry.start_date = new Date(event.entry.start_date).toISOString();
if (event.entry.end_date !== null && event.entry.end_date !== undefined) {
event.entry.end_date = new Date(event.entry.end_date).toISOString();
Expand Down