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
13 changes: 5 additions & 8 deletions src/app/modules/time-clock/pages/time-clock.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ <h6 class="text-left"><strong>Projects</strong></h6>
<br />
<form *ngIf="!isClockIn || showFields">
<div class="form-group row">
<label for="inputActivity" class="col-sm-2 col-form-label text-center"><strong>Activity</strong></label>
<label for="activitiesSelect" class="col-sm-2 col-form-label text-center"><strong>Activity</strong></label>
<div class="col-sm-10">
<input type="text" class="form-control" />
<select id="activitiesSelect" class="form-control">
<option *ngFor="let activity of activities;">{{activity.name}}</option>
</select>
</div>
</div>
<div class="form-group row">
Expand All @@ -61,12 +63,7 @@ <h6 class="text-left"><strong>Projects</strong></h6>
<button *ngIf="isClockIn" class="btn btn-primary" type="button" (click)="employeClockIn()">
Clock In
</button>
<button
*ngIf="!isClockIn"
class="btn btn-primary"
type="button"
(click)="employeClockOut()"
>
<button *ngIf="!isClockIn" class="btn btn-primary" type="button" (click)="employeClockOut()">
Clock Out
</button>
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/app/modules/time-clock/pages/time-clock.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LoadActivities } from '../../activities-management/store/activity-management.actions';
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
Expand Down Expand Up @@ -49,6 +50,14 @@ describe('TimeClockComponent', () => {
expect(component).toBeTruthy();
});

it('onInit, LoadActivities action is dispatched', () => {
spyOn(store, 'dispatch');

component.ngOnInit();

expect(store.dispatch).toHaveBeenCalledWith(new LoadActivities());
});

it('Service injected via inject(...) and TestBed.get(...) should be the same instance', inject(
[ProjectService],
(injectService: ProjectService) => {
Expand Down
18 changes: 16 additions & 2 deletions src/app/modules/time-clock/pages/time-clock.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { LoadActivities } from '../../activities-management/store/activity-management.actions';
import { ActivityState } from '../../activities-management/store/activity-management.reducers';
import { Store, select } from '@ngrx/store';
import { allActivities } from '../../activities-management/store';
import { Activity } from 'src/app/modules/shared/models';
import { Component, OnInit } from '@angular/core';

@Component({
Expand Down Expand Up @@ -25,7 +30,9 @@ export class TimeClockComponent implements OnInit {
isClockInEnable = false;
isHidenForm = true;

constructor() {
activities: Activity[] = [];

constructor(private store: Store<ActivityState>) {
this.isClockIn = true;
this.isEnterTechnology = false;
this.hourCounterRealTime = 0;
Expand All @@ -36,6 +43,14 @@ export class TimeClockComponent implements OnInit {
this.seconds = 0;
}

ngOnInit() {
this.store.dispatch(new LoadActivities());
const activities$ = this.store.pipe(select(allActivities));
activities$.subscribe((response) => {
this.activities = response;
});
}

employeClockIn(): boolean {
this.isClockInEnable = true;
this.isClockIn = !this.isClockIn;
Expand Down Expand Up @@ -119,5 +134,4 @@ export class TimeClockComponent implements OnInit {
this.isClockInEnable = false;
}

ngOnInit(): void {}
}