@@ -49,6 +49,18 @@ describe('PoPageJobSchedulerExecutionComponent:', () => {
49
49
expectPropertiesValues ( component , 'value' , validValues , validValues ) ;
50
50
} ) ;
51
51
52
+ it ( 'value: should set `containsFrequency` with true if value.frequency.value' , ( ) => {
53
+ component . value = { frequency : { value : 2 } } ;
54
+
55
+ expect ( component . containsFrequency ) . toBeTrue ( ) ;
56
+ } ) ;
57
+
58
+ it ( 'value: should set `containsFrequency` with false if value.frequency.value is undefined' , ( ) => {
59
+ component . value = { frequency : undefined } ;
60
+
61
+ expect ( component . containsFrequency ) . toBeFalse ( ) ;
62
+ } ) ;
63
+
52
64
it ( 'startDateFirstExecution: should return `Date` if `isEdit` is false' , ( ) => {
53
65
component . isEdit = false ;
54
66
@@ -61,6 +73,30 @@ describe('PoPageJobSchedulerExecutionComponent:', () => {
61
73
expect ( component . startDateFirstExecution instanceof Date ) . toBe ( false ) ;
62
74
expect ( component . startDateFirstExecution ) . toBeUndefined ( ) ;
63
75
} ) ;
76
+
77
+ it ( 'hourLabel: should return `literals.startTime` if `containsFrequency`' , ( ) => {
78
+ component . containsFrequency = true ;
79
+ const result = component . hourLabel ;
80
+ expect ( result ) . toEqual ( component . literals . startTime ) ;
81
+ } ) ;
82
+
83
+ it ( 'hourLabel: should return `literals.time` if `containsFrequency` is false' , ( ) => {
84
+ component . containsFrequency = false ;
85
+ const result = component . hourLabel ;
86
+ expect ( result ) . toEqual ( component . literals . time ) ;
87
+ } ) ;
88
+
89
+ it ( 'dayLabel: should return `literals.startDay` if `containsFrequency`' , ( ) => {
90
+ component . containsFrequency = true ;
91
+ const result = component . dayLabel ;
92
+ expect ( result ) . toEqual ( component . literals . startDay ) ;
93
+ } ) ;
94
+
95
+ it ( 'dayLabel: should return `literals.day` if `containsFrequency` is false' , ( ) => {
96
+ component . containsFrequency = false ;
97
+ const result = component . dayLabel ;
98
+ expect ( result ) . toEqual ( component . literals . day ) ;
99
+ } ) ;
64
100
} ) ;
65
101
66
102
describe ( 'Methods:' , ( ) => {
@@ -74,24 +110,58 @@ describe('PoPageJobSchedulerExecutionComponent:', () => {
74
110
expect ( component [ 'subscribeProcessIdValueChanges' ] ) . toHaveBeenCalled ( ) ;
75
111
} ) ) ;
76
112
113
+ it ( 'ngAfterViewInit: should update `frequencyOption.disabled` if `frequencyOption.value` is equal to `day`' , fakeAsync ( ( ) => {
114
+ component . value . periodicity = 'daily' ;
115
+ component . frequencyOptions = [
116
+ { label : 'Day' , value : 'day' } ,
117
+ { label : 'Hour' , value : 'hour' } ,
118
+ { label : 'minute' , value : 'minute' }
119
+ ] ;
120
+ const expectedValue = [
121
+ { label : 'Day' , value : 'day' , disabled : true } ,
122
+ { label : 'Hour' , value : 'hour' , disabled : false } ,
123
+ { label : 'minute' , value : 'minute' , disabled : false }
124
+ ] ;
125
+
126
+ component . ngAfterViewInit ( ) ;
127
+
128
+ tick ( 50 ) ;
129
+
130
+ expect ( component . frequencyOptions ) . toEqual ( expectedValue ) ;
131
+ } ) ) ;
132
+
77
133
it ( 'ngOnInit: should call `checkExistsProcessesAPI` and set `periodicityTemplates`, `periodicityOptions` and `weekDays`' , ( ) => {
78
134
component . periodicityTemplates = undefined ;
79
135
component . periodicityOptions = undefined ;
136
+ component . frequencyOptions = undefined ;
80
137
component . weekDays = undefined ;
81
138
82
139
spyOn ( component , < any > 'checkExistsProcessesAPI' ) ;
83
140
spyOn ( component , < any > 'getPeriodicityOptions' ) . and . callThrough ( ) ;
84
141
spyOn ( component , < any > 'getWeekDays' ) . and . callThrough ( ) ;
142
+ spyOn ( component , < any > 'getFrequencyOptions' ) . and . callThrough ( ) ;
85
143
86
144
component . ngOnInit ( ) ;
87
145
88
146
expect ( typeof component . periodicityTemplates === 'object' ) . toBe ( true ) ;
89
147
expect ( component . periodicityOptions instanceof Array ) . toBe ( true ) ;
90
148
expect ( component . weekDays instanceof Array ) . toBe ( true ) ;
149
+ expect ( component . frequencyOptions instanceof Array ) . toBe ( true ) ;
91
150
92
151
expect ( component [ 'checkExistsProcessesAPI' ] ) . toHaveBeenCalled ( ) ;
93
152
expect ( component [ 'getPeriodicityOptions' ] ) . toHaveBeenCalled ( ) ;
94
153
expect ( component [ 'getWeekDays' ] ) . toHaveBeenCalled ( ) ;
154
+ expect ( component [ 'getFrequencyOptions' ] ) . toHaveBeenCalled ( ) ;
155
+ } ) ;
156
+
157
+ it ( 'ngOnInit: shouldn`t call `checkExistsProcessesAPI` if `noParameters` is false' , ( ) => {
158
+ component . noParameters = false ;
159
+
160
+ spyOn ( component , < any > 'checkExistsProcessesAPI' ) ;
161
+
162
+ component . ngOnInit ( ) ;
163
+
164
+ expect ( component [ 'checkExistsProcessesAPI' ] ) . not . toHaveBeenCalled ( ) ;
95
165
} ) ;
96
166
97
167
it ( 'checkExistsProcessesAPI: should subscribe `getHeadProcesses` and on error set `existProcessAPI` to false' , ( ) => {
@@ -126,6 +196,15 @@ describe('PoPageJobSchedulerExecutionComponent:', () => {
126
196
expect ( weekDays . length ) . toBe ( weekDaysLength ) ;
127
197
} ) ;
128
198
199
+ it ( 'getFrequencyOptions: should return 3 options' , ( ) => {
200
+ const frequencyOptionsLength = 3 ;
201
+
202
+ const frequencyOptions = component [ 'getFrequencyOptions' ] ( ) ;
203
+
204
+ expect ( frequencyOptions instanceof Array ) . toBe ( true ) ;
205
+ expect ( frequencyOptions . length ) . toBe ( frequencyOptionsLength ) ;
206
+ } ) ;
207
+
129
208
it ( 'subscribeProcessIdValueChanges: should call `changeProcess.emit` when subscribe `processID.valueChanges`' , ( ) => {
130
209
const processId = 1 ;
131
210
component [ 'form' ] = < any > {
@@ -144,6 +223,60 @@ describe('PoPageJobSchedulerExecutionComponent:', () => {
144
223
expect ( component [ 'form' ] . controls . processID . valueChanges . subscribe ) . toHaveBeenCalled ( ) ;
145
224
expect ( component . changeProcess . emit ) . toHaveBeenCalledWith ( { processId, existAPI : component . existProcessAPI } ) ;
146
225
} ) ;
226
+
227
+ it ( 'changeContainsFrequency: should update `value.frequency` if `containsfrequency`' , ( ) => {
228
+ const containsFrequency = true ;
229
+ const expectedValue = { type : 'hour' , value : null } ;
230
+
231
+ component . onChangeContainsFrequency ( containsFrequency ) ;
232
+
233
+ expect ( component . value . frequency ) . toEqual ( expectedValue ) ;
234
+ } ) ;
235
+
236
+ it ( 'changeContainsFrequency: should update `value.frequency` with empty object if `containsfrequency` is false' , ( ) => {
237
+ const containsFrequency = false ;
238
+ const expectedValue = { } ;
239
+
240
+ component . onChangeContainsFrequency ( containsFrequency ) ;
241
+
242
+ expect ( component . value . frequency ) . toEqual ( expectedValue ) ;
243
+ } ) ;
244
+
245
+ it ( 'changeContainsFrequency: should update `value.rangeLimitHour`, `value.rangeLimitDay` and `value.dayOfMonth` with null' , ( ) => {
246
+ const containsFrequency = false ;
247
+
248
+ component . onChangeContainsFrequency ( containsFrequency ) ;
249
+
250
+ expect ( component . value . rangeLimitHour ) . toBeNull ( ) ;
251
+ expect ( component . value . rangeLimitDay ) . toBeNull ( ) ;
252
+ expect ( component . value . dayOfMonth ) . toBeNull ( ) ;
253
+ } ) ;
254
+
255
+ it ( 'onChangePeriodicityOptions: should update `frequencyOptions` and `value.frequency.type`' , ( ) => {
256
+ const periodicity = 'daily' ;
257
+ component . value . frequency = { } ;
258
+ component . frequencyOptions = [
259
+ { label : 'Day' , value : 'day' } ,
260
+ { label : 'Hour' , value : 'hour' } ,
261
+ { label : 'minute' , value : 'minute' }
262
+ ] ;
263
+ const expectedValue = [
264
+ { label : 'Day' , value : 'day' , disabled : true } ,
265
+ { label : 'Hour' , value : 'hour' , disabled : false } ,
266
+ { label : 'minute' , value : 'minute' , disabled : false }
267
+ ] ;
268
+
269
+ component . onChangePeriodicityOptions ( periodicity ) ;
270
+
271
+ expect ( component . frequencyOptions ) . toEqual ( expectedValue ) ;
272
+ expect ( component . value . frequency . type ) . toBeNull ( ) ;
273
+ } ) ;
274
+
275
+ it ( 'onChangeFrequencyOptions: should update `value.rangeLimitHour` with `null`' , ( ) => {
276
+ component . onChangeFrequencyOptions ( ) ;
277
+
278
+ expect ( component . value . rangeLimitHour ) . toBeNull ( ) ;
279
+ } ) ;
147
280
} ) ;
148
281
149
282
describe ( 'Templates:' , ( ) => {
0 commit comments