Skip to content

Commit 1197078

Browse files
committed
reafactor code and names
1 parent 9b86107 commit 1197078

File tree

6 files changed

+108
-64
lines changed

6 files changed

+108
-64
lines changed

src/app/components/options-sidebar/time-clock/time-clock.component.css

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,4 @@
77
display: flex;
88
height: 100%;
99
justify-content: center;
10-
}
11-
12-
.place-holder-danger::-webkit-input-placeholder {
13-
/* WebKit, Blink, Edge */
14-
color: #909;
15-
}
16-
17-
.place-holder-danger:-moz-placeholder {
18-
/* Mozilla Firefox 4 to 18 */
19-
color: #909;
20-
opacity: 1;
21-
}
22-
23-
.placeholder-danger::-moz-placeholder {
24-
/* Mozilla Firefox 19+ */
25-
color: #DC3545 !important;
26-
opacity: 1;
27-
}
28-
29-
.placeholder-danger:-ms-input-placeholder {
30-
/* Internet Explorer 10-11 */
31-
color: #DC3545 !important;
32-
}
33-
34-
.placeholder-danger::-ms-input-placeholder {
35-
/* Microsoft Edge */
36-
color: #DC3545 !important;
37-
}
38-
39-
.placeholder-danger::placeholder {
40-
/* Most modern browsers support this now. */
41-
color: #DC3545 !important;
4210
}

src/app/components/options-sidebar/time-clock/time-clock.component.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ <h3>{{ hourCounterRealTime | number: '2.0-2' }}:{{ minuteCounterRealTime | numbe
2323
</div>
2424
<div class="col-4">
2525
<h6>Day</h6>
26-
<h3>4:22</h3>
26+
<h3>00:00</h3>
2727
</div>
2828
<div class="col-4">
2929
<h6>Week</h6>
30-
<h3>14:00</h3>
30+
<h3>00:00</h3>
3131
</div>
3232
</div>
3333
<h6 class="text-left"><strong>Projects</strong></h6>
@@ -41,7 +41,7 @@ <h6 class="text-left"><strong>Projects</strong></h6>
4141
<app-project-list-hover [projects]="projects" (showFields)="setShowFields($event)"></app-project-list-hover>
4242
</ul>
4343
<br>
44-
<form *ngIf="!isClockIn || showFields">
44+
<form *ngIf="(!isClockIn || showFields) && !isHidenForm">
4545
<div class="form-group row">
4646
<label for="inputActivity" class="col-sm-2 col-form-label text-center"><strong>Activity</strong></label>
4747
<div class="col-sm-10">
@@ -58,19 +58,22 @@ <h6 class="text-left"><strong>Projects</strong></h6>
5858
<label for="inputTechnology" class="col-sm-2 col-form-label text-center"><strong>Technology</strong></label>
5959
<div class="col-sm-10">
6060
<input *ngIf="!showAlertEnterTecnology" #data type="text" (keyup)="enterTechnology(data.value)" class="form-control">
61-
<input *ngIf="showAlertEnterTecnology" #data type="text" (keyup)="enterTechnology(data.value)" class="form-control border-danger placeholder-danger " placeholder="Field technology is required. Enter this field for clock out.">
61+
<input *ngIf="showAlertEnterTecnology" #data type="text" (keyup)="enterTechnology(data.value)" class="form-control border-danger">
62+
<div class="">
63+
<h6 *ngIf="showAlertEnterTecnology" class="text-danger text-left">Technology field is required. Enter this field to clock out.</h6>
64+
</div>
6265
</div>
6366
</div>
6467
</form>
6568
<hr>
6669
<div class="container">
6770
<div class="row">
68-
<div class="col text-left">
71+
<div class="col text-left" id="optionsContainer">
6972
<button class="btn btn-light btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
7073
Options
7174
</button>
7275
</div>
73-
<div class="col text-right">
76+
<div class="col text-right" id="clockInOutContainer">
7477
<button *ngIf="isClockIn" class="btn btn-success btn-sm" type="button" (click)="employeClockIn()">Clock In</button>
7578
<button *ngIf="!isClockIn" class="btn btn-danger btn-sm" type="button" (click)="employeClockOut()">Clock Out</button>
7679
</div>

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

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
1+
import { async, ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
22
import { By } from '@angular/platform-browser';
3-
import { DebugElement } from '@angular/core';
3+
import { DebugElement, Component } from '@angular/core';
44
import { TimeClockComponent } from './time-clock.component';
55
import { ProjectListHoverComponent } from '../../shared/project-list-hover/project-list-hover.component';
66

@@ -10,7 +10,6 @@ describe('TimeClockComponent', () => {
1010
let de: DebugElement;
1111

1212
function setup() {
13-
// tslint:disable-next-line: no-shadowed-variable
1413
const fixture = TestBed.createComponent(TimeClockComponent);
1514
const app = fixture.debugElement.componentInstance;
1615
return { fixture, app };
@@ -34,8 +33,7 @@ describe('TimeClockComponent', () => {
3433
});
3534

3635
it('should have p tag as \'Dario clocked out at 00:00:00\'', async(() => {
37-
// tslint:disable-next-line: no-shadowed-variable
38-
const { app, fixture } = setup();
36+
const { fixture } = setup();
3937
fixture.detectChanges();
4038
const compile = fixture.debugElement.nativeElement;
4139
const ptag = compile.querySelector('p');
@@ -63,4 +61,68 @@ describe('TimeClockComponent', () => {
6361
li.nativeElement.click();
6462
expect(component.setShowFields).toHaveBeenCalledWith(true);
6563
});
64+
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');
79+
});
80+
81+
it('should setVartToEmpty called', () => {
82+
spyOn(component, 'setDefaultValuesToFields');
83+
component.setDefaultValuesToFields();
84+
expect(component.setDefaultValuesToFields).toHaveBeenCalled();
85+
});
86+
87+
it('should employeClockIn called', () => {
88+
spyOn(component, 'employeClockIn');
89+
component.employeClockIn();
90+
expect(component.employeClockIn).toHaveBeenCalled();
91+
});
92+
93+
it('should employeClockOut called', () => {
94+
spyOn(component, 'employeClockOut');
95+
component.employeClockOut();
96+
expect(component.employeClockOut).toHaveBeenCalled();
97+
});
98+
99+
it('should enterTechnolofy called', () => {
100+
spyOn(component, 'enterTechnology');
101+
component.enterTechnology('');
102+
expect(component.enterTechnology).toHaveBeenCalled();
103+
});
104+
105+
// it('show init state of vars', () => {
106+
// spyOn(component, 'employeClockIn');
107+
// const isClockIn = true;
108+
// const isEnterTechnology = false;
109+
// const hourCounterRealTime = 0;
110+
// const minuteCounterRealTime = 0;
111+
// const secondsCounterRealTime = 0;
112+
// const hour = 0;
113+
// const minute = 0;
114+
// const seconds = 0;
115+
// expect(component.isClockIn).toBe(isClockIn);
116+
// expect(component.isEnterTechnology).toBe(isEnterTechnology);
117+
// expect(component.hourCounterRealTime).toBe(hourCounterRealTime);
118+
// expect(component.minuteCounterRealTime).toBe(minuteCounterRealTime);
119+
// expect(component.secondsCounterRealTime).toBe(secondsCounterRealTime);
120+
// expect(component.hour).toBe(hour);
121+
// expect(component.minute).toBe(minute);
122+
// expect(component.seconds).toBe(hour);
123+
// });
124+
125+
126+
127+
66128
});

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ export class TimeClockComponent implements OnInit {
2828
minute: number;
2929
seconds: number;
3030
interval;
31-
dataTechnology: string;
32-
execOnlyOneTimeCounter = 0;
33-
execOnlyOneTimeClockIn = 0;
31+
dataTechnology: string[] = new Array();
32+
execOnlyOneTimeCounter = false;
33+
execOnlyOneTimeClockIn = false;
3434
isClockInEnable = false;
35+
isHidenForm = true;
3536

3637
constructor() {
3738
this.isClockIn = true;
@@ -47,8 +48,9 @@ export class TimeClockComponent implements OnInit {
4748
employeClockIn(): boolean {
4849
this.isClockInEnable = true;
4950
this.isClockIn = !this.isClockIn;
51+
this.isHidenForm = false;
5052
this.startTimer();
51-
this.setTimeToInOut();
53+
this.setArrivalAndDepartureTimes();
5254
return this.isClockIn;
5355
}
5456

@@ -57,15 +59,13 @@ export class TimeClockComponent implements OnInit {
5759
this.isClockIn = false;
5860
this.showAlertEnterTecnology = true;
5961
} else {
60-
this.setVarToEmpty();
62+
this.setDefaultValuesToFields();
6163
this.pauseTimer();
62-
this.setTimeToInOut();
63-
64+
this.setArrivalAndDepartureTimes();
6465
}
6566
}
6667

6768
enterTechnology(data: string) {
68-
this.dataTechnology = data;
6969
if ( data.length > 0 ) {
7070
this.isEnterTechnology = true;
7171
} else {
@@ -74,14 +74,15 @@ export class TimeClockComponent implements OnInit {
7474
}
7575

7676
setShowFields(show: boolean) {
77+
this.isHidenForm = false;
7778
if ( this.isClockInEnable !== true ) {
7879
this.isClockIn = false;
7980
this.showFields = show;
80-
if ( this.execOnlyOneTimeCounter === 0 ) {
81+
if ( !this.execOnlyOneTimeCounter ) {
8182
this.startTimer();
82-
this.execOnlyOneTimeCounter++;
83+
this.execOnlyOneTimeCounter = true;
8384
}
84-
this.setTimeToInOut();
85+
this.setArrivalAndDepartureTimes();
8586
}
8687
}
8788

@@ -107,27 +108,28 @@ export class TimeClockComponent implements OnInit {
107108
}
108109
}
109110

110-
setTimeToInOut() {
111-
if ( this.execOnlyOneTimeClockIn === 0 ) {
111+
setArrivalAndDepartureTimes() {
112+
if ( !this.execOnlyOneTimeClockIn ) {
112113
this.currentDate = new Date();
113114
this.hour = this.currentDate.getHours();
114115
this.minute = this.currentDate.getMinutes();
115116
this.seconds = this.currentDate.getSeconds();
116-
this.execOnlyOneTimeClockIn++;
117+
this.execOnlyOneTimeClockIn = true;
117118
}
118119

119120
}
120121

121-
setVarToEmpty() {
122-
this.dataTechnology = '';
122+
setDefaultValuesToFields() {
123+
this.isHidenForm = true;
123124
this.isClockIn = true;
124125
this.isEnterTechnology = false;
125126
this.showAlertEnterTecnology = false;
126-
this.execOnlyOneTimeClockIn = 0;
127-
this.execOnlyOneTimeCounter = 0;
127+
this.execOnlyOneTimeClockIn = false;
128+
this.execOnlyOneTimeCounter = false;
128129
this.isClockInEnable = false;
129130
}
130131

131-
ngOnInit(): void {}
132+
ngOnInit(): void {
133+
}
132134

133135
}

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

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

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

56
describe('ClockComponent', () => {
67
let component: ClockComponent;
78
let fixture: ComponentFixture<ClockComponent>;
89

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+
917
beforeEach(async(() => {
1018
TestBed.configureTestingModule({
1119
declarations: [ ClockComponent ]
@@ -38,4 +46,5 @@ describe('ClockComponent', () => {
3846
expect(component.currentDate.getSeconds()).toEqual(currentDate.getSeconds());
3947
});
4048

49+
4150
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ export class ClockComponent implements OnInit {
1515
displayTime: boolean;
1616

1717
constructor() {
18-
this.showClcok();
18+
this.showClock();
1919
this.displayTime = false;
2020
setTimeout(() => {
2121
this.displayTime = true;
2222
}, 3000);
2323
}
2424

25-
showClcok() {
25+
showClock() {
2626
const timenInterval = interval(1000);
2727
timenInterval.subscribe( (data) => {
2828
this.currentDate = new Date();

0 commit comments

Comments
 (0)