Skip to content

Commit ec2d162

Browse files
committed
added test for clock
1 parent 65b5195 commit ec2d162

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed
Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { Component, OnInit, OnDestroy } from '@angular/core';
2-
import { interval, timer } from 'rxjs';
3-
42

53
@Component({
64
selector: 'app-time-clock',
@@ -15,13 +13,10 @@ export class TimeClockComponent implements OnInit {
1513
isClockIn: boolean;
1614
isEnterTechnology: boolean;
1715
showAlertEnterTecnology: boolean;
18-
1916
hour: number;
2017
minute: number;
2118
seconds: number;
2219

23-
public timer;
24-
2520
constructor() {
2621
this.isClockIn = true;
2722
this.isEnterTechnology = false;
@@ -32,7 +27,6 @@ export class TimeClockComponent implements OnInit {
3227

3328
employeClockIn(): boolean {
3429
this.isClockIn = !this.isClockIn;
35-
this.enableTimer();
3630
return this.isClockIn;
3731
}
3832

@@ -44,7 +38,6 @@ export class TimeClockComponent implements OnInit {
4438
this.isClockIn = true;
4539
this.isEnterTechnology = false;
4640
this.showAlertEnterTecnology = false;
47-
console.log('Disble Timer');
4841
}
4942
}
5043

@@ -56,26 +49,7 @@ export class TimeClockComponent implements OnInit {
5649
}
5750
}
5851

59-
enableTimer() {
60-
this.timer = interval(1000);
61-
this.timer.subscribe( (data) => {
62-
this.seconds += 1;
63-
if ( this.seconds === 59 ) {
64-
this.minute += 1;
65-
this.seconds = 0;
66-
if ( this.minute === 59 ) {
67-
this.hour += 1;
68-
this.minute = 0;
69-
}
70-
}
71-
// console.log(this.hour + ' : ' + this.minute + ' : ' + this.seconds);
72-
});
73-
74-
}
75-
76-
7752
ngOnInit(): void {
7853
}
7954

80-
8155
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe('ClockComponent', () => {
66
let component: ClockComponent;
77
let fixture: ComponentFixture<ClockComponent>;
88

9+
910
beforeEach(async(() => {
1011
TestBed.configureTestingModule({
1112
declarations: [ ClockComponent ]
@@ -22,4 +23,15 @@ describe('ClockComponent', () => {
2223
it('should create', () => {
2324
expect(component).toBeTruthy();
2425
});
26+
27+
it('should show the current hour of day', () => {
28+
const currentHour = 11;
29+
expect(component.currentDate.getHours()).toEqual(currentHour);
30+
});
31+
32+
it('should show the current minutes of day', () => {
33+
const currenMinutes = 5;
34+
expect(component.currentDate.getMinutes()).toEqual(currenMinutes);
35+
});
36+
2537
});

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { interval, timer } from 'rxjs';
88
})
99
export class ClockComponent implements OnInit {
1010

11-
currentDate: Date;
11+
currentDate: Date = new Date();
1212
hour: number;
1313
minutes: number;
1414
seconds: number;
@@ -23,13 +23,13 @@ export class ClockComponent implements OnInit {
2323
}
2424

2525
showClcok() {
26-
const timer = interval(1000);
27-
timer.subscribe( (data) => {
26+
const timenInterval = interval(1000);
27+
timenInterval.subscribe( (data) => {
2828
this.currentDate = new Date();
2929
this.hour = this.currentDate.getHours();
3030
this.minutes = this.currentDate.getMinutes();
3131
this.seconds = this.currentDate.getSeconds();
32-
} );
32+
});
3333
}
3434

3535
ngOnInit(): void {

0 commit comments

Comments
 (0)