Skip to content

Commit fd6faa8

Browse files
committed
added test file timer component
1 parent b0ff933 commit fd6faa8

File tree

1 file changed

+235
-0
lines changed

1 file changed

+235
-0
lines changed
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
2+
import { By } from '@angular/platform-browser';
3+
import { DebugElement, Component } from '@angular/core';
4+
import { TimeClockComponent } from './time-clock.component';
5+
import { ProjectListHoverComponent } from '../../shared/project-list-hover/project-list-hover.component';
6+
7+
describe('TimeClockComponent', () => {
8+
let component: TimeClockComponent;
9+
let fixture: ComponentFixture<TimeClockComponent>;
10+
let de: DebugElement;
11+
12+
beforeEach(async(() => {
13+
TestBed.configureTestingModule({
14+
declarations: [TimeClockComponent, ProjectListHoverComponent]
15+
}).compileComponents();
16+
}));
17+
18+
beforeEach(() => {
19+
fixture = TestBed.createComponent(TimeClockComponent);
20+
component = fixture.componentInstance;
21+
de = fixture.debugElement;
22+
fixture.detectChanges();
23+
});
24+
25+
it('should be created', () => {
26+
expect(component).toBeTruthy();
27+
});
28+
29+
it('should set showfileds as true', () => {
30+
const show = true;
31+
component.setShowFields(show);
32+
expect(component.showFields).toBe(true);
33+
});
34+
35+
it('should be called the setShowFields event #1', () => {
36+
spyOn(component, 'setShowFields');
37+
const showFields = de.query(By.directive(ProjectListHoverComponent));
38+
const cmp = showFields.componentInstance;
39+
cmp.showFields.emit(true);
40+
expect(component.setShowFields).toHaveBeenCalledWith(true);
41+
});
42+
43+
it('should be called the setShowFields event #2', () => {
44+
spyOn(component, 'setShowFields');
45+
const showFields = de.query(By.directive(ProjectListHoverComponent));
46+
const li = showFields.query(By.css('li'));
47+
li.nativeElement.click();
48+
expect(component.setShowFields).toHaveBeenCalledWith(true);
49+
});
50+
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();
131+
});
132+
133+
it('should enter else and assign the value to var ' , () => {
134+
const dataTechnology = '';
135+
component.enterTechnology(dataTechnology);
136+
expect(component.isEnterTechnology).toBeFalsy();
137+
});
138+
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();
156+
});
157+
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();
174+
});
175+
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();
192+
});
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+
});
233+
});
234+
235+

0 commit comments

Comments
 (0)