Skip to content

Commit c9edc24

Browse files
author
Juan Gabriel Guzman
committed
test: #385 Adding unit tests for restarting entry related actions
1 parent d6ce982 commit c9edc24

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

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

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import * as actions from './entry.actions';
22
import * as moment from 'moment';
33
import { TimeEntriesTimeRange } from '../models/time-entries-time-range';
4+
import { Entry } from '../../shared/models';
45

56
describe('Actions for Entries', () => {
7+
let entry: Entry;
8+
beforeEach(() => {
9+
entry = {
10+
id: '1',
11+
start_date: new Date(),
12+
end_date: new Date(),
13+
activity_id: '',
14+
technologies: ['abc', 'abc'],
15+
};
16+
});
617

718

819
it('SwitchTimeEntry type is EntryActionTypes.SWITCH_TIME_ENTRY', () => {
@@ -66,13 +77,7 @@ describe('Actions for Entries', () => {
6677
});
6778

6879
it('UpdateEntrySuccess type is EntryActionTypes.UDPATE_ENTRY_SUCCESS', () => {
69-
const updateActiveEntrySuccess = new actions.UpdateEntrySuccess({
70-
id: '1',
71-
start_date: new Date(),
72-
end_date: new Date(),
73-
activity_id: '',
74-
technologies: ['abc', 'abc'],
75-
});
80+
const updateActiveEntrySuccess = new actions.UpdateEntrySuccess(entry);
7681
expect(updateActiveEntrySuccess.type).toEqual(actions.EntryActionTypes.UPDATE_ENTRY_SUCCESS);
7782
});
7883

@@ -82,13 +87,7 @@ describe('Actions for Entries', () => {
8287
});
8388

8489
it('UpdateActiveEntry type is EntryActionTypes.UDPATE_ENTRY_FAIL', () => {
85-
const action = new actions.UpdateEntryRunning({
86-
id: '1',
87-
start_date: new Date(),
88-
end_date: new Date(),
89-
activity_id: '',
90-
technologies: ['abc', 'abc'],
91-
});
90+
const action = new actions.UpdateEntryRunning(entry);
9291
expect(action.type).toEqual(actions.EntryActionTypes.UPDATE_ENTRY_RUNNING);
9392
});
9493

@@ -111,4 +110,19 @@ describe('Actions for Entries', () => {
111110
const action = new actions.LoadEntriesByTimeRangeFail();
112111
expect(action.type).toEqual(actions.EntryActionTypes.LOAD_ENTRIES_BY_TIME_RANGE_FAIL);
113112
});
113+
114+
it('RestartEntry type is EntryActionTypes.RESTART_ENTRY', () => {
115+
const action = new actions.RestartEntry(entry);
116+
expect(action.type).toEqual(actions.EntryActionTypes.RESTART_ENTRY);
117+
});
118+
119+
it('RestartEntrySuccess type is EntryActionTypes.RESTART_ENTRY_SUCCESS', () => {
120+
const action = new actions.RestartEntrySuccess(entry);
121+
expect(action.type).toEqual(actions.EntryActionTypes.RESTART_ENTRY_SUCCESS);
122+
});
123+
124+
it('RestartEntryFail type is EntryActionTypes.RESTART_ENTRY_FAIL', () => {
125+
const action = new actions.RestartEntryFail('error');
126+
expect(action.type).toEqual(actions.EntryActionTypes.RESTART_ENTRY_FAIL);
127+
});
114128
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class EntryEffects {
209209
}),
210210
catchError((error) => {
211211
this.toastrService.error( error.error.message, 'This entry could not be restarted');
212-
return of(new actions.UpdateEntryFail(error));
212+
return of(new actions.RestartEntryFail(error));
213213
})
214214
)
215215
)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,11 @@ <h5 class="modal-title" id="exampleModalLongTitle">{{ entryId ? 'Edit Entry' : '
6666
<app-details-fields
6767
[entryToEdit]="entry"
6868
(saveEntry)="saveEntry($event)"
69-
> Active TE: {{activeTimeEntry | json}}
69+
>
7070
</app-details-fields>
7171
</div>
7272
</div>
7373
</div>
74-
75-
Active TE: {{activeTimeEntry | json}}
7674
</div>
7775

7876
<app-dialog

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export class TimeEntriesComponent implements OnInit {
6262
}
6363

6464
doSave(event: SaveEntryEvent) {
65-
console.log(event);
6665
event.entry.start_date = new Date(event.entry.start_date).toISOString();
6766
if (event.entry.end_date !== null && event.entry.end_date !== undefined) {
6867
event.entry.end_date = new Date(event.entry.end_date).toISOString();

0 commit comments

Comments
 (0)