Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: TTA-206 implement test for validate time entry running in clock…
…in function
  • Loading branch information
Abigail Cabascango committed Nov 2, 2022
commit e25af33f06d04a1afc6dd9afbc291b15cf767138
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,38 @@ describe('ProjectListHoverComponent', () => {
expect(store.dispatch).toHaveBeenCalledWith(jasmine.any(ClockIn));
});

it('when the user make a clockin and there is an existing time entry running the user have an alert', () => {
component.activeEntry = null;
const activitiesMock = [{
id: 'xyz',
name: 'test',
description : 'test1'
}];
component.activities = activitiesMock;
spyOn(store, 'dispatch');

component.clockIn(1, 'customer', 'project');

expect(store.dispatch).toHaveBeenCalledWith(jasmine.any(ClockIn));
expect(component.canMarkEntryAsWIP).toBe(true);
});

it('when the user make a clockin and there is not an existing time entry running the user can make a clokin', () => {
component.activeEntry = null;
const activitiesMock = [{
id: 'xyz',
name: 'test',
description : 'test1'
}];
component.activities = activitiesMock;
spyOn(store, 'dispatch');

component.clockIn(1, 'customer', 'project');

expect(store.dispatch).toHaveBeenCalledWith(jasmine.any(ClockIn));
expect(component.canMarkEntryAsWIP).toBe(false);
});

it('dispatch a UpdateEntryRunning action on updateProject', () => {
component.activeEntry = { id: '123' };
spyOn(store, 'dispatch');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
this.canMarkEntryAsWIP = !this.isThereAnEntryRunning(ds.data);
});
if ( this.canMarkEntryAsWIP){
this.store.dispatch(new entryActions.ClockIn(entry));
this.projectsForm.setValue({ project_id: `${customerName} - ${name}` });
setTimeout(() => {
this.store.dispatch(new actions.LoadRecentProjects());
}, 2000);
if (this.canMarkEntryAsWIP !== false ){
this.toastrService.error('There is an existing time entry running please check your time entries')
return;
}
this.store.dispatch(new entryActions.ClockIn(entry));
this.projectsForm.setValue({ project_id: `${customerName} - ${name}` });
setTimeout(() => {
this.store.dispatch(new actions.LoadRecentProjects());
}, 2000);
}

getEntryRunning(entries: Entry[]) {
Expand Down