Skip to content

Commit c934b91

Browse files
committed
test: add unit tests #481
1 parent c5ec31c commit c934b91

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import { TechnologyState } from '../../shared/store/technology.reducers';
1111
import { TimeEntriesSummaryComponent } from '../../time-clock/components/time-entries-summary/time-entries-summary.component';
1212
import * as entryActions from '../../time-clock/store/entry.actions';
1313
import { EntryState } from '../../time-clock/store/entry.reducer';
14-
import { getTimeEntriesDataSource } from '../../time-clock/store/entry.selectors';
14+
import { getTimeEntriesDataSource, getActiveTimeEntry } from '../../time-clock/store/entry.selectors';
1515
import { LoadActiveEntry } from './../../time-clock/store/entry.actions';
1616
import { TimeEntriesComponent } from './time-entries.component';
17-
17+
import { ActionsSubject } from '@ngrx/store';
18+
import { EntryActionTypes } from './../../time-clock/store/entry.actions';
1819

1920
describe('TimeEntriesComponent', () => {
2021
type Merged = TechnologyState & ProjectState & EntryState;
@@ -179,6 +180,27 @@ describe('TimeEntriesComponent', () => {
179180
expect(component.entryId).toBe(anEntryId);
180181
});
181182

183+
it('when trigger edit action and there is no active entry, active entry should be null', () => {
184+
state.active = null;
185+
mockEntriesSelector = store.overrideSelector(getActiveTimeEntry, state.active);
186+
187+
const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;
188+
const action = {
189+
type: EntryActionTypes.UPDATE_ENTRY_SUCCESS,
190+
payload: {
191+
project_id: 'project-id',
192+
start_date: '2010-05-05T10:04',
193+
description: 'description',
194+
technologies: [],
195+
uri: 'abc',
196+
},
197+
};
198+
199+
actionSubject.next(action);
200+
201+
expect(component.activeTimeEntry).toBeNull();
202+
});
203+
182204
it('given a list of entries having an entry running when editing a different entry it cannot be marked as WIP ', () => {
183205
const anEntryId = '1';
184206
const anotherEntryId = '2';

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
125125
loadActiveEntry() {
126126
this.store.dispatch(new entryActions.LoadActiveEntry());
127127
this.store.pipe(select(getActiveTimeEntry)).subscribe((activeTimeEntry) => {
128-
if (activeTimeEntry) {
129-
this.activeTimeEntry = activeTimeEntry;
130-
} else {
131-
this.activeTimeEntry = null;
132-
}
128+
this.activeTimeEntry = activeTimeEntry;
133129
});
134130
}
135131

0 commit comments

Comments
 (0)