Skip to content

Commit 34450e9

Browse files
authored
fix: 🐛 refresh active entry on edit actions #481 (#482)
1 parent ce748d7 commit 34450e9

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
4646
)
4747
)
4848
).subscribe((action) => {
49+
this.loadActiveEntry();
4950
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
5051
});
5152
}
@@ -124,9 +125,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
124125
loadActiveEntry() {
125126
this.store.dispatch(new entryActions.LoadActiveEntry());
126127
this.store.pipe(select(getActiveTimeEntry)).subscribe((activeTimeEntry) => {
127-
if (activeTimeEntry) {
128-
this.activeTimeEntry = activeTimeEntry;
129-
}
128+
this.activeTimeEntry = activeTimeEntry;
130129
});
131130
}
132131

0 commit comments

Comments
 (0)