|
1 |
| -import { LoadActiveEntry, EntryActionTypes } from './../../store/entry.actions'; |
| 1 | +import { LoadActiveEntry, EntryActionTypes, UpdateEntry } from './../../store/entry.actions'; |
2 | 2 | import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
|
3 | 3 | import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
4 | 4 | import {MockStore, provideMockStore} from '@ngrx/store/testing';
|
@@ -28,8 +28,8 @@ describe('EntryFieldsComponent', () => {
|
28 | 28 | warning: (message?: string, title?: string, override?: Partial<IndividualConfig>) => { }
|
29 | 29 | };
|
30 | 30 | 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'); |
33 | 33 | const lastStartHourEntryEntered = new Date(`${lastDate}T${startHourTest.trim()}`).toISOString();
|
34 | 34 | const lastEndHourEntryEntered = new Date(`${lastDate}T${endHourTest.trim()}`).toISOString();
|
35 | 35 |
|
@@ -161,26 +161,26 @@ describe('EntryFieldsComponent', () => {
|
161 | 161 | expect(toastrServiceStub.error).toHaveBeenCalled();
|
162 | 162 | });
|
163 | 163 |
|
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', () => { |
165 | 165 | component.newData = entry;
|
166 | 166 | component.activeEntry = entry ;
|
167 | 167 | component.setDataToUpdate(entry);
|
168 | 168 | spyOn(toastrServiceStub, 'error');
|
169 | 169 |
|
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}); |
172 | 172 | component.onUpdateStartHour();
|
173 | 173 |
|
174 | 174 | expect(toastrServiceStub.error).toHaveBeenCalled();
|
175 | 175 | });
|
176 | 176 |
|
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', () => { |
178 | 178 | component.newData = entry;
|
179 | 179 | component.activeEntry = entry ;
|
180 | 180 | component.setDataToUpdate(entry);
|
181 | 181 |
|
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}); |
184 | 184 |
|
185 | 185 | spyOn(component.entryForm, 'patchValue');
|
186 | 186 | component.onUpdateStartHour();
|
@@ -213,35 +213,38 @@ describe('EntryFieldsComponent', () => {
|
213 | 213 | it('when a start hour is updated, then dispatch UpdateActiveEntry', () => {
|
214 | 214 | component.activeEntry = entry ;
|
215 | 215 | 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}); |
218 | 218 | spyOn(store, 'dispatch');
|
219 | 219 |
|
220 | 220 | component.onUpdateStartHour();
|
221 | 221 | expect(store.dispatch).toHaveBeenCalled();
|
222 | 222 | });
|
223 | 223 |
|
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(() => { |
225 | 225 | component.activeEntry = entry ;
|
226 | 226 | component.setDataToUpdate(entry);
|
227 |
| - const newHour = moment().format('HH:mm:ss'); |
| 227 | + const updatedTime = moment().format('HH:mm:ss'); |
228 | 228 |
|
229 |
| - component.entryForm.patchValue({ start_hour : newHour}); |
| 229 | + component.entryForm.patchValue({ start_hour : updatedTime}); |
230 | 230 | component.onUpdateStartHour();
|
231 | 231 |
|
232 | 232 | expect(component.lastEntry).toBe(state.entries.timeEntriesDataSource.data[1]);
|
233 | 233 | }));
|
234 | 234 |
|
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', () => { |
236 | 236 | component.activeEntry = entry ;
|
237 | 237 | 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}); |
241 | 242 | spyOn(store, 'dispatch');
|
242 | 243 |
|
243 | 244 | component.onUpdateStartHour();
|
| 245 | + |
244 | 246 | expect(store.dispatch).toHaveBeenCalledTimes(2);
|
| 247 | + expect(store.dispatch).toHaveBeenCalledWith(new UpdateEntry({id: lastEntry.id, end_date: lastStartHourEntryEnteredTest})); |
245 | 248 | });
|
246 | 249 |
|
247 | 250 | it('when a technology is added, then dispatch UpdateActiveEntry', () => {
|
|
0 commit comments