Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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 Expand Up @@ -61,5 +61,6 @@ export class ProjectListHoverComponent implements OnInit {
const newEntry = { project_id: selectedProject, start_date: new Date().toISOString() };
this.store.dispatch(new entryActions.CreateEntry(newEntry));
}
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1 ));
}
}
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
2 changes: 1 addition & 1 deletion src/app/modules/time-clock/store/entry.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
const entryList = [...state.entryList];
const index = entryList.findIndex((entry) => entry.id === action.payload.id);
entryList[index] = action.payload;
entryList.sort((a, b) => b.start_date.getTime() - a.start_date.getTime());
entryList.sort((a, b) => new Date(b.start_date).getTime() - new Date(a.start_date).getTime());
return {
...state,
isLoading: false,
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 Down