Skip to content

Commit bfcd3ae

Browse files
committed
fix: #151 clock out
1 parent 27011b4 commit bfcd3ae

23 files changed

+277
-477
lines changed

src/app/modules/activities-management/components/activity-list/activity-list.component.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { provideMockStore, MockStore } from '@ngrx/store/testing';
2+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
23

34
import { allActivities } from './../../store/activity-management.selectors';
45
import { ActivityState } from './../../store/activity-management.reducers';
5-
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
6+
import { DeleteActivity, SetActivityToEdit } from './../../store/activity-management.actions';
67
import { ActivityListComponent } from './activity-list.component';
78

89
describe('ActivityListComponent', () => {
@@ -47,6 +48,22 @@ describe('ActivityListComponent', () => {
4748
expect(store.dispatch).toHaveBeenCalled();
4849
});
4950

51+
it('deleteActivity, dispatchs DeleteActivity action', () => {
52+
spyOn(store, 'dispatch');
53+
54+
component.deleteActivity('id');
55+
56+
expect(store.dispatch).toHaveBeenCalledWith(new DeleteActivity('id'));
57+
});
58+
59+
it('updateActivity, dispatchs SetActivityToEdit action', () => {
60+
spyOn(store, 'dispatch');
61+
62+
component.updateActivity('id');
63+
64+
expect(store.dispatch).toHaveBeenCalledWith(new SetActivityToEdit('id'));
65+
});
66+
5067
it('onInit, activities field is populated with data from store', () => {
5168
component.ngOnInit();
5269

src/app/modules/shared/components/modal/modal.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ <h5 class="modal-title" id="exampleModalLabel">Delete Project</h5>
77
</button>
88
</div>
99
<div class="modal-body">
10-
Are you sure you want to delete <b>{{ list.name || list.project }}</b> entry?
10+
Are you sure you want to delete <b>{{ list.name }}</b> entry?
1111
</div>
1212
<div class="modal-footer">
1313
<button #cancelDeleteModal type="button" class="btn cancel-button-style" data-dismiss="modal">Cancel</button>
14-
<button (click)="removeListById(list.id)" type="button" class="btn delete-button-style">Delete</button>
14+
<button type="button" class="btn delete-button-style">Delete</button>
1515
</div>
1616
</div>
1717
</div>

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,4 @@ describe('ModalComponent', () => {
2222
expect(component).toBeTruthy();
2323
});
2424

25-
it('should emit removeProject event #removedProject', () => {
26-
const merged = {
27-
id: '1',
28-
name: 'app 4',
29-
description: 'It is a good app',
30-
project_type_id: '123',
31-
completed: true,
32-
project: 'ErnstYoung',
33-
startDate: '2020-02-05T15:36:15.887Z',
34-
endDate: '2020-02-05T18:36:15.887Z',
35-
activity: 'development',
36-
technologies: ['Angular', 'TypeScript'],
37-
};
38-
39-
spyOn(component.removeList, 'emit');
40-
component.list = merged;
41-
fixture.detectChanges();
42-
component.removeListById(merged.id);
43-
expect(component.removeList.emit).toHaveBeenCalled();
44-
component.cancelDeleteModal.nativeElement.click();
45-
});
4625
});

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,4 @@ export class ModalComponent implements OnInit {
2424
constructor() { }
2525

2626
ngOnInit(): void { }
27-
28-
removeListById(projectId: string) {
29-
this.removeList.emit(projectId);
30-
this.cancelDeleteModal.nativeElement.click();
31-
}
3227
}

src/app/modules/shared/models/entry.model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export interface Entry {
22
id: string;
3-
project: string;
4-
startDate: string;
5-
endDate: string;
3+
start_date: Date;
4+
end_date: Date;
65
activity: string;
76
technologies: string[];
87
comments?: string;
98
uri?: string;
9+
project_id?: string;
1010
}
1111

1212
export interface NewEntry {

src/app/modules/shared/store/technology.effects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class TechnologyEffects {
1515
ofType(actions.TechnologyActionTypes.FIND_TECHNOLOGIES),
1616
map((action: actions.FindTechnology) => action.payload),
1717
mergeMap((value) =>
18-
this.technologyService.getTechnologies(value).pipe(
18+
this.technologyService.getTechnologies(value.toLowerCase()).pipe(
1919
map((technology) => {
2020
return new actions.FindTechnologySuccess(technology);
2121
}),

src/app/modules/time-clock/components/entry-fields/entry-fields.component.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,25 @@
3838
{{ item.name }}
3939
</div>
4040
</div>
41-
<div class="tags-content d-flex flex-wrap">
41+
<div class="tags-content d-flex flex-wrap" *ngIf="selectedTechnology.length">
4242
<div *ngFor="let technology of selectedTechnology; let tagIndex = index" class="tag">
4343
<span class="mr-3">{{ technology }}</span>
4444
<i class="fas fa-times text-white" (click)="removeTag(tagIndex)"></i>
4545
</div>
4646
</div>
4747

48+
<div class="form-group" *ngIf="selectedTechnology.length === 0">
49+
<!-- empty-space -->
50+
</div>
51+
4852
<div class="form-group text-left">
4953
<label for="NotesTextarea">Description</label>
5054
<textarea
5155
(blur)="onSubmit()"
5256
formControlName="description"
5357
class="form-control"
5458
id="NotesTextarea"
55-
rows="3"
56-
></textarea>
59+
rows="3">
60+
</textarea>
5761
</div>
5862
</form>

src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { allTechnologies } from '../../../shared/store/technology.selectors';
77
import { EntryFieldsComponent } from './entry-fields.component';
88
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
99
import { allProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
10-
import { allEntries } from '../../store/entry.selectors';
1110
import * as actions from '../../../shared/store/technology.actions';
1211
import * as entryActions from '../../store/entry.actions';
1312

@@ -18,7 +17,6 @@ describe('EntryFieldsComponent', () => {
1817
let store: MockStore<Merged>;
1918
let mockTechnologySelector;
2019
let mockProjectsSelector;
21-
let mockEntrySelector;
2220
let length;
2321

2422
const state = {
@@ -68,7 +66,6 @@ describe('EntryFieldsComponent', () => {
6866
store = TestBed.inject(MockStore);
6967
mockTechnologySelector = store.overrideSelector(allTechnologies, state.technologies);
7068
mockProjectsSelector = store.overrideSelector(allProjects, state.projects);
71-
mockEntrySelector = store.overrideSelector(allEntries, state.entries);
7269
}));
7370

7471
beforeEach(() => {

src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Component, OnInit, ViewChild, ElementRef, Renderer2 } from '@angular/core';
1+
import { getActiveTimeEntry } from './../../store/entry.selectors';
2+
import { Component, OnInit, ViewChild, ElementRef, Renderer2, Output, EventEmitter } from '@angular/core';
23
import { FormBuilder, FormGroup } from '@angular/forms';
34
import { Store, select } from '@ngrx/store';
45

@@ -10,7 +11,6 @@ import { ProjectState } from '../../../customer-management/components/projects/c
1011
import { TechnologyState } from '../../../shared/store/technology.reducers';
1112
import { LoadActivities, ActivityState, allActivities } from '../../../activities-management/store';
1213

13-
import { allEntries } from '../../store/entry.selectors';
1414
import * as entryActions from '../../store/entry.actions';
1515

1616
type Merged = TechnologyState & ProjectState & ActivityState;
@@ -21,6 +21,7 @@ type Merged = TechnologyState & ProjectState & ActivityState;
2121
styleUrls: ['./entry-fields.component.scss'],
2222
})
2323
export class EntryFieldsComponent implements OnInit {
24+
2425
@ViewChild('list') list: ElementRef;
2526
entryForm: FormGroup;
2627
technology: Technology;
@@ -57,15 +58,17 @@ export class EntryFieldsComponent implements OnInit {
5758
this.activities = response;
5859
});
5960

60-
const activeEntry$ = this.store.pipe(select(allEntries));
61+
const activeEntry$ = this.store.pipe(select(getActiveTimeEntry));
6162
activeEntry$.subscribe((response) => {
62-
this.activeEntry = response.active;
63-
this.setDataToUpdate(this.activeEntry);
64-
this.newData = {
65-
id: this.activeEntry.id,
66-
project_id: this.activeEntry.project_id,
67-
uri: this.activeEntry.uri,
68-
};
63+
if (response) {
64+
this.activeEntry = response;
65+
this.setDataToUpdate(this.activeEntry);
66+
this.newData = {
67+
id: this.activeEntry.id,
68+
project_id: this.activeEntry.project_id,
69+
uri: this.activeEntry.uri,
70+
};
71+
}
6972
});
7073
}
7174

@@ -92,7 +95,6 @@ export class EntryFieldsComponent implements OnInit {
9295

9396
setTechnology(name: string) {
9497
const index = this.selectedTechnology.indexOf(name);
95-
9698
if (index > -1) {
9799
this.removeTag(index);
98100
} else if (this.selectedTechnology.length < 10) {
@@ -111,4 +113,5 @@ export class EntryFieldsComponent implements OnInit {
111113
onSubmit() {
112114
this.store.dispatch(new entryActions.UpdateActiveEntry({ ...this.newData, ...this.entryForm.value }));
113115
}
116+
114117
}

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { ProjectListHoverComponent } from './project-list-hover.component';
66
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
77
import { allProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
88
import { FilterProjectPipe } from '../../../shared/pipes';
9-
import { NewEntry } from '../../../shared/models';
109
import * as action from '../../store/entry.actions';
1110

1211
describe('ProjectListHoverComponent', () => {
@@ -54,22 +53,11 @@ describe('ProjectListHoverComponent', () => {
5453
expect(component).toBeTruthy();
5554
});
5655

57-
it('should set selectedId with Id and dispatch CreateEntry action', () => {
56+
it('clock-in dispatchs a new action', () => {
5857
spyOn(store, 'dispatch');
59-
const id = 'P1';
60-
const entryData: NewEntry = {
61-
project_id: id,
62-
start_date: new Date().toISOString(),
63-
};
64-
component.clockIn(id);
6558

66-
expect(store.dispatch).toHaveBeenCalledWith(new action.CreateEntry(entryData));
67-
expect(component.selectedId).toBe(id);
68-
});
59+
component.clockIn('id');
6960

70-
it('should emit showFields event', () => {
71-
const id = 'P1';
72-
component.showFields.subscribe((showFields: boolean) => expect(showFields).toEqual(true));
73-
component.clockIn(id);
61+
expect(store.dispatch).toHaveBeenCalledWith(new action.CreateEntry({project_id: 'id', start_date: new Date().toISOString() }));
7462
});
7563
});

0 commit comments

Comments
 (0)