@@ -29,9 +29,10 @@ describe('EntryFieldsComponent', () => {
2929 error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { } ,
3030 warning : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { }
3131 } ;
32- const lastDate = moment ( ) . format ( 'YYYY-MM-DD' ) ;
33- const startHourTest = moment ( ) . subtract ( 5 , 'hours' ) . format ( 'HH:mm:ss' ) ;
34- const endHourTest = moment ( ) . subtract ( 3 , 'hours' ) . format ( 'HH:mm:ss' ) ;
32+ const mockDate = '2020-12-01T12:00:00' ;
33+ const lastDate = moment ( mockDate ) . format ( DATE_FORMAT_YEAR ) ;
34+ const startHourTest = moment ( mockDate ) . subtract ( 5 , 'hours' ) . format ( 'HH:mm:ss' ) ;
35+ const endHourTest = moment ( mockDate ) . subtract ( 3 , 'hours' ) . format ( 'HH:mm:ss' ) ;
3536 const lastStartHourEntryEntered = new Date ( `${ lastDate } T${ startHourTest . trim ( ) } ` ) . toISOString ( ) ;
3637 const lastEndHourEntryEntered = new Date ( `${ lastDate } T${ endHourTest . trim ( ) } ` ) . toISOString ( ) ;
3738
@@ -95,8 +96,8 @@ describe('EntryFieldsComponent', () => {
9596 project_id : 'project-id-15' ,
9697 description : 'description for active entry' ,
9798 uri : 'abc' ,
98- start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
99- start_hour : moment ( ) . format ( 'HH:mm' ) ,
99+ start_date : moment ( mockDate ) . format ( DATE_FORMAT_YEAR ) ,
100+ start_hour : moment ( mockDate ) . format ( 'HH:mm' ) ,
100101 } ;
101102
102103 beforeEach ( waitForAsync ( ( ) => {
@@ -144,16 +145,20 @@ describe('EntryFieldsComponent', () => {
144145 uri : entryDataForm . uri ,
145146 activity_id : entryDataForm . activity_id ,
146147 start_hour : formatDate ( entry . start_date , 'HH:mm' , 'en' ) ,
147- start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
148+ start_date : moment ( mockDate ) . format ( DATE_FORMAT_YEAR ) ,
148149 }
149150 ) ;
150151 expect ( component . selectedTechnologies ) . toEqual ( [ ] ) ;
151152 } ) ;
152153
153154 it ( 'displays error message when the date selected is in the future' , ( ) => {
154- component . newData = entry ;
155- component . activeEntry = entry ;
156- component . setDataToUpdate ( entry ) ;
155+ const mockEntry = { ...entry ,
156+ start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
157+ start_hour : moment ( ) . format ( 'HH:mm' )
158+ } ;
159+ component . newData = mockEntry ;
160+ component . activeEntry = mockEntry ;
161+ component . setDataToUpdate ( mockEntry ) ;
157162 spyOn ( toastrServiceStub , 'error' ) ;
158163
159164 const hourInTheFuture = moment ( ) . add ( 1 , 'hours' ) . format ( 'HH:mm' ) ;
@@ -170,7 +175,7 @@ describe('EntryFieldsComponent', () => {
170175 component . setDataToUpdate ( entry ) ;
171176 spyOn ( toastrServiceStub , 'error' ) ;
172177
173- const hourInThePast = moment ( ) . subtract ( 6 , 'hour' ) . format ( 'HH:mm' ) ;
178+ const hourInThePast = moment ( mockDate ) . subtract ( 6 , 'hour' ) . format ( 'HH:mm' ) ;
174179 component . entryForm . patchValue ( { start_hour : hourInThePast } ) ;
175180 component . onUpdateStartHour ( ) ;
176181
@@ -188,7 +193,7 @@ describe('EntryFieldsComponent', () => {
188193 component . newData = entry ;
189194 component . activeEntry = entry ;
190195 component . setDataToUpdate ( entry ) ;
191- const updatedTime = moment ( ) . format ( 'HH:mm' ) ;
196+ const updatedTime = moment ( mockDate ) . format ( 'HH:mm' ) ;
192197 component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
193198 spyOn ( component . entryForm , 'patchValue' ) ;
194199 component . cancelTimeInUpdate ( ) ;
@@ -206,7 +211,7 @@ describe('EntryFieldsComponent', () => {
206211 component . activeEntry = entry ;
207212 component . setDataToUpdate ( entry ) ;
208213
209- const updatedTime = moment ( ) . subtract ( 6 , 'hours' ) . format ( 'HH:mm' ) ;
214+ const updatedTime = moment ( mockDate ) . subtract ( 6 , 'hours' ) . format ( 'HH:mm' ) ;
210215 component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
211216
212217 spyOn ( component . entryForm , 'patchValue' ) ;
@@ -221,9 +226,13 @@ describe('EntryFieldsComponent', () => {
221226 } ) ;
222227
223228 it ( 'If start hour is in the future, reset to initial start_date in form' , ( ) => {
224- component . newData = entry ;
225- component . activeEntry = entry ;
226- component . setDataToUpdate ( entry ) ;
229+ const mockEntry = { ...entry ,
230+ start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
231+ start_hour : moment ( ) . format ( 'HH:mm' )
232+ } ;
233+ component . newData = mockEntry ;
234+ component . activeEntry = mockEntry ;
235+ component . setDataToUpdate ( mockEntry ) ;
227236
228237 const hourInTheFuture = moment ( ) . add ( 1 , 'hours' ) . format ( 'HH:mm' ) ;
229238 component . entryForm . patchValue ( { start_hour : hourInTheFuture } ) ;
@@ -240,9 +249,10 @@ describe('EntryFieldsComponent', () => {
240249 } ) ;
241250
242251 it ( 'when a start hour is updated, then dispatch UpdateActiveEntry' , ( ) => {
243- component . activeEntry = entry ;
252+ component . activeEntry = entry ;
244253 component . setDataToUpdate ( entry ) ;
245- const updatedTime = moment ( ) . format ( 'HH:mm' ) ;
254+ const updatedTime = moment ( mockDate ) . format ( 'HH:mm' ) ;
255+
246256 component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
247257 spyOn ( store , 'dispatch' ) ;
248258
@@ -252,9 +262,9 @@ describe('EntryFieldsComponent', () => {
252262 } ) ;
253263
254264 it ( 'When start_time is updated, component.last_entry is equal to time entry in the position 1' , waitForAsync ( ( ) => {
255- component . activeEntry = entry ;
265+ component . activeEntry = entry ;
256266 component . setDataToUpdate ( entry ) ;
257- const updatedTime = moment ( ) . format ( 'HH:mm' ) ;
267+ const updatedTime = moment ( mockDate ) . format ( 'HH:mm' ) ;
258268
259269 component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
260270 component . onUpdateStartHour ( ) ;
@@ -263,9 +273,9 @@ describe('EntryFieldsComponent', () => {
263273 } ) ) ;
264274
265275 it ( 'When start_time is updated for a time entry. UpdateCurrentOrLastEntry action is dispatched' , ( ) => {
266- component . activeEntry = entry ;
276+ component . activeEntry = entry ;
267277 component . setDataToUpdate ( entry ) ;
268- const updatedTime = moment ( ) . subtract ( 4 , 'hours' ) . format ( 'HH:mm' ) ;
278+ const updatedTime = moment ( mockDate ) . subtract ( 4 , 'hours' ) . format ( 'HH:mm' ) ;
269279 component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
270280 spyOn ( store , 'dispatch' ) ;
271281
0 commit comments