Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,39 @@ 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');
component.clockIn(2, '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 Expand Up @@ -174,25 +207,4 @@ describe('ProjectListHoverComponent', () => {
expect(component.clockIn).toHaveBeenCalledWith(id, customer, name);
});

// TODO Fix this test since it is throwing this error
// Expected spy dispatch to have been called with:
// [CreateEntry({ payload: Object({ project_id: '1', start_date: '2020-07-27T22:30:26.743Z', timezone_offset: 300 }),
// type: '[Entry] CREATE_ENTRY' })]
// but actual calls were:
// [CreateEntry({ payload: Object({ project_id: '1', start_date: '2020-07-27T22:30:26.742Z', timezone_offset: 300 }),
// type: '[Entry] CREATE_ENTRY' })].

// Call 0:
// Expected $[0].payload.start_date = '2020-07-27T22:30:26.742Z' to equal '2020-07-27T22:30:26.743Z'.
// it('creates time-entry with timezone_offset property', () => {
// spyOn(store, 'dispatch');
// component.clockIn('1', 'customer', 'project');
// expect(store.dispatch).toHaveBeenCalledWith(
// new CreateEntry({
// project_id: '1',
// start_date: new Date().toISOString(),
// timezone_offset: new Date().getTimezoneOffset()
// })
// );
// });
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import { Project } from 'src/app/modules/shared/models';
import * as actions from '../../../customer-management/components/projects/components/store/project.actions';
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
import * as entryActions from '../../store/entry.actions';

import {
getIsLoading,
getProjects,
getRecentProjects,
} from './../../../customer-management/components/projects/components/store/project.selectors';
import { EntryActionTypes } from './../../store/entry.actions';
import { getActiveTimeEntry } from './../../store/entry.selectors';
import { getActiveTimeEntry, getTimeEntriesDataSource } from './../../store/entry.selectors';
import { Activity, } from '../../../shared/models';
import { LoadActivities } from './../../../activities-management/store/activity-management.actions';
import { allActivities } from 'src/app/modules/activities-management/store/activity-management.selectors';
import { head } from 'lodash';
import { Entry } from '../../../shared/models';
import { EntryState } from '../../store/entry.reducer';

@Component({
selector: 'app-project-list-hover',
Expand All @@ -39,9 +42,11 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
recentProjectsSubscription: Subscription;
activeEntrySubscription: Subscription;
loadActivitiesSubscription: Subscription;
canMarkEntryAsWIP: boolean;

constructor(
private formBuilder: FormBuilder,
private storeEntry: Store<EntryState>,
private store: Store<ProjectState>,
private actionsSubject$: ActionsSubject,
private toastrService: ToastrService
Expand Down Expand Up @@ -113,13 +118,31 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
technologies: [],
activity_id: head(this.activities).id,
};
this.canMarkEntryAsWIP = true;
this.storeEntry.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
this.canMarkEntryAsWIP = this.isThereAnEntryRunning(ds.data);
});

if (this.canMarkEntryAsWIP === true ){
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[]) {
const runningEntry: Entry = entries.find(entry => entry.running === true);
return runningEntry;
}

isThereAnEntryRunning(entries: Entry[]) {
return !!this.getEntryRunning(entries);
}

updateProject(selectedProject) {
const entry = { id: this.activeEntry.id, project_id: selectedProject };
this.store.dispatch(new entryActions.UpdateEntryRunning(entry));
Expand Down