Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added test for clock
  • Loading branch information
daros10 committed Mar 17, 2020
commit ec2d162081c491ac91efa2af4cd3cdfd721ef694
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { interval, timer } from 'rxjs';


@Component({
selector: 'app-time-clock',
Expand All @@ -15,13 +13,10 @@ export class TimeClockComponent implements OnInit {
isClockIn: boolean;
isEnterTechnology: boolean;
showAlertEnterTecnology: boolean;

hour: number;
minute: number;
seconds: number;

public timer;

constructor() {
this.isClockIn = true;
this.isEnterTechnology = false;
Expand All @@ -32,7 +27,6 @@ export class TimeClockComponent implements OnInit {

employeClockIn(): boolean {
this.isClockIn = !this.isClockIn;
this.enableTimer();
return this.isClockIn;
}

Expand All @@ -44,7 +38,6 @@ export class TimeClockComponent implements OnInit {
this.isClockIn = true;
this.isEnterTechnology = false;
this.showAlertEnterTecnology = false;
console.log('Disble Timer');
}
}

Expand All @@ -56,26 +49,7 @@ export class TimeClockComponent implements OnInit {
}
}

enableTimer() {
this.timer = interval(1000);
this.timer.subscribe( (data) => {
this.seconds += 1;
if ( this.seconds === 59 ) {
this.minute += 1;
this.seconds = 0;
if ( this.minute === 59 ) {
this.hour += 1;
this.minute = 0;
}
}
// console.log(this.hour + ' : ' + this.minute + ' : ' + this.seconds);
});

}


ngOnInit(): void {
}


}
12 changes: 12 additions & 0 deletions src/app/components/shared/clock/clock.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('ClockComponent', () => {
let component: ClockComponent;
let fixture: ComponentFixture<ClockComponent>;


beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ClockComponent ]
Expand All @@ -22,4 +23,15 @@ describe('ClockComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should show the current hour of day', () => {
const currentHour = 11;
expect(component.currentDate.getHours()).toEqual(currentHour);
});

it('should show the current minutes of day', () => {
const currenMinutes = 5;
expect(component.currentDate.getMinutes()).toEqual(currenMinutes);
});

});
8 changes: 4 additions & 4 deletions src/app/components/shared/clock/clock.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { interval, timer } from 'rxjs';
})
export class ClockComponent implements OnInit {

currentDate: Date;
currentDate: Date = new Date();
hour: number;
minutes: number;
seconds: number;
Expand All @@ -23,13 +23,13 @@ export class ClockComponent implements OnInit {
}

showClcok() {
const timer = interval(1000);
timer.subscribe( (data) => {
const timenInterval = interval(1000);
timenInterval.subscribe( (data) => {
this.currentDate = new Date();
this.hour = this.currentDate.getHours();
this.minutes = this.currentDate.getMinutes();
this.seconds = this.currentDate.getSeconds();
} );
});
}

ngOnInit(): void {
Expand Down