Skip to content
Closed
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
#3 added project service in list
  • Loading branch information
daros10 committed Mar 31, 2020
commit ada712fdb09d6afffec057c25ff407e1c6eedba9
4 changes: 1 addition & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NavbarComponent } from './modules/shared/components/navbar/navbar.component';
Expand All @@ -27,7 +26,6 @@ import { CreateActivityComponent } from './modules/activities-management/compone
import { FilterProjectPipe } from './modules/shared/pipes/filter-project/filter-project.pipe';
import { SearchProjectComponent } from './modules/shared/components/search-project/search-project.component';


@NgModule({
declarations: [
AppComponent,
Expand All @@ -51,7 +49,7 @@ import { SearchProjectComponent } from './modules/shared/components/search-proje
CreateActivityComponent,
ActivityListComponent,
FilterProjectPipe,
SearchProjectComponent
SearchProjectComponent,
],
imports: [
CommonModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<div class="card-body">
<div class="scroll">
<div class="accordion" id="accordionActivities">
<div *ngIf="activities?.length > 0; else notShow">
<div class="card" *ngFor="let activity of activities; let rowIndex = index">
<div class="card-header">
<h2 class="mb-0">
<a type="button" data-toggle="collapse" [attr.data-target]="'#row'+rowIndex">
{{activity.name}}
</a>
<div class="btn-group float-right" role="group">
<i class="far fa-edit btn btn-link"></i>
<i class="far fa-trash-alt btn btn-link"></i>
</div>
</h2>
</div>
<div class="scroll">
<div class="accordion" id="accordionActivities">
<div *ngIf="activities?.length > 0; else notShow">
<div class="card" *ngFor="let activity of activities; let rowIndex = index">
<div class="card-header">
<h2 class="mb-0">
<a type="button" data-toggle="collapse" [attr.data-target]="'#row'+rowIndex">
{{activity.name}}
</a>
<div class="btn-group float-right" role="group">
<i class="far fa-edit btn btn-link"></i>
<i class="far fa-trash-alt btn btn-link"></i>
</div>
</h2>
</div>

<div [id]="'row'+rowIndex" class="collapse" data-parent="#accordionActivities">
<div class="card-body">
<h5>Description:</h5>
<p>{{activity.description}}</p>
</div>
</div>
</div>
<div [id]="'row'+rowIndex" class="collapse" data-parent="#accordionActivities">
<div class="card-body">
<h5>Description:</h5>
<p>{{activity.description}}</p>
</div>
<ng-template #notShow>
<app-empty-state></app-empty-state>
</ng-template>
</div>
</div>
</div>
<ng-template #notShow>
<app-empty-state></app-empty-state>
</ng-template>
</div>
</div>
</div>
</div>
12 changes: 6 additions & 6 deletions src/app/modules/shared/components/clock/clock.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="row">
<div class="col mt-1 time-clock-color">
<i *ngIf="!displayTime" class="fas fa-sync-alt fa fa-spin"></i>
</div>
<div *ngIf="displayTime" class="col time-clock-color">
<h3>{{ hour | number: '2.0-2' }}:{{ minutes | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }}</h3>
</div>
<div class="col mt-1 time-clock-color">
<i *ngIf="!displayTime" class="fas fa-sync-alt fa fa-spin"></i>
</div>
<div *ngIf="displayTime" class="col time-clock-color">
<h3>{{ hour | number: '2.0-2' }}:{{ minutes | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }}</h3>
</div>
</div>
20 changes: 17 additions & 3 deletions src/app/modules/shared/components/clock/clock.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ describe('ClockComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ClockComponent ]
declarations: [ClockComponent]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down Expand Up @@ -44,4 +44,18 @@ describe('ClockComponent', () => {
expect(component.showClock).toHaveBeenCalled();
});

});
it('should be verify the init state of vars', () => {
expect(component.hour).toEqual(0);
expect(component.minutes).toEqual(0);
expect(component.seconds).toEqual(0);
expect(component.displayTime).toBeFalsy();
});

it('should enter if and assign the value to vars', () => {
component.showClock();
expect(component.hour).toEqual(0);
expect(component.minutes).toEqual(0);
expect(component.seconds).toEqual(0);
});

});
13 changes: 8 additions & 5 deletions src/app/modules/shared/components/clock/clock.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ export class ClockComponent implements OnInit {
constructor() {
this.showClock();
this.displayTime = false;
this.hour = 0;
this.minutes = 0;
this.seconds = 0;
setTimeout(() => {
this.displayTime = true;
}, 3000);
}
}

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

ngOnInit(): void {
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ describe('FilterProjectPipe', () => {
const pipe = new FilterProjectPipe();
expect(pipe).toBeTruthy();
});

it('test method of pipe', () => {
expect(new FilterProjectPipe().transform([], '')).toEqual([]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improve the test, you can create a mock with projects data and test the transform method.

});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<app-search-project (changeFilterProject)="filterProjects = $event"></app-search-project>
<ul class="list-group content-projects">
<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 }">
{{ item.name }}
<span *ngIf="showButton === i && selectedId !== item.id" class="badge badge-light">Clock In</span>
</li>
<div *ngFor="let item of listProjects | filterProject:filterProjects; let i = index" class="container">
<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 }">
{{ item.name }}
<span *ngIf="showButton != i" class="badge badge-success">{{ item.status }}</span>
<span *ngIf="showButton === i && selectedId !== item.id" class="badge badge-light">Clock In</span>
</li>
</div>
</ul>
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';

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

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

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ProjectListHoverComponent, FilterProjectPipe]
imports: [HttpClientTestingModule],
declarations: [ProjectListHoverComponent],
providers: [ProjectService]
}).compileComponents();
}));

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

it('should be created', () => {
const service: ProjectService = TestBed.get(ProjectService);
expect(service).toBeTruthy();
});

it('should have add function', () => {
const service: ProjectService = TestBed.get(ProjectService);
expect(service.getProjects).toBeTruthy();
});

it('should create', () => {
expect(component).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Project } from 'src/app/modules/shared/models/project.model';
import { ProjectService } from 'src/app/modules/project-management/services/project.service';

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

selectedId: string;
showButton: number;

filterProjects: string = '';
listProjects: Project[] = [];

constructor() {
constructor(private projectService: ProjectService) {
this.showButton = -1;
}

ngOnInit(): void { }
ngOnInit(): void {
this.projectService.getProjects().subscribe(data => this.listProjects = data);
}

clockIn(id: string) {
this.selectedId = id;
Expand Down
27 changes: 16 additions & 11 deletions src/app/modules/time-clock/pages/time-clock.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DebugElement } from '@angular/core';
import { DebugElement, inject } from '@angular/core';
import { By } from '@angular/platform-browser';
import { TimeClockComponent } from './time-clock.component';
import { ProjectListHoverComponent } from '../components';
import { FilterProjectPipe } from '../../shared/pipes/filter-project/filter-project.pipe';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ProjectService } from '../../project-management/services/project.service';

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

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TimeClockComponent, ProjectListHoverComponent, FilterProjectPipe]
imports: [HttpClientTestingModule],
declarations: [TimeClockComponent, ProjectListHoverComponent],
providers: [ProjectService]
}).compileComponents();
}));

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

it('should be created', () => {
const service: ProjectService = TestBed.get(ProjectService);
expect(service).toBeTruthy();
});

it('should have add function', () => {
const service: ProjectService = TestBed.get(ProjectService);
expect(service.getProjects).toBeTruthy();
});

it('should be created', () => {
expect(component).toBeTruthy();
});
Expand All @@ -41,14 +54,6 @@ describe('TimeClockComponent', () => {
expect(component.setShowFields).toHaveBeenCalledWith(true);
});

it('should be called the setShowFields event #2', () => {
spyOn(component, 'setShowFields');
const showFields = de.query(By.directive(ProjectListHoverComponent));
const li = showFields.query(By.css('li'));
li.nativeElement.click();
expect(component.setShowFields).toHaveBeenCalledWith(true);
});

/* ---------------------- EMPLOYE CLOCK IN ------------------------------------- */
it('should be verify the init state of vars', () => {
expect(component.isClockIn).toBeTruthy();
Expand Down
Loading