Skip to content

Commit 10e7694

Browse files
committed
fix: #329 reload time-entries, #274 sets the right project id on time-clock screen, #327 close modal #325 #323
1 parent feaf175 commit 10e7694

File tree

11 files changed

+53
-8
lines changed

11 files changed

+53
-8
lines changed

src/app/modules/reports/components/time-range-form/time-range-form.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export class TimeRangeFormComponent {
2323
onSubmit() {
2424
this.store.dispatch(new entryActions.LoadEntriesByTimeRange({
2525
start_date: this.startDate.value,
26-
end_date: this.endDate.value
26+
end_date: this.endDate.value,
27+
user_id: '*',
2728
}));
2829
}
2930
}

src/app/modules/reports/components/time-range-form/time-range.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ describe('Reports Page', () => {
6767
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntriesByTimeRange({
6868
start_date: startDateValue,
6969
end_date: endDateValue,
70+
user_id: '*',
7071
}));
7172
});
7273

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<span class="input-group-text span-width">Activity</span>
55
</div>
66
<select id="activitiesSelect" (blur)="onSubmit()" class="form-control" formControlName="activity_id">
7+
<option value="-1"></option>
78
<option *ngFor="let activity of activities" value="{{activity.id}}">{{ activity.name }}</option>
89
</select>
910
</div>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class EntryFieldsComponent implements OnInit {
2929
this.entryForm = this.formBuilder.group({
3030
description: '',
3131
uri: '',
32-
activity_id: ''
32+
activity_id: '-1'
3333
});
3434
}
3535

@@ -38,8 +38,11 @@ export class EntryFieldsComponent implements OnInit {
3838
const activities$ = this.store.pipe(select(allActivities));
3939
activities$.subscribe((response) => {
4040
this.activities = response;
41+
this.loadActiveEntry();
4142
});
43+
}
4244

45+
loadActiveEntry() {
4346
const activeEntry$ = this.store.pipe(select(getActiveTimeEntry));
4447
activeEntry$.subscribe((response) => {
4548
if (response) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export class ProjectListHoverComponent implements OnInit {
3131
const projects$ = this.store.pipe(select(getProjects));
3232
projects$.subscribe((projects) => {
3333
this.listProjects = projects;
34+
this.loadActiveTimeEntry();
3435
});
35-
this.loadActiveTimeEntry();
3636
}
3737

3838
private loadActiveTimeEntry() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface TimeEntriesTimeRange {
22
start_date: Date;
33
end_date: Date;
4+
user_id: string;
45
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('EntryService', () => {
9292
const startDateValue = new Date();
9393
const endDateValue = new Date();
9494
const pipe: DatePipe = new DatePipe('en');
95-
const timeRange: TimeEntriesTimeRange = {start_date: startDateValue, end_date: endDateValue};
95+
const timeRange: TimeEntriesTimeRange = {start_date: startDateValue, end_date: endDateValue, user_id: '*'};
9696

9797
service.loadEntriesByTimeRange(timeRange).subscribe();
9898

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export class EntryService {
5555
{
5656
params: {
5757
start_date: this.datePipe.transform(range.start_date, EntryService.TIME_ENTRIES_DATE_TIME_FORMAT),
58-
end_date: this.datePipe.transform(range.end_date, EntryService.TIME_ENTRIES_DATE_TIME_FORMAT)
58+
end_date: this.datePipe.transform(range.end_date, EntryService.TIME_ENTRIES_DATE_TIME_FORMAT),
59+
user_id: range.user_id
5960
}
6061
}
6162
);

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,27 @@ describe('TimeEntryActionEffects', () => {
3434
expect(effects).toBeTruthy();
3535
});
3636

37+
it('returns an action with type LOAD_ENTRIES_SUMMARY_SUCCESS when the service returns a value', () => {
38+
actions$ = of({type: EntryActionTypes.LOAD_ENTRIES_SUMMARY});
39+
const serviceSpy = spyOn(service, 'summary');
40+
serviceSpy.and.returnValue(of({}));
41+
42+
effects.loadEntriesSummary$.subscribe(action => {
43+
expect(action.type).toEqual(EntryActionTypes.LOAD_ENTRIES_SUMMARY_SUCCESS);
44+
});
45+
});
46+
47+
it('returns an action with type LOAD_ENTRIES_SUMMARY_FAIL when the service fails', () => {
48+
actions$ = of({type: EntryActionTypes.LOAD_ENTRIES_SUMMARY});
49+
spyOn(service, 'summary').and.returnValue(throwError('any error'));
50+
51+
effects.loadEntriesSummary$.subscribe(action => {
52+
expect(action.type).toEqual(EntryActionTypes.LOAD_ENTRIES_SUMMARY_FAIL);
53+
});
54+
});
55+
3756
it('When the service returns a value, then LOAD_ENTRIES_BY_TIME_RANGE_SUCCESS should be triggered', () => {
38-
const timeRange: TimeEntriesTimeRange = {start_date: new Date(), end_date: new Date()};
57+
const timeRange: TimeEntriesTimeRange = {start_date: new Date(), end_date: new Date(), user_id: '*' };
3958
actions$ = of({type: EntryActionTypes.LOAD_ENTRIES_BY_TIME_RANGE, timeRange});
4059
const serviceSpy = spyOn(service, 'loadEntriesByTimeRange');
4160
serviceSpy.and.returnValue(of([]));
@@ -47,7 +66,7 @@ describe('TimeEntryActionEffects', () => {
4766
});
4867

4968
it('When the service fails, then LOAD_ENTRIES_BY_TIME_RANGE_FAIL should be triggered', async () => {
50-
const timeRange: TimeEntriesTimeRange = {start_date: new Date(), end_date: new Date()};
69+
const timeRange: TimeEntriesTimeRange = {start_date: new Date(), end_date: new Date(), user_id: '*'};
5170
actions$ = of({type: EntryActionTypes.LOAD_ENTRIES_BY_TIME_RANGE, timeRange});
5271
spyOn(service, 'loadEntriesByTimeRange').and.returnValue(throwError('any error'));
5372

src/app/modules/time-entries/pages/time-entries.component.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getActiveTimeEntry } from './../../time-clock/store/entry.selectors';
12
import { ToastrService } from 'ngx-toastr';
23
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
34
import { provideMockStore, MockStore } from '@ngrx/store/testing';
@@ -232,4 +233,21 @@ describe('TimeEntriesComponent', () => {
232233
component.getMonth(month);
233234
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntries(month));
234235
});
236+
237+
238+
it('doSave when activeTimeEntry === null', async(() => {
239+
const entryToSave = {
240+
project_id: 'project-id',
241+
start_date: '2010-05-05T10:04',
242+
description: 'description',
243+
technologies: [],
244+
uri: 'abc',
245+
};
246+
spyOn(component, 'doSave');
247+
component.activeTimeEntry = null;
248+
249+
component.saveEntry(entryToSave);
250+
251+
expect(component.doSave).toHaveBeenCalledWith(entryToSave);
252+
}));
235253
});

0 commit comments

Comments
 (0)