@@ -9,12 +9,6 @@ describe('TimeClockComponent', () => {
9
9
let fixture : ComponentFixture < TimeClockComponent > ;
10
10
let de : DebugElement ;
11
11
12
- function setup ( ) {
13
- const fixture = TestBed . createComponent ( TimeClockComponent ) ;
14
- const app = fixture . debugElement . componentInstance ;
15
- return { fixture, app } ;
16
- }
17
-
18
12
beforeEach ( async ( ( ) => {
19
13
TestBed . configureTestingModule ( {
20
14
declarations : [ TimeClockComponent , ProjectListHoverComponent ]
@@ -32,14 +26,6 @@ describe('TimeClockComponent', () => {
32
26
expect ( component ) . toBeTruthy ( ) ;
33
27
} ) ;
34
28
35
- it ( 'should have p tag as \'Dario clocked out at 00:00:00\'' , async ( ( ) => {
36
- const { fixture } = setup ( ) ;
37
- fixture . detectChanges ( ) ;
38
- const compile = fixture . debugElement . nativeElement ;
39
- const ptag = compile . querySelector ( 'p' ) ;
40
- expect ( ptag . textContent ) . toBe ( 'Dario clocked out at 00:00:00' ) ;
41
- } ) ) ;
42
-
43
29
it ( 'should set showfileds as true' , ( ) => {
44
30
const show = true ;
45
31
component . setShowFields ( show ) ;
@@ -62,44 +48,188 @@ describe('TimeClockComponent', () => {
62
48
expect ( component . setShowFields ) . toHaveBeenCalledWith ( true ) ;
63
49
} ) ;
64
50
65
- it ( 'should have button text as Options' , async ( ( ) => {
66
- const { fixture } = setup ( ) ;
67
- fixture . detectChanges ( ) ;
68
- const x = document . getElementById ( 'optionsContainer' ) ;
69
- const ptag = x . querySelector ( 'button' ) ;
70
- expect ( ptag . textContent ) . toBe ( ' Options ' ) ;
71
- } ) ) ;
72
-
73
- it ( 'should set Clock In' , ( ) => {
74
- const { fixture } = setup ( ) ;
75
- fixture . detectChanges ( ) ;
76
- const x = document . getElementById ( 'clockInOutContainer' ) ;
77
- const ptag = x . querySelector ( 'button' ) ;
78
- expect ( ptag . textContent ) . toBe ( 'Clock In' ) ;
51
+ /* ---------------------- EMPLOYE CLOCK IN ------------------------------------- */
52
+ it ( 'should be verify the init state of vars' , ( ) => {
53
+ expect ( component . isClockIn ) . toBeTruthy ( ) ;
54
+ expect ( component . isEnterTechnology ) . toBeFalsy ( ) ;
55
+ expect ( component . showAlertEnterTecnology ) . toBeFalsy ( ) ;
56
+ expect ( component . showFields ) . toBeFalsy ( ) ;
57
+ expect ( component . execOnlyOneTimeCounter ) . toBeFalsy ( ) ;
58
+ expect ( component . execOnlyOneTimeClockIn ) . toBeFalsy ( ) ;
59
+ expect ( component . isClockInEnable ) . toBeFalsy ( ) ;
60
+ expect ( component . isHidenForm ) . toBeTruthy ( ) ;
61
+
62
+ expect ( component . hourCounterRealTime ) . toEqual ( 0 ) ;
63
+ expect ( component . minuteCounterRealTime ) . toEqual ( 0 ) ;
64
+ expect ( component . secondsCounterRealTime ) . toEqual ( 0 ) ;
65
+
66
+ expect ( component . hour ) . toEqual ( 0 ) ;
67
+ expect ( component . minute ) . toEqual ( 0 ) ;
68
+ expect ( component . seconds ) . toEqual ( 0 ) ;
69
+ } ) ;
70
+
71
+ it ( 'should be change state of isClockInEnale, isClockIn, isHidenForm when function is called' , ( ) => {
72
+ component . employeClockIn ( ) ;
73
+ expect ( component . isClockInEnable ) . toBeTruthy ( ) ;
74
+ expect ( component . isClockIn ) . toBeFalsy ( ) ;
75
+ } ) ;
76
+
77
+ it ( 'the function should return false' , ( ) => {
78
+ expect ( component . employeClockIn ( ) ) . toEqual ( false ) ;
79
+ } ) ;
80
+
81
+ it ( 'should be called to intern methods of employeClockIn' , ( ) => {
82
+ spyOn ( component , 'startTimer' ) ;
83
+ spyOn ( component , 'setArrivalAndDepartureTimes' ) ;
84
+
85
+ component . employeClockIn ( ) ;
86
+
87
+ expect ( component . startTimer ) . toHaveBeenCalled ( ) ;
88
+ expect ( component . setArrivalAndDepartureTimes ) . toHaveBeenCalled ( ) ;
89
+ } ) ;
90
+
91
+ /* ---------------------- EMPLOYE CLOCK OUT ------------------------------------- */
92
+ it ( 'should enter if and assign the value to vars' , ( ) => {
93
+ component . isEnterTechnology = false ;
94
+ component . employeClockOut ( ) ;
95
+ expect ( component . isClockIn ) . toBeFalsy ( ) ;
96
+ expect ( component . showAlertEnterTecnology ) . toBeTruthy ( ) ;
97
+ } ) ;
98
+
99
+ it ( 'should enter if and not called to intern methods' , ( ) => {
100
+ component . isEnterTechnology = false ;
101
+ spyOn ( component , 'setDefaultValuesToFields' ) ;
102
+ spyOn ( component , 'pauseTimer' ) ;
103
+ spyOn ( component , 'setArrivalAndDepartureTimes' ) ;
104
+ component . employeClockOut ( ) ;
105
+ expect ( component . setDefaultValuesToFields ) . not . toHaveBeenCalled ( ) ;
106
+ expect ( component . pauseTimer ) . not . toHaveBeenCalled ( ) ;
107
+ expect ( component . setArrivalAndDepartureTimes ) . not . toHaveBeenCalled ( ) ;
108
+
109
+ } ) ;
110
+
111
+ it ( 'should enter else and execute internal methods' , ( ) => {
112
+ component . isEnterTechnology = true ;
113
+
114
+ spyOn ( component , 'setDefaultValuesToFields' ) ;
115
+ spyOn ( component , 'pauseTimer' ) ;
116
+ spyOn ( component , 'setArrivalAndDepartureTimes' ) ;
117
+
118
+ component . employeClockOut ( ) ;
119
+
120
+ expect ( component . setDefaultValuesToFields ) . toHaveBeenCalled ( ) ;
121
+ expect ( component . pauseTimer ) . toHaveBeenCalled ( ) ;
122
+ expect ( component . setArrivalAndDepartureTimes ) . toHaveBeenCalled ( ) ;
123
+
124
+ } ) ;
125
+
126
+ /* ---------------------- ENTER TECHNOLOGY ------------------------------------- */
127
+ it ( 'should enter if and assign the value to var' , ( ) => {
128
+ const dataTechnology = 'Angular' ;
129
+ component . enterTechnology ( dataTechnology ) ;
130
+ expect ( component . isEnterTechnology ) . toBeTruthy ( ) ;
79
131
} ) ;
80
132
81
- it ( 'should setVartToEmpty called' , ( ) => {
82
- spyOn ( component , 'setDefaultValuesToFields' ) ;
83
- component . setDefaultValuesToFields ( ) ;
84
- expect ( component . setDefaultValuesToFields ) . toHaveBeenCalled ( ) ;
133
+ it ( 'should enter else and assign the value to var ' , ( ) => {
134
+ const dataTechnology = '' ;
135
+ component . enterTechnology ( dataTechnology ) ;
136
+ expect ( component . isEnterTechnology ) . toBeFalsy ( ) ;
85
137
} ) ;
86
138
87
- it ( 'should employeClockIn called' , ( ) => {
88
- spyOn ( component , 'employeClockIn' ) ;
89
- component . employeClockIn ( ) ;
90
- expect ( component . employeClockIn ) . toHaveBeenCalled ( ) ;
139
+ /* ---------------------- SET SHOW FIELDS ------------------------------------- */
140
+ it ( 'should execute all internal methods' , ( ) => {
141
+ const show = true ;
142
+ component . isClockInEnable = false ;
143
+ component . execOnlyOneTimeCounter = false ;
144
+
145
+ spyOn ( component , 'startTimer' ) ;
146
+ spyOn ( component , 'setArrivalAndDepartureTimes' ) ;
147
+
148
+ component . setShowFields ( show ) ;
149
+
150
+ expect ( component . isHidenForm ) . toBeFalsy ( ) ;
151
+ expect ( component . isClockIn ) . toBeFalsy ( ) ;
152
+ expect ( component . showFields ) . toEqual ( show ) ;
153
+ expect ( component . startTimer ) . toHaveBeenCalled ( ) ;
154
+ expect ( component . execOnlyOneTimeCounter ) . toBeTruthy ( ) ;
155
+ expect ( component . setArrivalAndDepartureTimes ) . toHaveBeenCalled ( ) ;
91
156
} ) ;
92
157
93
- it ( 'should employeClockOut called' , ( ) => {
94
- spyOn ( component , 'employeClockOut' ) ;
95
- component . employeClockOut ( ) ;
96
- expect ( component . employeClockOut ) . toHaveBeenCalled ( ) ;
158
+ it ( 'should not call nested if internal methods' , ( ) => {
159
+ const show = true ;
160
+ component . isClockInEnable = false ;
161
+ component . execOnlyOneTimeCounter = true ;
162
+
163
+ spyOn ( component , 'startTimer' ) ;
164
+ spyOn ( component , 'setArrivalAndDepartureTimes' ) ;
165
+
166
+ component . setShowFields ( show ) ;
167
+
168
+ expect ( component . isHidenForm ) . toBeFalsy ( ) ;
169
+ expect ( component . isClockIn ) . toBeFalsy ( ) ;
170
+ expect ( component . showFields ) . toEqual ( show ) ;
171
+ expect ( component . startTimer ) . not . toHaveBeenCalled ( ) ;
172
+ expect ( component . execOnlyOneTimeCounter ) . toBeTruthy ( ) ;
173
+ expect ( component . setArrivalAndDepartureTimes ) . toHaveBeenCalled ( ) ;
97
174
} ) ;
98
175
99
- it ( 'should enterTechnolofy called' , ( ) => {
100
- spyOn ( component , 'enterTechnology' ) ;
101
- component . enterTechnology ( '' ) ;
102
- expect ( component . enterTechnology ) . toHaveBeenCalled ( ) ;
176
+ it ( 'shouldn not execute any main if method' , ( ) => {
177
+ const show = true ;
178
+ component . isClockInEnable = true ;
179
+ component . execOnlyOneTimeCounter = true ;
180
+
181
+ spyOn ( component , 'startTimer' ) ;
182
+ spyOn ( component , 'setArrivalAndDepartureTimes' ) ;
183
+
184
+ component . setShowFields ( show ) ;
185
+
186
+ expect ( component . isHidenForm ) . toBeFalsy ( ) ;
187
+ expect ( component . isClockIn ) . toBeTruthy ( ) ;
188
+ expect ( component . showFields ) . toEqual ( undefined ) ;
189
+ expect ( component . startTimer ) . not . toHaveBeenCalled ( ) ;
190
+ expect ( component . execOnlyOneTimeCounter ) . toBeTruthy ( ) ;
191
+ expect ( component . setArrivalAndDepartureTimes ) . not . toHaveBeenCalled ( ) ;
103
192
} ) ;
104
193
194
+ /* ---------------------- TIMER ------------------------------------- */
195
+ it ( 'should be var not equal to zero' , ( ) => {
196
+ component . timer ( ) ;
197
+ expect ( component . secondsCounterRealTime ) . not . toEqual ( 0 ) ;
198
+ } ) ;
199
+
200
+ /* ---------------------- ARRIVALS ------------------------------------- */
201
+ it ( 'should execute intern methods of arrivals' , ( ) => {
202
+ const currentDate = new Date ( ) ;
203
+ component . execOnlyOneTimeClockIn = false ;
204
+ component . setArrivalAndDepartureTimes ( ) ;
205
+ expect ( component . hour ) . toEqual ( currentDate . getHours ( ) ) ;
206
+ expect ( component . minute ) . toEqual ( currentDate . getMinutes ( ) ) ;
207
+ expect ( component . seconds ) . toEqual ( currentDate . getSeconds ( ) ) ;
208
+ expect ( component . execOnlyOneTimeClockIn ) . toEqual ( true ) ;
209
+
210
+ } ) ;
211
+
212
+ it ( 'should not execute intern methods of arrivals' , ( ) => {
213
+ component . execOnlyOneTimeClockIn = true ;
214
+ component . setArrivalAndDepartureTimes ( ) ;
215
+ expect ( component . hour ) . toEqual ( 0 ) ;
216
+ expect ( component . minute ) . toEqual ( 0 ) ;
217
+ expect ( component . seconds ) . toEqual ( 0 ) ;
218
+ expect ( component . execOnlyOneTimeClockIn ) . toEqual ( true ) ;
219
+ } ) ;
220
+
221
+ /* ---------------------- DEFAULT FIELDS ------------------------------------- */
222
+ it ( 'set values to empty' , ( ) => {
223
+ component . setDefaultValuesToFields ( ) ;
224
+ expect ( component . isHidenForm ) . toBeTruthy ( ) ;
225
+ expect ( component . isClockIn ) . toBeTruthy ( ) ;
226
+ expect ( component . isEnterTechnology ) . toBeFalsy ( ) ;
227
+ expect ( component . showAlertEnterTecnology ) . toBeFalsy ( ) ;
228
+ expect ( component . execOnlyOneTimeClockIn ) . toBeFalsy ( ) ;
229
+ expect ( component . execOnlyOneTimeCounter ) . toBeFalsy ( ) ;
230
+ expect ( component . isClockInEnable ) . toBeFalsy ( ) ;
231
+
232
+ } ) ;
105
233
} ) ;
234
+
235
+
0 commit comments