Skip to content

Commit eaf18c2

Browse files
authored
Merge pull request #380 from ioet/378-remove-message-updating-current-entry
fix: #378 remove notification messages from time-clock screen
2 parents 5a71bcf + bd49185 commit eaf18c2

13 files changed

+103
-45
lines changed

src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('EntryFieldsComponent', () => {
9999
it('should dispatch UpdateActiveEntry action #onSubmit', () => {
100100
spyOn(store, 'dispatch');
101101
component.onSubmit();
102-
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.UpdateActiveEntry(entry));
102+
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.UpdateEntryRunning(entry));
103103
});
104104

105105
it('when a technology is added, then dispatch UpdateActiveEntry', () => {

src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ export class EntryFieldsComponent implements OnInit {
7474
}
7575

7676
onSubmit() {
77-
this.store.dispatch(new entryActions.UpdateActiveEntry({...this.newData, ...this.entryForm.value}));
77+
this.store.dispatch(new entryActions.UpdateEntryRunning({...this.newData, ...this.entryForm.value}));
7878
}
7979

8080
onTechnologyAdded($event: string[]) {
81-
this.store.dispatch(new entryActions.UpdateActiveEntry({...this.newData, technologies: $event})
81+
this.store.dispatch(new entryActions.UpdateEntryRunning({...this.newData, technologies: $event})
8282
);
8383
}
8484

8585
onTechnologyRemoved($event: string[]) {
86-
this.store.dispatch(new entryActions.UpdateActiveEntry({...this.newData, technologies: $event}));
86+
this.store.dispatch(new entryActions.UpdateEntryRunning({...this.newData, technologies: $event}));
8787
}
8888

8989
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {ProjectListHoverComponent} from './project-list-hover.component';
77
import {ProjectState} from '../../../customer-management/components/projects/components/store/project.reducer';
88
import {getCustomerProjects} from '../../../customer-management/components/projects/components/store/project.selectors';
99
import {FilterProjectPipe} from '../../../shared/pipes';
10-
import {CreateEntry, UpdateActiveEntry} from '../../store/entry.actions';
10+
import {CreateEntry, UpdateEntryRunning} from '../../store/entry.actions';
1111
import {AutocompleteLibModule} from 'angular-ng-autocomplete';
1212

1313
describe('ProjectListHoverComponent', () => {
@@ -65,13 +65,13 @@ describe('ProjectListHoverComponent', () => {
6565
expect(store.dispatch).toHaveBeenCalledWith(jasmine.any(CreateEntry));
6666
});
6767

68-
it('dispatchs a UpdateEntry action when activeEntry is not null', () => {
68+
it('dispatchs a UpdateEntryRunning action when activeEntry is not null', () => {
6969
const entry = {id: '123', project_id: 'p1', start_date: new Date().toISOString()};
7070
component.activeEntry = entry;
7171
spyOn(store, 'dispatch');
7272

7373
component.clockIn();
7474

75-
expect(store.dispatch).toHaveBeenCalledWith(jasmine.any(UpdateActiveEntry));
75+
expect(store.dispatch).toHaveBeenCalledWith(jasmine.any(UpdateEntryRunning));
7676
});
7777
});

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ export class ProjectListHoverComponent implements OnInit {
5656
const selectedProject = this.projectsForm.get('project_id').value;
5757
if (this.activeEntry) {
5858
const entry = { id: this.activeEntry.id, project_id: selectedProject };
59-
this.store.dispatch(new entryActions.UpdateActiveEntry(entry));
59+
this.store.dispatch(new entryActions.UpdateEntryRunning(entry));
6060
} else {
6161
const newEntry = { project_id: selectedProject, start_date: new Date().toISOString() };
6262
this.store.dispatch(new entryActions.CreateEntry(newEntry));
6363
}
6464
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1 ));
65-
this.loadActiveTimeEntry();
6665
}
6766

6867
}

src/app/modules/time-clock/services/entry.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('EntryService', () => {
6666
it('update an entry using PUT', () => {
6767
const updatedEntry = {foo: 'bar', id: 'id'};
6868

69-
service.updateActiveEntry(updatedEntry).subscribe();
69+
service.updateEntry(updatedEntry).subscribe();
7070

7171
const updateEntryRequest = httpMock.expectOne(`${service.baseUrl}/id`);
7272
expect(updateEntryRequest.request.method).toBe('PUT');

src/app/modules/time-clock/services/entry.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class EntryService {
3030
return this.http.post(this.baseUrl, entryData);
3131
}
3232

33-
updateActiveEntry(entryData): Observable<any> {
33+
updateEntry(entryData): Observable<any> {
3434
const {id} = entryData;
3535
return this.http.put(`${this.baseUrl}/${id}`, entryData);
3636
}

src/app/modules/time-clock/store/entry.actions.spec.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,31 @@ describe('Actions for Entries', () => {
5555
expect(deleteEntryFail.type).toEqual(actions.EntryActionTypes.DELETE_ENTRY_FAIL);
5656
});
5757

58-
it('UpdateActiveEntrySuccess type is EntryActionTypes.UDPATE_ACTIVE_ENTRY_SUCCESS', () => {
59-
const updateActiveEntrySuccess = new actions.UpdateActiveEntrySuccess({
58+
it('UpdateEntrySuccess type is EntryActionTypes.UDPATE_ENTRY_SUCCESS', () => {
59+
const updateActiveEntrySuccess = new actions.UpdateEntrySuccess({
6060
id: '1',
6161
start_date: new Date(),
6262
end_date: new Date(),
6363
activity_id: '',
6464
technologies: ['abc', 'abc'],
6565
});
66-
expect(updateActiveEntrySuccess.type).toEqual(actions.EntryActionTypes.UPDATE_ACTIVE_ENTRY_SUCCESS);
66+
expect(updateActiveEntrySuccess.type).toEqual(actions.EntryActionTypes.UPDATE_ENTRY_SUCCESS);
6767
});
6868

69-
it('UpdateActiveEntryFail type is EntryActionTypes.UDPATE_ACTIVE_ENTRY_FAIL', () => {
70-
const updateActiveEntryFail = new actions.UpdateActiveEntryFail('error');
71-
expect(updateActiveEntryFail.type).toEqual(actions.EntryActionTypes.UPDATE_ACTIVE_ENTRY_FAIL);
69+
it('UpdateEntryFail type is EntryActionTypes.UDPATE_ENTRY_FAIL', () => {
70+
const updateActiveEntryFail = new actions.UpdateEntryFail('error');
71+
expect(updateActiveEntryFail.type).toEqual(actions.EntryActionTypes.UPDATE_ENTRY_FAIL);
72+
});
73+
74+
it('UpdateActiveEntry type is EntryActionTypes.UDPATE_ENTRY_FAIL', () => {
75+
const action = new actions.UpdateEntryRunning({
76+
id: '1',
77+
start_date: new Date(),
78+
end_date: new Date(),
79+
activity_id: '',
80+
technologies: ['abc', 'abc'],
81+
});
82+
expect(action.type).toEqual(actions.EntryActionTypes.UPDATE_ENTRY_RUNNING);
7283
});
7384

7485
it('LoadEntriesByTimeRange type is EntryActionTypes.LOAD_ENTRIES_BY_TIME_RANGE', () => {

src/app/modules/time-clock/store/entry.actions.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ export enum EntryActionTypes {
1616
CREATE_ENTRY = '[Entry] CREATE_ENTRY',
1717
CREATE_ENTRY_SUCCESS = '[Entry] CREATE_ENTRY_SUCCESS',
1818
CREATE_ENTRY_FAIL = '[Entry] CREATE_ENTRY_FAIL',
19-
UPDATE_ACTIVE_ENTRY = '[Entry] UPDATE_ACTIVE_ENTRY',
20-
UPDATE_ACTIVE_ENTRY_SUCCESS = '[Entry] UPDATE_ACTIVE_ENTRY_SUCCESS',
21-
UPDATE_ACTIVE_ENTRY_FAIL = '[Entry] UPDATE_ACTIVE_ENTRY_FAIL',
19+
UPDATE_ENTRY_RUNNING = '[Entry] UPDATE_ENTRY_RUNNING',
20+
UPDATE_ENTRY = '[Entry] UPDATE_ENTRY',
21+
UPDATE_ENTRY_SUCCESS = '[Entry] UPDATE_ENTRY_SUCCESS',
22+
UPDATE_ENTRY_FAIL = '[Entry] UPDATE_ENTRY_FAIL',
2223
DELETE_ENTRY = '[Entry] DELETE_ENTRY',
2324
DELETE_ENTRY_SUCCESS = '[Entry] DELETE_ENTRY_SUCCESS',
2425
DELETE_ENTRY_FAIL = '[Entry] DELETE_ENTRY_FAIL',
@@ -112,20 +113,26 @@ export class DeleteEntryFail implements Action {
112113

113114
constructor(public error: string) {}
114115
}
115-
export class UpdateActiveEntry implements Action {
116-
public readonly type = EntryActionTypes.UPDATE_ACTIVE_ENTRY;
117116

117+
export class UpdateEntryRunning implements Action {
118+
public readonly type = EntryActionTypes.UPDATE_ENTRY_RUNNING;
118119
constructor(public payload) {}
119120
}
120121

121-
export class UpdateActiveEntrySuccess implements Action {
122-
public readonly type = EntryActionTypes.UPDATE_ACTIVE_ENTRY_SUCCESS;
122+
export class UpdateEntry implements Action {
123+
public readonly type = EntryActionTypes.UPDATE_ENTRY;
124+
125+
constructor(public payload) {}
126+
}
127+
128+
export class UpdateEntrySuccess implements Action {
129+
public readonly type = EntryActionTypes.UPDATE_ENTRY_SUCCESS;
123130

124131
constructor(public payload: Entry) {}
125132
}
126133

127-
export class UpdateActiveEntryFail implements Action {
128-
public readonly type = EntryActionTypes.UPDATE_ACTIVE_ENTRY_FAIL;
134+
export class UpdateEntryFail implements Action {
135+
public readonly type = EntryActionTypes.UPDATE_ENTRY_FAIL;
129136

130137
constructor(public error: string) {}
131138
}
@@ -186,9 +193,10 @@ export type EntryActions =
186193
| CreateEntry
187194
| CreateEntrySuccess
188195
| CreateEntryFail
189-
| UpdateActiveEntry
190-
| UpdateActiveEntrySuccess
191-
| UpdateActiveEntryFail
196+
| UpdateEntryRunning
197+
| UpdateEntry
198+
| UpdateEntrySuccess
199+
| UpdateEntryFail
192200
| DeleteEntry
193201
| DeleteEntrySuccess
194202
| DeleteEntryFail

src/app/modules/time-clock/store/entry.effects.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { INFO_SAVED_SUCCESSFULLY } from './../../shared/messages';
12
import {TestBed} from '@angular/core/testing';
23
import {provideMockActions} from '@ngrx/effects/testing';
34
import {EntryEffects} from './entry.effects';
45
import {Observable, of, throwError} from 'rxjs';
56
import {HttpClientTestingModule} from '@angular/common/http/testing';
6-
import {ToastrModule} from 'ngx-toastr';
7+
import { ToastrModule, ToastrService } from 'ngx-toastr';
78
import {Action} from '@ngrx/store';
89
import {DatePipe} from '@angular/common';
910
import {EntryActionTypes} from './entry.actions';
@@ -15,6 +16,7 @@ describe('TimeEntryActionEffects', () => {
1516
let actions$: Observable<Action>;
1617
let effects: EntryEffects;
1718
let service;
19+
let toastrService;
1820

1921
beforeEach(() => {
2022
TestBed.configureTestingModule({
@@ -28,6 +30,7 @@ describe('TimeEntryActionEffects', () => {
2830
});
2931
effects = TestBed.inject(EntryEffects);
3032
service = TestBed.inject(EntryService);
33+
toastrService = TestBed.inject(ToastrService);
3134
});
3235

3336
it('should be created', async () => {
@@ -95,7 +98,27 @@ describe('TimeEntryActionEffects', () => {
9598
serviceSpy.and.returnValue(of(activeEntry));
9699

97100
effects.loadActiveEntry$.subscribe(action => {
98-
expect(action.type).toEqual(EntryActionTypes.UPDATE_ACTIVE_ENTRY);
101+
expect(action.type).toEqual(EntryActionTypes.UPDATE_ENTRY);
102+
});
103+
});
104+
105+
it('display a success message on UPDATE_ENTRY', async () => {
106+
const activeEntry = {};
107+
actions$ = of({type: EntryActionTypes.UPDATE_ENTRY, activeEntry});
108+
spyOn(toastrService, 'success');
109+
110+
effects.updateEntry$.subscribe(action => {
111+
expect(toastrService.success).toHaveBeenCalledWith(INFO_SAVED_SUCCESSFULLY);
112+
});
113+
});
114+
115+
it('does not display any message on UPDATE_ENTRY_RUNNING', async () => {
116+
const activeEntry = {};
117+
actions$ = of({type: EntryActionTypes.UPDATE_ENTRY_RUNNING, activeEntry});
118+
spyOn(toastrService, 'success');
119+
120+
effects.updateEntry$.subscribe(action => {
121+
expect(toastrService.success).toHaveBeenCalledTimes(0);
99122
});
100123
});
101124

src/app/modules/time-clock/store/entry.effects.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class EntryEffects {
4646
} else {
4747
const endDate = new Date(activeEntry.start_date);
4848
endDate.setHours(23, 59, 59);
49-
return new actions.UpdateActiveEntry({id: activeEntry.id, end_date: endDate.toISOString()});
49+
return new actions.UpdateEntry({id: activeEntry.id, end_date: endDate.toISOString()});
5050
}
5151
}
5252
}),
@@ -113,18 +113,35 @@ export class EntryEffects {
113113
);
114114

115115
@Effect()
116-
updateActiveEntry$: Observable<Action> = this.actions$.pipe(
117-
ofType(actions.EntryActionTypes.UPDATE_ACTIVE_ENTRY),
118-
map((action: actions.UpdateActiveEntry) => action.payload),
116+
updateEntry$: Observable<Action> = this.actions$.pipe(
117+
ofType(actions.EntryActionTypes.UPDATE_ENTRY),
118+
map((action: actions.UpdateEntry) => action.payload),
119119
mergeMap((entry) =>
120-
this.entryService.updateActiveEntry(entry).pipe(
120+
this.entryService.updateEntry(entry).pipe(
121121
map((entryResponse) => {
122122
this.toastrService.success(INFO_SAVED_SUCCESSFULLY);
123-
return new actions.UpdateActiveEntrySuccess(entryResponse);
123+
return new actions.UpdateEntrySuccess(entryResponse);
124124
}),
125125
catchError((error) => {
126126
this.toastrService.error(error.error.message);
127-
return of(new actions.UpdateActiveEntryFail(error));
127+
return of(new actions.UpdateEntryFail(error));
128+
})
129+
)
130+
)
131+
);
132+
133+
@Effect()
134+
updateEntryRunning$: Observable<Action> = this.actions$.pipe(
135+
ofType(actions.EntryActionTypes.UPDATE_ENTRY_RUNNING),
136+
map((action: actions.UpdateEntry) => action.payload),
137+
mergeMap((entry) =>
138+
this.entryService.updateEntry(entry).pipe(
139+
map((entryResponse) => {
140+
return new actions.UpdateEntrySuccess(entryResponse);
141+
}),
142+
catchError((error) => {
143+
this.toastrService.error(error.error.message);
144+
return of(new actions.UpdateEntryFail(error));
128145
})
129146
)
130147
)

0 commit comments

Comments
 (0)