Skip to content

Commit 472b09d

Browse files
author
Abigail Cabascango
committed
fix: TTA-206 validate clockin
1 parent e25af33 commit 472b09d

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -206,25 +206,4 @@ describe('ProjectListHoverComponent', () => {
206206
expect(component.clockIn).toHaveBeenCalledWith(id, customer, name);
207207
});
208208

209-
// TODO Fix this test since it is throwing this error
210-
// Expected spy dispatch to have been called with:
211-
// [CreateEntry({ payload: Object({ project_id: '1', start_date: '2020-07-27T22:30:26.743Z', timezone_offset: 300 }),
212-
// type: '[Entry] CREATE_ENTRY' })]
213-
// but actual calls were:
214-
// [CreateEntry({ payload: Object({ project_id: '1', start_date: '2020-07-27T22:30:26.742Z', timezone_offset: 300 }),
215-
// type: '[Entry] CREATE_ENTRY' })].
216-
217-
// Call 0:
218-
// Expected $[0].payload.start_date = '2020-07-27T22:30:26.742Z' to equal '2020-07-27T22:30:26.743Z'.
219-
// it('creates time-entry with timezone_offset property', () => {
220-
// spyOn(store, 'dispatch');
221-
// component.clockIn('1', 'customer', 'project');
222-
// expect(store.dispatch).toHaveBeenCalledWith(
223-
// new CreateEntry({
224-
// project_id: '1',
225-
// start_date: new Date().toISOString(),
226-
// timezone_offset: new Date().getTimezoneOffset()
227-
// })
228-
// );
229-
// });
230209
});

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { LoadActivities } from './../../../activities-management/store/activity-
2121
import { allActivities } from 'src/app/modules/activities-management/store/activity-management.selectors';
2222
import { head } from 'lodash';
2323
import { Entry } from '../../../shared/models';
24+
import { EntryState } from '../../store/entry.reducer';
2425

2526
@Component({
2627
selector: 'app-project-list-hover',
@@ -41,10 +42,11 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
4142
recentProjectsSubscription: Subscription;
4243
activeEntrySubscription: Subscription;
4344
loadActivitiesSubscription: Subscription;
44-
canMarkEntryAsWIP = true;
45+
canMarkEntryAsWIP : boolean;
4546

4647
constructor(
4748
private formBuilder: FormBuilder,
49+
private storeEntry: Store<EntryState>,
4850
private store: Store<ProjectState>,
4951
private actionsSubject$: ActionsSubject,
5052
private toastrService: ToastrService
@@ -116,11 +118,13 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
116118
technologies: [],
117119
activity_id: head(this.activities).id,
118120
};
119-
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
120-
this.canMarkEntryAsWIP = !this.isThereAnEntryRunning(ds.data);
121+
this.canMarkEntryAsWIP = true;
122+
this.storeEntry.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
123+
this.canMarkEntryAsWIP = this.isThereAnEntryRunning(ds.data);
121124
});
122-
if (this.canMarkEntryAsWIP !== false ){
123-
this.toastrService.error('There is an existing time entry running please check your time entries')
125+
126+
if (this.canMarkEntryAsWIP === true ){
127+
this.toastrService.error('There is an existing time entry running please check your time entries');
124128
return;
125129
}
126130
this.store.dispatch(new entryActions.ClockIn(entry));
@@ -134,7 +138,9 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
134138
const runningEntry: Entry = entries.find(entry => entry.running === true);
135139
return runningEntry;
136140
}
141+
137142
isThereAnEntryRunning(entries: Entry[]) {
143+
console.log(!!this.getEntryRunning(entries))
138144
return !!this.getEntryRunning(entries);
139145
}
140146

0 commit comments

Comments
 (0)