@@ -26,8 +26,8 @@ describe('EntryFieldsComponent', () => {
2626 let entryForm ;
2727 const actionSub : ActionsSubject = new ActionsSubject ( ) ;
2828 const toastrServiceStub = {
29- error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { } ,
30- warning : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { }
29+ error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { } ,
30+ warning : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { } ,
3131 } ;
3232 const mockDate = '2020-12-01T12:00:00' ;
3333 const lastDate = moment ( mockDate ) . format ( DATE_FORMAT_YEAR ) ;
@@ -77,6 +77,8 @@ describe('EntryFieldsComponent', () => {
7777 uri : 'abc' ,
7878 start_date : moment ( ) . toISOString ( ) ,
7979 end_date : moment ( ) . toISOString ( ) ,
80+ project_name : 'project_name' ,
81+ customer_name : 'customer_name' ,
8082 } ,
8183 {
8284 activity_id : 'xyz' ,
@@ -87,9 +89,11 @@ describe('EntryFieldsComponent', () => {
8789 uri : 'abc' ,
8890 start_date : lastStartHourEntryEntered ,
8991 end_date : lastEndHourEntryEntered ,
90- }
91- ]
92- }
92+ project_name : 'project_name' ,
93+ customer_name : 'customer name' ,
94+ } ,
95+ ] ,
96+ } ,
9397 } ,
9498 } ;
9599
@@ -100,28 +104,31 @@ describe('EntryFieldsComponent', () => {
100104 description : 'description for active entry' ,
101105 uri : 'abc' ,
102106 start_date : moment ( mockDate ) . format ( DATE_FORMAT_YEAR ) ,
103- start_hour : moment ( mockDate ) . format ( 'HH:mm' )
107+ start_hour : moment ( mockDate ) . format ( 'HH:mm' ) ,
108+ customer_name : 'ioet' ,
104109 } ;
105110
106111 const mockEntryOverlap = {
107- update_last_entry_if_overlap : true
112+ update_last_entry_if_overlap : true ,
108113 } ;
109114
110- beforeEach ( waitForAsync ( ( ) => {
111- TestBed . configureTestingModule ( {
112- declarations : [ EntryFieldsComponent ] ,
113- providers : [
114- provideMockStore ( { initialState : state } ) ,
115- { provide : ActionsSubject , useValue : actionSub } ,
116- { provide : ToastrService , useValue : toastrServiceStub }
117- ] ,
118- imports : [ FormsModule , ReactiveFormsModule , NgxMaterialTimepickerModule ] ,
119- } ) . compileComponents ( ) ;
120- store = TestBed . inject ( MockStore ) ;
121- entryForm = TestBed . inject ( FormBuilder ) ;
122- mockTechnologySelector = store . overrideSelector ( allTechnologies , state . technologies ) ;
123- mockProjectsSelector = store . overrideSelector ( getCustomerProjects , state . projects ) ;
124- } ) ) ;
115+ beforeEach (
116+ waitForAsync ( ( ) => {
117+ TestBed . configureTestingModule ( {
118+ declarations : [ EntryFieldsComponent ] ,
119+ providers : [
120+ provideMockStore ( { initialState : state } ) ,
121+ { provide : ActionsSubject , useValue : actionSub } ,
122+ { provide : ToastrService , useValue : toastrServiceStub } ,
123+ ] ,
124+ imports : [ FormsModule , ReactiveFormsModule , NgxMaterialTimepickerModule ] ,
125+ } ) . compileComponents ( ) ;
126+ store = TestBed . inject ( MockStore ) ;
127+ entryForm = TestBed . inject ( FormBuilder ) ;
128+ mockTechnologySelector = store . overrideSelector ( allTechnologies , state . technologies ) ;
129+ mockProjectsSelector = store . overrideSelector ( getCustomerProjects , state . projects ) ;
130+ } )
131+ ) ;
125132
126133 beforeEach ( ( ) => {
127134 fixture = TestBed . createComponent ( EntryFieldsComponent ) ;
@@ -144,15 +151,13 @@ describe('EntryFieldsComponent', () => {
144151 spyOn ( component . entryForm , 'patchValue' ) ;
145152 component . setDataToUpdate ( entry ) ;
146153 expect ( component . entryForm . patchValue ) . toHaveBeenCalledTimes ( 1 ) ;
147- expect ( component . entryForm . patchValue ) . toHaveBeenCalledWith (
148- {
149- description : entryDataForm . description ,
150- uri : entryDataForm . uri ,
151- activity_id : entryDataForm . activity_id ,
152- start_hour : formatDate ( entry . start_date , 'HH:mm' , 'en' ) ,
153- start_date : moment ( mockDate ) . format ( DATE_FORMAT_YEAR ) ,
154- }
155- ) ;
154+ expect ( component . entryForm . patchValue ) . toHaveBeenCalledWith ( {
155+ description : entryDataForm . description ,
156+ uri : entryDataForm . uri ,
157+ activity_id : entryDataForm . activity_id ,
158+ start_hour : formatDate ( entry . start_date , 'HH:mm' , 'en' ) ,
159+ start_date : moment ( mockDate ) . format ( DATE_FORMAT_YEAR ) ,
160+ } ) ;
156161 expect ( component . selectedTechnologies ) . toEqual ( [ ] ) ;
157162 } ) ;
158163
@@ -164,7 +169,7 @@ describe('EntryFieldsComponent', () => {
164169 const mockEntry = {
165170 ...entry ,
166171 start_date : startMoment . format ( DATE_FORMAT_YEAR ) ,
167- start_hour : startMoment . format ( 'HH:mm' )
172+ start_hour : startMoment . format ( 'HH:mm' ) ,
168173 } ;
169174
170175 component . newData = mockEntry ;
@@ -210,11 +215,9 @@ describe('EntryFieldsComponent', () => {
210215 component . cancelTimeInUpdate ( ) ;
211216
212217 expect ( component . showTimeInbuttons ) . toEqual ( false ) ;
213- expect ( component . entryForm . patchValue ) . toHaveBeenCalledWith (
214- {
215- start_hour : component . newData . start_hour
216- }
217- ) ;
218+ expect ( component . entryForm . patchValue ) . toHaveBeenCalledWith ( {
219+ start_hour : component . newData . start_hour ,
220+ } ) ;
218221 } ) ;
219222
220223 it ( 'should reset to current start_date when start_date has an error' , ( ) => {
@@ -228,11 +231,9 @@ describe('EntryFieldsComponent', () => {
228231 spyOn ( component . entryForm , 'patchValue' ) ;
229232 component . onUpdateStartHour ( ) ;
230233
231- expect ( component . entryForm . patchValue ) . toHaveBeenCalledWith (
232- {
233- start_hour : component . newData . start_hour
234- }
235- ) ;
234+ expect ( component . entryForm . patchValue ) . toHaveBeenCalledWith ( {
235+ start_hour : component . newData . start_hour ,
236+ } ) ;
236237 expect ( component . showTimeInbuttons ) . toEqual ( false ) ;
237238 } ) ;
238239
@@ -244,7 +245,7 @@ describe('EntryFieldsComponent', () => {
244245 const mockEntry = {
245246 ...entry ,
246247 start_date : startMoment . format ( DATE_FORMAT_YEAR ) ,
247- start_hour : startMoment . format ( 'HH:mm' )
248+ start_hour : startMoment . format ( 'HH:mm' ) ,
248249 } ;
249250 component . newData = mockEntry ;
250251 component . activeEntry = mockEntry ;
@@ -256,11 +257,9 @@ describe('EntryFieldsComponent', () => {
256257 spyOn ( component . entryForm , 'patchValue' ) ;
257258 component . onUpdateStartHour ( ) ;
258259
259- expect ( component . entryForm . patchValue ) . toHaveBeenCalledWith (
260- {
261- start_hour : component . newData . start_hour
262- }
263- ) ;
260+ expect ( component . entryForm . patchValue ) . toHaveBeenCalledWith ( {
261+ start_hour : component . newData . start_hour ,
262+ } ) ;
264263 expect ( component . showTimeInbuttons ) . toEqual ( false ) ;
265264 } ) ;
266265
@@ -279,17 +278,20 @@ describe('EntryFieldsComponent', () => {
279278 expect ( component . showTimeInbuttons ) . toEqual ( false ) ;
280279 } ) ;
281280
282- it ( 'When start_time is updated, component.last_entry is equal to time entry in the position 1' , waitForAsync ( ( ) => {
283- component . newData = mockEntryOverlap ;
284- component . activeEntry = entry ;
285- component . setDataToUpdate ( entry ) ;
286- const updatedTime = moment ( mockDate ) . format ( 'HH:mm' ) ;
281+ it (
282+ 'When start_time is updated, component.last_entry is equal to time entry in the position 1' ,
283+ waitForAsync ( ( ) => {
284+ component . newData = mockEntryOverlap ;
285+ component . activeEntry = entry ;
286+ component . setDataToUpdate ( entry ) ;
287+ const updatedTime = moment ( mockDate ) . format ( 'HH:mm' ) ;
287288
288- component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
289- component . onUpdateStartHour ( ) ;
289+ component . entryForm . patchValue ( { start_hour : updatedTime } ) ;
290+ component . onUpdateStartHour ( ) ;
290291
291- expect ( component . lastEntry ) . toBe ( state . entries . timeEntriesDataSource . data [ 1 ] ) ;
292- } ) ) ;
292+ expect ( component . lastEntry ) . toBe ( state . entries . timeEntriesDataSource . data [ 1 ] ) ;
293+ } )
294+ ) ;
293295
294296 it ( 'When start_time is updated for a time entry. UpdateCurrentOrLastEntry action is dispatched' , ( ) => {
295297 component . newData = mockEntryOverlap ;
@@ -310,10 +312,10 @@ describe('EntryFieldsComponent', () => {
310312
311313 component . onTechnologyUpdated ( addedTechnologies ) ;
312314 expect ( store . dispatch ) . toHaveBeenCalled ( ) ;
313-
314315 } ) ;
315316
316317 it ( 'uses the form to check if is valid or not' , ( ) => {
318+ component . activeEntry = entry ;
317319 entryForm . valid = false ;
318320
319321 const result = component . entryFormIsValidate ( ) ;
@@ -339,7 +341,6 @@ describe('EntryFieldsComponent', () => {
339341 expect ( store . dispatch ) . toHaveBeenCalled ( ) ;
340342 } ) ;
341343
342-
343344 it ( 'sets the technologies on the class when entry has technologies' , ( ) => {
344345 const entryData = { ...entry , technologies : [ 'foo' ] } ;
345346
@@ -348,7 +349,6 @@ describe('EntryFieldsComponent', () => {
348349 expect ( component . selectedTechnologies ) . toEqual ( entryData . technologies ) ;
349350 } ) ;
350351
351-
352352 it ( 'activites are populated using the payload of the action' , ( ) => {
353353 const actionSubject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
354354 const action = {
@@ -366,35 +366,35 @@ describe('EntryFieldsComponent', () => {
366366 {
367367 id : '004' ,
368368 name : 'Meeting' ,
369- description : 'Some description'
369+ description : 'Some description' ,
370370 } ,
371371 {
372372 id : '005' ,
373373 name : 'ABCD' ,
374- description : 'Some description'
374+ description : 'Some description' ,
375375 } ,
376376 {
377377 id : '006' ,
378378 name : 'XYZA' ,
379- description : 'Some description'
379+ description : 'Some description' ,
380380 } ,
381381 ] ;
382382
383383 const activitiesOrdered = [
384384 {
385385 id : '005' ,
386386 name : 'ABCD' ,
387- description : 'Some description'
387+ description : 'Some description' ,
388388 } ,
389389 {
390390 id : '004' ,
391391 name : 'Meeting' ,
392- description : 'Some description'
392+ description : 'Some description' ,
393393 } ,
394394 {
395395 id : '006' ,
396396 name : 'XYZA' ,
397- description : 'Some description'
397+ description : 'Some description' ,
398398 } ,
399399 ] ;
400400
@@ -488,17 +488,19 @@ describe('EntryFieldsComponent', () => {
488488 } ) ;
489489
490490 it ( 'when a activity is not register in DB should show activatefocus in select activity' , ( ) => {
491- const activitiesMock = [ {
492- id : 'xyz' ,
493- name : 'test' ,
494- description : 'test1'
495- } ] ;
491+ const activitiesMock = [
492+ {
493+ id : 'xyz' ,
494+ name : 'test' ,
495+ description : 'test1' ,
496+ } ,
497+ ] ;
496498 const data = {
497499 activity_id : 'xyz' ,
498500 description : '' ,
499501 start_date : moment ( ) . format ( DATE_FORMAT_YEAR ) ,
500502 start_hour : moment ( ) . format ( 'HH:mm' ) ,
501- uri : ''
503+ uri : '' ,
502504 } ;
503505 component . activities = activitiesMock ;
504506 component . entryForm . patchValue ( {
@@ -517,6 +519,18 @@ describe('EntryFieldsComponent', () => {
517519 expect ( autofocus ) . toHaveBeenCalled ( ) ;
518520 } ) ;
519521 } ) ;
520- } ) ;
521522
523+ it ( 'should show an error message if description and ticket fields are empty for internal apps' , ( ) => {
524+ spyOn ( toastrServiceStub , 'error' ) ;
525+ const result = component . requiredFieldsForInternalAppExist ( 'ioet' ) ;
526+ expect ( toastrServiceStub . error ) . toHaveBeenCalled ( ) ;
527+ expect ( result ) . toBe ( false ) ;
528+ } ) ;
522529
530+ it ( 'should return true if customer name does not contain ioet ' , ( ) => {
531+ spyOn ( toastrServiceStub , 'error' ) ;
532+ const result = component . requiredFieldsForInternalAppExist ( 'Project Name' ) ;
533+ expect ( toastrServiceStub . error ) . not . toHaveBeenCalled ( ) ;
534+ expect ( result ) . toBe ( true ) ;
535+ } ) ;
536+ } ) ;
0 commit comments