Skip to content

Commit e25af33

Browse files
author
Abigail Cabascango
committed
test: TTA-206 implement test for validate time entry running in clockin function
1 parent 9783d05 commit e25af33

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,38 @@ describe('ProjectListHoverComponent', () => {
8383
expect(store.dispatch).toHaveBeenCalledWith(jasmine.any(ClockIn));
8484
});
8585

86+
it('when the user make a clockin and there is an existing time entry running the user have an alert', () => {
87+
component.activeEntry = null;
88+
const activitiesMock = [{
89+
id: 'xyz',
90+
name: 'test',
91+
description : 'test1'
92+
}];
93+
component.activities = activitiesMock;
94+
spyOn(store, 'dispatch');
95+
96+
component.clockIn(1, 'customer', 'project');
97+
98+
expect(store.dispatch).toHaveBeenCalledWith(jasmine.any(ClockIn));
99+
expect(component.canMarkEntryAsWIP).toBe(true);
100+
});
101+
102+
it('when the user make a clockin and there is not an existing time entry running the user can make a clokin', () => {
103+
component.activeEntry = null;
104+
const activitiesMock = [{
105+
id: 'xyz',
106+
name: 'test',
107+
description : 'test1'
108+
}];
109+
component.activities = activitiesMock;
110+
spyOn(store, 'dispatch');
111+
112+
component.clockIn(1, 'customer', 'project');
113+
114+
expect(store.dispatch).toHaveBeenCalledWith(jasmine.any(ClockIn));
115+
expect(component.canMarkEntryAsWIP).toBe(false);
116+
});
117+
86118
it('dispatch a UpdateEntryRunning action on updateProject', () => {
87119
component.activeEntry = { id: '123' };
88120
spyOn(store, 'dispatch');

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
119119
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
120120
this.canMarkEntryAsWIP = !this.isThereAnEntryRunning(ds.data);
121121
});
122-
if ( this.canMarkEntryAsWIP){
123-
this.store.dispatch(new entryActions.ClockIn(entry));
124-
this.projectsForm.setValue({ project_id: `${customerName} - ${name}` });
125-
setTimeout(() => {
126-
this.store.dispatch(new actions.LoadRecentProjects());
127-
}, 2000);
122+
if (this.canMarkEntryAsWIP !== false ){
123+
this.toastrService.error('There is an existing time entry running please check your time entries')
124+
return;
128125
}
126+
this.store.dispatch(new entryActions.ClockIn(entry));
127+
this.projectsForm.setValue({ project_id: `${customerName} - ${name}` });
128+
setTimeout(() => {
129+
this.store.dispatch(new actions.LoadRecentProjects());
130+
}, 2000);
129131
}
130132

131133
getEntryRunning(entries: Entry[]) {

0 commit comments

Comments
 (0)