Skip to content

Commit f4304fe

Browse files
committed
#3 added project service in list
1 parent 6defa24 commit f4304fe

File tree

12 files changed

+183
-111
lines changed

12 files changed

+183
-111
lines changed

src/app/app.module.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { BrowserModule } from '@angular/platform-browser';
33
import { NgModule } from '@angular/core';
44
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
55
import { HttpClientModule } from '@angular/common/http';
6-
76
import { AppRoutingModule } from './app-routing.module';
87
import { AppComponent } from './app.component';
98
import { NavbarComponent } from './modules/shared/components/navbar/navbar.component';
@@ -27,7 +26,6 @@ import { CreateActivityComponent } from './modules/activities-management/compone
2726
import { FilterProjectPipe } from './modules/shared/pipes/filter-project/filter-project.pipe';
2827
import { SearchProjectComponent } from './modules/shared/components/search-project/search-project.component';
2928

30-
3129
@NgModule({
3230
declarations: [
3331
AppComponent,
@@ -51,7 +49,7 @@ import { SearchProjectComponent } from './modules/shared/components/search-proje
5149
CreateActivityComponent,
5250
ActivityListComponent,
5351
FilterProjectPipe,
54-
SearchProjectComponent
52+
SearchProjectComponent,
5553
],
5654
imports: [
5755
CommonModule,
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
<div class="card-body">
2-
<div class="scroll">
3-
<div class="accordion" id="accordionActivities">
4-
<div *ngIf="activities?.length > 0; else notShow">
5-
<div class="card" *ngFor="let activity of activities; let rowIndex = index">
6-
<div class="card-header">
7-
<h2 class="mb-0">
8-
<a type="button" data-toggle="collapse" [attr.data-target]="'#row'+rowIndex">
9-
{{activity.name}}
10-
</a>
11-
<div class="btn-group float-right" role="group">
12-
<i class="far fa-edit btn btn-link"></i>
13-
<i class="far fa-trash-alt btn btn-link"></i>
14-
</div>
15-
</h2>
16-
</div>
2+
<div class="scroll">
3+
<div class="accordion" id="accordionActivities">
4+
<div *ngIf="activities?.length > 0; else notShow">
5+
<div class="card" *ngFor="let activity of activities; let rowIndex = index">
6+
<div class="card-header">
7+
<h2 class="mb-0">
8+
<a type="button" data-toggle="collapse" [attr.data-target]="'#row'+rowIndex">
9+
{{activity.name}}
10+
</a>
11+
<div class="btn-group float-right" role="group">
12+
<i class="far fa-edit btn btn-link"></i>
13+
<i class="far fa-trash-alt btn btn-link"></i>
14+
</div>
15+
</h2>
16+
</div>
1717

18-
<div [id]="'row'+rowIndex" class="collapse" data-parent="#accordionActivities">
19-
<div class="card-body">
20-
<h5>Description:</h5>
21-
<p>{{activity.description}}</p>
22-
</div>
23-
</div>
24-
</div>
18+
<div [id]="'row'+rowIndex" class="collapse" data-parent="#accordionActivities">
19+
<div class="card-body">
20+
<h5>Description:</h5>
21+
<p>{{activity.description}}</p>
2522
</div>
26-
<ng-template #notShow>
27-
<app-empty-state></app-empty-state>
28-
</ng-template>
23+
</div>
2924
</div>
25+
</div>
26+
<ng-template #notShow>
27+
<app-empty-state></app-empty-state>
28+
</ng-template>
3029
</div>
31-
</div>
30+
</div>
31+
</div>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="row">
2-
<div class="col mt-1 time-clock-color">
3-
<i *ngIf="!displayTime" class="fas fa-sync-alt fa fa-spin"></i>
4-
</div>
5-
<div *ngIf="displayTime" class="col time-clock-color">
6-
<h3>{{ hour | number: '2.0-2' }}:{{ minutes | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }}</h3>
7-
</div>
2+
<div class="col mt-1 time-clock-color">
3+
<i *ngIf="!displayTime" class="fas fa-sync-alt fa fa-spin"></i>
4+
</div>
5+
<div *ngIf="displayTime" class="col time-clock-color">
6+
<h3>{{ hour | number: '2.0-2' }}:{{ minutes | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }}</h3>
7+
</div>
88
</div>

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ describe('ClockComponent', () => {
88

99
beforeEach(async(() => {
1010
TestBed.configureTestingModule({
11-
declarations: [ ClockComponent ]
11+
declarations: [ClockComponent]
1212
})
13-
.compileComponents();
13+
.compileComponents();
1414
}));
1515

1616
beforeEach(() => {
@@ -44,4 +44,18 @@ describe('ClockComponent', () => {
4444
expect(component.showClock).toHaveBeenCalled();
4545
});
4646

47-
});
47+
it('should be verify the init state of vars', () => {
48+
expect(component.hour).toEqual(0);
49+
expect(component.minutes).toEqual(0);
50+
expect(component.seconds).toEqual(0);
51+
expect(component.displayTime).toBeFalsy();
52+
});
53+
54+
it('should enter if and assign the value to vars', () => {
55+
component.showClock();
56+
expect(component.hour).toEqual(0);
57+
expect(component.minutes).toEqual(0);
58+
expect(component.seconds).toEqual(0);
59+
});
60+
61+
});

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@ export class ClockComponent implements OnInit {
1717
constructor() {
1818
this.showClock();
1919
this.displayTime = false;
20+
this.hour = 0;
21+
this.minutes = 0;
22+
this.seconds = 0;
2023
setTimeout(() => {
2124
this.displayTime = true;
2225
}, 3000);
23-
}
26+
}
2427

25-
showClock() {
28+
showClock() {
2629
const timenInterval = interval(1000);
27-
timenInterval.subscribe( (data) => {
30+
timenInterval.subscribe((data) => {
2831
this.currentDate = new Date();
2932
this.hour = this.currentDate.getHours();
3033
this.minutes = this.currentDate.getMinutes();
3134
this.seconds = this.currentDate.getSeconds();
3235
});
33-
}
36+
}
3437

3538
ngOnInit(): void {
3639
}
3740

38-
}
41+
}

src/app/modules/shared/pipes/filter-project/filter-project.pipe.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ describe('FilterProjectPipe', () => {
55
const pipe = new FilterProjectPipe();
66
expect(pipe).toBeTruthy();
77
});
8+
9+
it('test method of pipe', () => {
10+
expect(new FilterProjectPipe().transform([], '')).toEqual([]);
11+
});
812
});
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<app-search-project (changeFilterProject)="filterProjects = $event"></app-search-project>
22
<ul class="list-group content-projects">
3-
<li class="list-group-item list-group-item-action d-flex justify-content-between align-items-center" *ngFor="let item of projects | filterProject:filterProjects; let i = index" (mouseenter)="showButton = i" (mouseleave)="showButton = -1" (click)="clockIn(item.id)" [ngClass]="{ active: selectedId === item.id }">
4-
{{ item.name }}
5-
<span *ngIf="showButton === i && selectedId !== item.id" class="badge badge-light">Clock In</span>
6-
</li>
3+
<div *ngFor="let item of listProjects | filterProject:filterProjects; let i = index" class="container">
4+
<li *ngIf="item.status === 'Active'" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center" (mouseenter)="showButton = i" (mouseleave)="showButton = -1" (click)="clockIn(item.id)" [ngClass]="{ active: selectedId === item.id }">
5+
{{ item.name }}
6+
<span *ngIf="showButton != i" class="badge badge-success">{{ item.status }}</span>
7+
<span *ngIf="showButton === i && selectedId !== item.id" class="badge badge-light">Clock In</span>
8+
</li>
9+
</div>
710
</ul>

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
1+
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
22

33
import { ProjectListHoverComponent } from './project-list-hover.component';
4-
import { FilterProjectPipe } from 'src/app/modules/shared/pipes/filter-project/filter-project.pipe';
4+
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
5+
import { ProjectService } from 'src/app/modules/project-management/services/project.service';
56

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

1011
beforeEach(async(() => {
1112
TestBed.configureTestingModule({
12-
declarations: [ProjectListHoverComponent, FilterProjectPipe]
13+
imports: [HttpClientTestingModule],
14+
declarations: [ProjectListHoverComponent],
15+
providers: [ProjectService]
1316
}).compileComponents();
1417
}));
1518

@@ -19,6 +22,16 @@ describe('ProjectListHoverComponent', () => {
1922
fixture.detectChanges();
2023
});
2124

25+
it('should be created', () => {
26+
const service: ProjectService = TestBed.get(ProjectService);
27+
expect(service).toBeTruthy();
28+
});
29+
30+
it('should have add function', () => {
31+
const service: ProjectService = TestBed.get(ProjectService);
32+
expect(service.getProjects).toBeTruthy();
33+
});
34+
2235
it('should create', () => {
2336
expect(component).toBeTruthy();
2437
});

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
2+
import { Project } from 'src/app/modules/shared/models/project.model';
3+
import { ProjectService } from 'src/app/modules/project-management/services/project.service';
24

35
@Component({
46
selector: 'app-project-list-hover',
@@ -11,14 +13,16 @@ export class ProjectListHoverComponent implements OnInit {
1113

1214
selectedId: string;
1315
showButton: number;
14-
1516
filterProjects: string = '';
17+
listProjects: Project[] = [];
1618

17-
constructor() {
19+
constructor(private projectService: ProjectService) {
1820
this.showButton = -1;
1921
}
2022

21-
ngOnInit(): void { }
23+
ngOnInit(): void {
24+
this.projectService.getProjects().subscribe(data => this.listProjects = data);
25+
}
2226

2327
clockIn(id: string) {
2428
this.selectedId = id;

src/app/modules/time-clock/pages/time-clock.component.spec.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2-
import { DebugElement } from '@angular/core';
2+
import { DebugElement, inject } from '@angular/core';
33
import { By } from '@angular/platform-browser';
44
import { TimeClockComponent } from './time-clock.component';
55
import { ProjectListHoverComponent } from '../components';
6-
import { FilterProjectPipe } from '../../shared/pipes/filter-project/filter-project.pipe';
6+
import { HttpClientTestingModule } from '@angular/common/http/testing';
7+
import { ProjectService } from '../../project-management/services/project.service';
78

89
describe('TimeClockComponent', () => {
910
let component: TimeClockComponent;
@@ -12,7 +13,9 @@ describe('TimeClockComponent', () => {
1213

1314
beforeEach(async(() => {
1415
TestBed.configureTestingModule({
15-
declarations: [TimeClockComponent, ProjectListHoverComponent, FilterProjectPipe]
16+
imports: [HttpClientTestingModule],
17+
declarations: [TimeClockComponent, ProjectListHoverComponent],
18+
providers: [ProjectService]
1619
}).compileComponents();
1720
}));
1821

@@ -23,6 +26,16 @@ describe('TimeClockComponent', () => {
2326
fixture.detectChanges();
2427
});
2528

29+
it('should be created', () => {
30+
const service: ProjectService = TestBed.get(ProjectService);
31+
expect(service).toBeTruthy();
32+
});
33+
34+
it('should have add function', () => {
35+
const service: ProjectService = TestBed.get(ProjectService);
36+
expect(service.getProjects).toBeTruthy();
37+
});
38+
2639
it('should be created', () => {
2740
expect(component).toBeTruthy();
2841
});
@@ -41,14 +54,6 @@ describe('TimeClockComponent', () => {
4154
expect(component.setShowFields).toHaveBeenCalledWith(true);
4255
});
4356

44-
it('should be called the setShowFields event #2', () => {
45-
spyOn(component, 'setShowFields');
46-
const showFields = de.query(By.directive(ProjectListHoverComponent));
47-
const li = showFields.query(By.css('li'));
48-
li.nativeElement.click();
49-
expect(component.setShowFields).toHaveBeenCalledWith(true);
50-
});
51-
5257
/* ---------------------- EMPLOYE CLOCK IN ------------------------------------- */
5358
it('should be verify the init state of vars', () => {
5459
expect(component.isClockIn).toBeTruthy();

0 commit comments

Comments
 (0)