Skip to content

Commit c14f35f

Browse files
committed
test: add test for new field time in #233
1 parent 0a52158 commit c14f35f

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {getCustomerProjects} from '../../../customer-management/components/proje
1212
import { ActionsSubject } from '@ngrx/store';
1313
import { IndividualConfig, ToastrService } from 'ngx-toastr';
1414
import { formatDate } from '@angular/common';
15+
import * as moment from 'moment';
1516

1617
describe('EntryFieldsComponent', () => {
1718
type Merged = TechnologyState & ProjectState;
@@ -65,7 +66,8 @@ describe('EntryFieldsComponent', () => {
6566
project_id: 'project-id-15',
6667
description: 'description for active entry',
6768
uri: 'abc',
68-
start_date : '2020-10-22T10:00:00.000Z'
69+
start_date : '2020-10-22T10:00:00.000Z',
70+
start_hour : formatDate('2020-10-22T10:00:00.000Z', 'HH:mm:ss', 'en'),
6971
};
7072

7173
beforeEach(async(() => {
@@ -118,6 +120,47 @@ describe('EntryFieldsComponent', () => {
118120
expect(component.selectedTechnologies).toEqual([]);
119121
});
120122

123+
it('when a start hour is updated, then dispatch UpdateActiveEntry & LoadActiveEntry', () => {
124+
component.activeEntry = entry ;
125+
component.setDataToUpdate(entry);
126+
spyOn(store, 'dispatch');
127+
128+
component.onUpdateStartHour();
129+
expect(store.dispatch).toHaveBeenCalled();
130+
expect(store.dispatch).toHaveBeenCalledTimes(2);
131+
});
132+
133+
it('displays error message when the date selected is in the future', () => {
134+
component.newData = entry;
135+
component.activeEntry = entry ;
136+
component.setDataToUpdate(entry);
137+
spyOn(toastrServiceStub, 'error');
138+
139+
const hourInTheFuture = moment().add(1, 'hours').format('HH:mm:ss');
140+
component.entryForm.patchValue({ start_hour : hourInTheFuture});
141+
component.onUpdateStartHour();
142+
143+
expect(toastrServiceStub.error).toHaveBeenCalled();
144+
});
145+
146+
it('If start hour is in the future, reset to initial start_date in form', () => {
147+
component.newData = entry;
148+
component.activeEntry = entry ;
149+
component.setDataToUpdate(entry);
150+
151+
const hourInTheFuture = moment().add(1, 'hours').format('HH:mm:ss');
152+
component.entryForm.patchValue({ start_hour : hourInTheFuture});
153+
154+
spyOn(component.entryForm, 'patchValue');
155+
component.onUpdateStartHour();
156+
157+
expect(component.entryForm.patchValue).toHaveBeenCalledWith(
158+
{
159+
start_hour: component.newData.start_hour
160+
}
161+
);
162+
});
163+
121164
it('when a technology is added, then dispatch UpdateActiveEntry', () => {
122165
const addedTechnologies = ['react'];
123166
spyOn(store, 'dispatch');

0 commit comments

Comments
 (0)