Skip to content

Commit 66e9a70

Browse files
committed
fix: #441 make activity required before switching
1 parent 3b51775 commit 66e9a70

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ToastrService, IndividualConfig } from 'ngx-toastr';
12
import { SwitchTimeEntry } from './../../store/entry.actions';
23
import { FormBuilder } from '@angular/forms';
34
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
@@ -17,6 +18,9 @@ describe('ProjectListHoverComponent', () => {
1718
let fixture: ComponentFixture<ProjectListHoverComponent>;
1819
let store: MockStore<ProjectState>;
1920
let mockProjectsSelector;
21+
const toastrServiceStub = {
22+
error: (message?: string, title?: string, override?: Partial<IndividualConfig>) => { }
23+
};
2024

2125
const state = {
2226
projects: {
@@ -41,7 +45,8 @@ describe('ProjectListHoverComponent', () => {
4145
beforeEach(async(() => {
4246
TestBed.configureTestingModule({
4347
declarations: [ProjectListHoverComponent, FilterProjectPipe],
44-
providers: [FormBuilder, provideMockStore({ initialState: state })],
48+
providers: [FormBuilder, provideMockStore({ initialState: state }),
49+
{ provide: ToastrService, useValue: toastrServiceStub }],
4550
imports: [HttpClientTestingModule, AutocompleteLibModule],
4651
}).compileComponents();
4752
store = TestBed.inject(MockStore);
@@ -76,6 +81,15 @@ describe('ProjectListHoverComponent', () => {
7681
expect(store.dispatch).toHaveBeenCalledWith(new UpdateEntryRunning({ id: component.activeEntry.id, project_id: 1 }));
7782
});
7883

84+
it('displays a message when the acitivity_id is null', () => {
85+
spyOn(toastrServiceStub, 'error');
86+
component.activeEntry = { activity_id: null };
87+
88+
component.switch(1, 'customer', 'project');
89+
90+
expect(toastrServiceStub.error).toHaveBeenCalled();
91+
});
92+
7993
it('dispatch a SwitchTimeEntry action', () => {
8094
spyOn(store, 'dispatch');
8195
component.activeEntry = { id: '123' };

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ToastrService } from 'ngx-toastr';
12
import { EntryActionTypes } from './../../store/entry.actions';
23
import { filter } from 'rxjs/operators';
34
import { FormGroup, FormBuilder } from '@angular/forms';
@@ -26,7 +27,8 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
2627
showClockIn: boolean;
2728
updateEntrySubscription: Subscription;
2829

29-
constructor(private formBuilder: FormBuilder, private store: Store<ProjectState>, private actionsSubject$: ActionsSubject) {
30+
constructor(private formBuilder: FormBuilder, private store: Store<ProjectState>,
31+
private actionsSubject$: ActionsSubject, private toastrService: ToastrService) {
3032
this.projectsForm = this.formBuilder.group({ project_id: null, });
3133
}
3234

@@ -88,8 +90,12 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
8890
}
8991

9092
switch(selectedProject, customerName, name) {
91-
this.store.dispatch(new entryActions.SwitchTimeEntry(this.activeEntry.id, selectedProject));
92-
this.projectsForm.setValue( { project_id: `${customerName} - ${name}`, } );
93+
if (this.activeEntry.activity_id === null) {
94+
this.toastrService.error('Before switching, please select an activity');
95+
} else {
96+
this.store.dispatch(new entryActions.SwitchTimeEntry(this.activeEntry.id, selectedProject));
97+
this.projectsForm.setValue( { project_id: `${customerName} - ${name}`, } );
98+
}
9399
}
94100

95101
ngOnDestroy(): void {

0 commit comments

Comments
 (0)