Skip to content

Commit ae55794

Browse files
committed
fix: #572 correct names of tests, messages and variables
1 parent 79e991a commit ae55794

File tree

4 files changed

+41
-29
lines changed

4 files changed

+41
-29
lines changed

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LoadActiveEntry, EntryActionTypes } from './../../store/entry.actions';
1+
import { LoadActiveEntry, EntryActionTypes, UpdateEntry } from './../../store/entry.actions';
22
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
33
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
44
import {MockStore, provideMockStore} from '@ngrx/store/testing';
@@ -28,8 +28,8 @@ describe('EntryFieldsComponent', () => {
2828
warning: (message?: string, title?: string, override?: Partial<IndividualConfig>) => { }
2929
};
3030
const lastDate = moment().format('YYYY-MM-DD');
31-
const startHourTest = moment().add(-5, 'hours').format('HH:mm:ss');
32-
const endHourTest = moment().add(-3, 'hours').format('HH:mm:ss');
31+
const startHourTest = moment().subtract(5, 'hours').format('HH:mm:ss');
32+
const endHourTest = moment().subtract(3, 'hours').format('HH:mm:ss');
3333
const lastStartHourEntryEntered = new Date(`${lastDate}T${startHourTest.trim()}`).toISOString();
3434
const lastEndHourEntryEntered = new Date(`${lastDate}T${endHourTest.trim()}`).toISOString();
3535

@@ -161,26 +161,26 @@ describe('EntryFieldsComponent', () => {
161161
expect(toastrServiceStub.error).toHaveBeenCalled();
162162
});
163163

164-
it('displays error message when new hour entered is in the past of other entry', () => {
164+
it('Displays an error message when the active entry has start_time before the start_time of another entry', () => {
165165
component.newData = entry;
166166
component.activeEntry = entry ;
167167
component.setDataToUpdate(entry);
168168
spyOn(toastrServiceStub, 'error');
169169

170-
const hourInTheFuture = moment().add(-6, 'hour').format('HH:mm:ss');
171-
component.entryForm.patchValue({ start_hour : hourInTheFuture});
170+
const hourInThePast = moment().subtract(6, 'hour').format('HH:mm:ss');
171+
component.entryForm.patchValue({ start_hour : hourInThePast});
172172
component.onUpdateStartHour();
173173

174174
expect(toastrServiceStub.error).toHaveBeenCalled();
175175
});
176176

177-
it('If start hour is in the past of other entry, reset to initial start_date in form', () => {
177+
it('should reset to current start_date when start_date has an error', () => {
178178
component.newData = entry;
179179
component.activeEntry = entry ;
180180
component.setDataToUpdate(entry);
181181

182-
const newHour = moment().add(-6, 'hours').format('HH:mm:ss');
183-
component.entryForm.patchValue({ start_hour : newHour});
182+
const updatedTime = moment().subtract(6, 'hours').format('HH:mm:ss');
183+
component.entryForm.patchValue({ start_hour : updatedTime});
184184

185185
spyOn(component.entryForm, 'patchValue');
186186
component.onUpdateStartHour();
@@ -213,35 +213,38 @@ describe('EntryFieldsComponent', () => {
213213
it('when a start hour is updated, then dispatch UpdateActiveEntry', () => {
214214
component.activeEntry = entry ;
215215
component.setDataToUpdate(entry);
216-
const newHour = moment().format('HH:mm:ss');
217-
component.entryForm.patchValue({ start_hour : newHour});
216+
const updatedTime = moment().format('HH:mm:ss');
217+
component.entryForm.patchValue({ start_hour : updatedTime});
218218
spyOn(store, 'dispatch');
219219

220220
component.onUpdateStartHour();
221221
expect(store.dispatch).toHaveBeenCalled();
222222
});
223223

224-
it('when a start hour is update, then select the last time entry', async(() => {
224+
it('When start_time is updated, component.last_entry is equal to time entry in the position 1', async(() => {
225225
component.activeEntry = entry ;
226226
component.setDataToUpdate(entry);
227-
const newHour = moment().format('HH:mm:ss');
227+
const updatedTime = moment().format('HH:mm:ss');
228228

229-
component.entryForm.patchValue({ start_hour : newHour});
229+
component.entryForm.patchValue({ start_hour : updatedTime});
230230
component.onUpdateStartHour();
231231

232232
expect(component.lastEntry).toBe(state.entries.timeEntriesDataSource.data[1]);
233233
}));
234234

235-
it('when a start hour is updated in other time entry, then dispatch UpdateEntry and UpdateEntryRunning', () => {
235+
it('When start_time is updated for a time entry. UpdateEntry and UpdateEntryRuning actions are dispatched', () => {
236236
component.activeEntry = entry ;
237237
component.setDataToUpdate(entry);
238-
239-
const newHour = moment().add(-4, 'hours').format('HH:mm:ss');
240-
component.entryForm.patchValue({ start_hour : newHour});
238+
const lastEntry = state.entries.timeEntriesDataSource.data[1];
239+
const updatedTime = moment().subtract(4, 'hours').format('HH:mm:ss');
240+
const lastStartHourEntryEnteredTest = new Date(`${lastDate}T${updatedTime.trim()}`).toISOString();
241+
component.entryForm.patchValue({ start_hour : updatedTime});
241242
spyOn(store, 'dispatch');
242243

243244
component.onUpdateStartHour();
245+
244246
expect(store.dispatch).toHaveBeenCalledTimes(2);
247+
expect(store.dispatch).toHaveBeenCalledWith(new UpdateEntry({id: lastEntry.id, end_date: lastStartHourEntryEnteredTest}));
245248
});
246249

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

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TechnologyState } from '../../../shared/store/technology.reducers';
1010
import { ActivityState, LoadActivities } from '../../../activities-management/store';
1111

1212
import * as entryActions from '../../store/entry.actions';
13-
13+
import { get } from 'lodash';
1414
import * as moment from 'moment';
1515
import { ToastrService } from 'ngx-toastr';
1616
import { formatDate } from '@angular/common';
@@ -37,7 +37,6 @@ export class EntryFieldsComponent implements OnInit {
3737
private actionsSubject$: ActionsSubject,
3838
private toastrService: ToastrService
3939
) {
40-
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
4140
this.entryForm = this.formBuilder.group({
4241
description: '',
4342
uri: '',
@@ -49,7 +48,7 @@ export class EntryFieldsComponent implements OnInit {
4948

5049
ngOnInit(): void {
5150
this.store.dispatch(new LoadActivities());
52-
51+
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
5352
this.actionsSubject$
5453
.pipe(filter((action: any) => action.type === ActivityManagementActionTypes.LOAD_ACTIVITIES_SUCCESS))
5554
.subscribe((action) => {
@@ -122,6 +121,7 @@ export class EntryFieldsComponent implements OnInit {
122121
}
123122

124123
onUpdateStartHour() {
124+
this.getLastEntry();
125125
const startDate = formatDate(this.activeEntry.start_date, 'yyyy-MM-dd', 'en');
126126
const newHourEntered = new Date(`${startDate}T${this.entryForm.value.start_hour.trim()}`).toISOString();
127127
const isEntryDateInTheFuture = moment(newHourEntered).isAfter(moment());
@@ -131,12 +131,10 @@ export class EntryFieldsComponent implements OnInit {
131131
return;
132132
}
133133

134-
this.getLastEntry();
135-
136-
const isFirstEntry = this.lastEntry !== undefined ? this.lastEntry.start_date : moment().add(-1, 'hours');
137-
const isEntryDateInLastStartDate = moment(newHourEntered).isBefore(isFirstEntry);
134+
const lastEntryStartDate = get(this.lastEntry, 'start_date', moment().subtract(1, 'hours'));
135+
const isEntryDateInLastStartDate = moment(newHourEntered).isSameOrBefore(lastEntryStartDate);
138136
if (isEntryDateInLastStartDate) {
139-
this.toastrService.error('You cannot start a time-entry before another time-entry');
137+
this.toastrService.error('There is another time entry registered in this time range');
140138
this.entryForm.patchValue({ start_hour: this.newData.start_hour });
141139
return;
142140
}
@@ -145,8 +143,8 @@ export class EntryFieldsComponent implements OnInit {
145143
}
146144

147145
private dispatchEntries(newHourEntered) {
148-
const isFirstEntry = this.lastEntry !== undefined ? this.lastEntry.end_date : moment().add(-1, 'hours');
149-
const isInLastEntry = moment(newHourEntered).isBefore(isFirstEntry);
146+
const lastEntryEndDate = get(this.lastEntry, 'end_date', moment().subtract(1, 'hours'));
147+
const isInLastEntry = moment(newHourEntered).isBefore(lastEntryEndDate);
150148
if (isInLastEntry) {
151149
this.store.dispatch(new entryActions.UpdateEntry({ id: this.lastEntry.id, end_date: newHourEntered }));
152150
}

src/app/modules/users/store/user.actions.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export enum UserActionTypes {
55
LOAD_USERS = '[User] LOAD_USERS',
66
LOAD_USERS_SUCCESS = '[User] LOAD_USERS_SUCCESS',
77
LOAD_USERS_FAIL = '[User] LOAD_USERS_FAIL',
8+
DEFAULT_USER = '[USER] DEFAULT_USER',
89
}
910

1011
export class LoadUsers implements Action {
@@ -21,4 +22,8 @@ export class LoadUsersFail implements Action {
2122
constructor(public error: string) {}
2223
}
2324

24-
export type UserActions = LoadUsers | LoadUsersSuccess | LoadUsersFail;
25+
export class DefaultUser implements Action {
26+
public readonly type = UserActionTypes.DEFAULT_USER;
27+
}
28+
29+
export type UserActions = LoadUsers | LoadUsersSuccess | LoadUsersFail | DefaultUser;

src/app/modules/users/store/user.reducer.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ describe('userReducer', () => {
2727
expect(state.isLoading).toEqual(false);
2828
expect(state.data.length).toBe(0);
2929
});
30+
31+
it('on Default, ', () => {
32+
const action = new actions.DefaultUser();
33+
const state = userReducer(initialState, action);
34+
expect(state).toEqual(initialState);
35+
});
3036
});

0 commit comments

Comments
 (0)