Skip to content
Merged
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
fix: #329 reload time-entries, #274 sets the right project id on time…
…-clock screen, #327 close modal #325 #323
  • Loading branch information
enriquezrene committed Jun 2, 2020
commit 10e7694a56bd6cca2df98664d54175bdfa293f86
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export class TimeRangeFormComponent {
onSubmit() {
this.store.dispatch(new entryActions.LoadEntriesByTimeRange({
start_date: this.startDate.value,
end_date: this.endDate.value
end_date: this.endDate.value,
user_id: '*',
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('Reports Page', () => {
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntriesByTimeRange({
start_date: startDateValue,
end_date: endDateValue,
user_id: '*',
}));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<span class="input-group-text span-width">Activity</span>
</div>
<select id="activitiesSelect" (blur)="onSubmit()" class="form-control" formControlName="activity_id">
<option value="-1"></option>
<option *ngFor="let activity of activities" value="{{activity.id}}">{{ activity.name }}</option>
</select>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class EntryFieldsComponent implements OnInit {
this.entryForm = this.formBuilder.group({
description: '',
uri: '',
activity_id: ''
activity_id: '-1'
});
}

Expand All @@ -38,8 +38,11 @@ export class EntryFieldsComponent implements OnInit {
const activities$ = this.store.pipe(select(allActivities));
activities$.subscribe((response) => {
this.activities = response;
this.loadActiveEntry();
});
}

loadActiveEntry() {
const activeEntry$ = this.store.pipe(select(getActiveTimeEntry));
activeEntry$.subscribe((response) => {
if (response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class ProjectListHoverComponent implements OnInit {
const projects$ = this.store.pipe(select(getProjects));
projects$.subscribe((projects) => {
this.listProjects = projects;
this.loadActiveTimeEntry();
});
this.loadActiveTimeEntry();
}

private loadActiveTimeEntry() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface TimeEntriesTimeRange {
start_date: Date;
end_date: Date;
user_id: string;
}
2 changes: 1 addition & 1 deletion src/app/modules/time-clock/services/entry.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('EntryService', () => {
const startDateValue = new Date();
const endDateValue = new Date();
const pipe: DatePipe = new DatePipe('en');
const timeRange: TimeEntriesTimeRange = {start_date: startDateValue, end_date: endDateValue};
const timeRange: TimeEntriesTimeRange = {start_date: startDateValue, end_date: endDateValue, user_id: '*'};

service.loadEntriesByTimeRange(timeRange).subscribe();

Expand Down
3 changes: 2 additions & 1 deletion src/app/modules/time-clock/services/entry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export class EntryService {
{
params: {
start_date: this.datePipe.transform(range.start_date, EntryService.TIME_ENTRIES_DATE_TIME_FORMAT),
end_date: this.datePipe.transform(range.end_date, EntryService.TIME_ENTRIES_DATE_TIME_FORMAT)
end_date: this.datePipe.transform(range.end_date, EntryService.TIME_ENTRIES_DATE_TIME_FORMAT),
user_id: range.user_id
}
}
);
Expand Down
23 changes: 21 additions & 2 deletions src/app/modules/time-clock/store/entry.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,27 @@ describe('TimeEntryActionEffects', () => {
expect(effects).toBeTruthy();
});

it('returns an action with type LOAD_ENTRIES_SUMMARY_SUCCESS when the service returns a value', () => {
actions$ = of({type: EntryActionTypes.LOAD_ENTRIES_SUMMARY});
const serviceSpy = spyOn(service, 'summary');
serviceSpy.and.returnValue(of({}));

effects.loadEntriesSummary$.subscribe(action => {
expect(action.type).toEqual(EntryActionTypes.LOAD_ENTRIES_SUMMARY_SUCCESS);
});
});

it('returns an action with type LOAD_ENTRIES_SUMMARY_FAIL when the service fails', () => {
actions$ = of({type: EntryActionTypes.LOAD_ENTRIES_SUMMARY});
spyOn(service, 'summary').and.returnValue(throwError('any error'));

effects.loadEntriesSummary$.subscribe(action => {
expect(action.type).toEqual(EntryActionTypes.LOAD_ENTRIES_SUMMARY_FAIL);
});
});

it('When the service returns a value, then LOAD_ENTRIES_BY_TIME_RANGE_SUCCESS should be triggered', () => {
const timeRange: TimeEntriesTimeRange = {start_date: new Date(), end_date: new Date()};
const timeRange: TimeEntriesTimeRange = {start_date: new Date(), end_date: new Date(), user_id: '*' };
actions$ = of({type: EntryActionTypes.LOAD_ENTRIES_BY_TIME_RANGE, timeRange});
const serviceSpy = spyOn(service, 'loadEntriesByTimeRange');
serviceSpy.and.returnValue(of([]));
Expand All @@ -47,7 +66,7 @@ describe('TimeEntryActionEffects', () => {
});

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

Expand Down
18 changes: 18 additions & 0 deletions src/app/modules/time-entries/pages/time-entries.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getActiveTimeEntry } from './../../time-clock/store/entry.selectors';
import { ToastrService } from 'ngx-toastr';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
Expand Down Expand Up @@ -232,4 +233,21 @@ describe('TimeEntriesComponent', () => {
component.getMonth(month);
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntries(month));
});


it('doSave when activeTimeEntry === null', async(() => {
const entryToSave = {
project_id: 'project-id',
start_date: '2010-05-05T10:04',
description: 'description',
technologies: [],
uri: 'abc',
};
spyOn(component, 'doSave');
component.activeTimeEntry = null;

component.saveEntry(entryToSave);

expect(component.doSave).toHaveBeenCalledWith(entryToSave);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class TimeEntriesComponent implements OnInit {
} else {
this.doSave(entry);
}
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
}

doSave(entry) {
Expand All @@ -65,7 +66,6 @@ export class TimeEntriesComponent implements OnInit {
} else {
this.store.dispatch(new entryActions.CreateEntry(entry));
}
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
}

removeEntry(entryId: string) {
Expand Down