Skip to content

Commit 58afe14

Browse files
committed
added test
1 parent e6e4e9a commit 58afe14

File tree

2 files changed

+55
-40
lines changed

2 files changed

+55
-40
lines changed

src/app/components/options-sidebar/time-clock/time-clock.component.spec.ts

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ describe('TimeClockComponent', () => {
99
let fixture: ComponentFixture<TimeClockComponent>;
1010
let de: DebugElement;
1111

12-
function setup() {
13-
const fixture = TestBed.createComponent(TimeClockComponent);
14-
const app = fixture.debugElement.componentInstance;
15-
return { fixture, app };
16-
}
17-
1812
beforeEach(async(() => {
1913
TestBed.configureTestingModule({
2014
declarations: [TimeClockComponent, ProjectListHoverComponent]
@@ -32,14 +26,6 @@ describe('TimeClockComponent', () => {
3226
expect(component).toBeTruthy();
3327
});
3428

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-
4329
it('should set showfileds as true', () => {
4430
const show = true;
4531
component.setShowFields(show);
@@ -62,33 +48,67 @@ describe('TimeClockComponent', () => {
6248
expect(component.setShowFields).toHaveBeenCalledWith(true);
6349
});
6450

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-
}));
51+
it('should internt methods employeClockIn called', () => {
52+
spyOn(component, 'startTimer');
53+
spyOn(component, 'setArrivalAndDepartureTimes');
54+
55+
component.employeClockIn();
56+
expect(component.startTimer).toHaveBeenCalled();
57+
expect(component.setArrivalAndDepartureTimes).toHaveBeenCalled();
7258

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');
7959
});
8060

61+
it('called intern method setArrivalAndDepartureTimes', () => {
62+
const show = true;
63+
64+
component.isClockInEnable = false;
65+
component.execOnlyOneTimeCounter = true;
66+
67+
spyOn(component, 'setArrivalAndDepartureTimes');
68+
spyOn(component, 'startTimer');
69+
component.setShowFields(show);
70+
71+
expect(component.showFields).toBe(true);
72+
expect(component.setArrivalAndDepartureTimes).toHaveBeenCalled();
73+
expect(component.startTimer).not.toHaveBeenCalled();
74+
});
75+
76+
it('called intern methods of employeClockOut ', () => {
77+
component.isEnterTechnology = true;
78+
79+
spyOn(component, 'setDefaultValuesToFields');
80+
spyOn(component, 'pauseTimer');
81+
spyOn(component, 'setArrivalAndDepartureTimes');
82+
83+
component.employeClockOut();
84+
85+
expect(component.setArrivalAndDepartureTimes).toHaveBeenCalled();
86+
expect(component.pauseTimer).toHaveBeenCalled();
87+
expect(component.setArrivalAndDepartureTimes).toHaveBeenCalled();
88+
});
89+
90+
91+
it('not called intern methods of employeClockOut ', () => {
92+
component.isEnterTechnology = false;
93+
94+
spyOn(component, 'setDefaultValuesToFields');
95+
spyOn(component, 'pauseTimer');
96+
spyOn(component, 'setArrivalAndDepartureTimes');
97+
98+
component.employeClockOut();
99+
100+
expect(component.setArrivalAndDepartureTimes).not.toHaveBeenCalled();
101+
expect(component.pauseTimer).not.toHaveBeenCalled();
102+
expect(component.setArrivalAndDepartureTimes).not.toHaveBeenCalled();
103+
});
104+
105+
81106
it('should setVartToEmpty called', () => {
82107
spyOn(component, 'setDefaultValuesToFields');
83108
component.setDefaultValuesToFields();
84109
expect(component.setDefaultValuesToFields).toHaveBeenCalled();
85110
});
86111

87-
it('should employeClockIn called', () => {
88-
spyOn(component, 'employeClockIn');
89-
component.employeClockIn();
90-
expect(component.employeClockIn).toHaveBeenCalled();
91-
});
92112

93113
it('should employeClockOut called', () => {
94114
spyOn(component, 'employeClockOut');
@@ -103,3 +123,5 @@ describe('TimeClockComponent', () => {
103123
});
104124

105125
});
126+
127+

src/app/components/shared/clock/clock.component.spec.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { ClockComponent } from './clock.component';
4-
import { interval, timer } from 'rxjs';
4+
import { interval, timer, of } from 'rxjs';
55

66
describe('ClockComponent', () => {
77
let component: ClockComponent;
88
let fixture: ComponentFixture<ClockComponent>;
99

10-
function setup() {
11-
// tslint:disable-next-line: no-shadowed-variable
12-
const fixture = TestBed.createComponent(ClockComponent);
13-
const app = fixture.debugElement.componentInstance;
14-
return { fixture, app };
15-
}
16-
1710
beforeEach(async(() => {
1811
TestBed.configureTestingModule({
1912
declarations: [ ClockComponent ]

0 commit comments

Comments
 (0)