Skip to content

Commit 286033c

Browse files
fix: TT-208 display the required activities when clicking on time entry with inactive activity
1 parent 5808250 commit 286033c

File tree

4 files changed

+64
-25
lines changed

4 files changed

+64
-25
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.html

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
formControlName="activity_id"
5656
>
5757
<option value="" selected="selected"></option>
58-
<option *ngFor="let activity of activities" value="{{ activity.id }}">{{ activity.name }}</option>
58+
<option *ngFor="let activity of activities$ | async" value="{{ activity.id }}">{{ activity.name }}</option>
5959
</select>
6060
</div>
6161
<div
@@ -141,7 +141,7 @@
141141
id="end_hour"
142142
class="timepicker-input"
143143
[class.timepicker-input--disabled]="!(project_id.value && project_name.value)"
144-
></ngx-timepicker-field>
144+
></ngx-timepicker-field>
145145
</div>
146146
</div>
147147

@@ -161,26 +161,18 @@
161161
(technologyRemoved)="onTechnologiesUpdated($event)"
162162
[selectedTechnologies]="selectedTechnologies"
163163
#technologies
164-
>
164+
>
165165
</app-technologies>
166166

167167
<div class="form-group text-left">
168168
<label for="NotesTextarea">Description:</label>
169-
<textarea
170-
maxlength="1500"
171-
formControlName="description"
172-
class="form-control"
173-
id="NotesTextarea"
174-
rows="3"
175-
>
169+
<textarea maxlength="1500" formControlName="description" class="form-control" id="NotesTextarea" rows="3">
176170
</textarea>
177171
</div>
178172
</fieldset>
179173
</div>
180174
<div class="modal-footer">
181175
<button type="submit" class="btn btn-primary">Save</button>
182-
<button #closeModal type="button" class="btn btn-secondary" data-dismiss="modal">
183-
Close
184-
</button>
176+
<button #closeModal type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
185177
</div>
186178
</form>

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ describe('DetailsFieldsComponent', () => {
5353
isLoading: false,
5454
},
5555
activities: {
56-
data: [{ id: 'fc5fab41-a21e-4155-9d05-511b956ebd05', tenant_id: 'ioet', deleted: null, name: 'abc', status: 'active' }],
56+
data: [{ id: 'fc5fab41-a21e-4155-9d05-511b956ebd05', tenant_id: 'ioet', deleted: null, name: 'abc', status: 'active' },
57+
{ id: 'fc5fab41-a21e-4155-9d05-511b956ebd07', tenant_id: 'ioet_1', deleted: null, name: 'def', status: 'active' },
58+
{ id: 'fc5fab41-a21e-4155-9d05-511b956ebd08', tenant_id: 'ioet_2', deleted: null, name: 'ghi', status: 'inactive' },
59+
{ id: 'fc5fab41-a21e-4155-9d05-511b956ebd09', tenant_id: 'ioet_3', deleted: null, name: 'jkl', status: 'active' }],
5760
isLoading: false,
5861
message: 'Data fetch successfully!',
5962
activityIdToEdit: '',
@@ -193,6 +196,7 @@ describe('DetailsFieldsComponent', () => {
193196
component.ngOnChanges();
194197
expect(component.shouldRestartEntry).toBeFalse();
195198
expect(component.entryForm.value).toEqual(initialData);
199+
expect(component.activities$).toBe(undefined);
196200
});
197201

198202
it('should emit ngOnChange with new data', () => {
@@ -215,6 +219,24 @@ describe('DetailsFieldsComponent', () => {
215219
expect(component.entryForm.value).toEqual(formValue);
216220
});
217221

222+
const activitiesParams = [
223+
{ select_activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd07', expected_size_activities: 3, title: 'active' },
224+
{ select_activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd08', expected_size_activities: 4, title: 'inactive' }
225+
];
226+
activitiesParams.map(param => {
227+
it(`should emit ngOnChange to set ${param.expected_size_activities} activities for select (${param.title} time entry clicked)`, () => {
228+
component.entryToEdit = { ...entryToEdit, activity_id: param.select_activity_id };
229+
spyOn(component.entryForm, 'patchValue');
230+
component.ngOnChanges();
231+
232+
component.activities$.subscribe(items => {
233+
console.log(items);
234+
235+
expect(items.length).toBe(param.expected_size_activities);
236+
});
237+
});
238+
});
239+
218240
it('should call createError ', () => {
219241
const childComponent = jasmine.createSpyObj('ChildComponent', ['closeModal']);
220242
component.closeModal = childComponent;
@@ -544,6 +566,16 @@ describe('DetailsFieldsComponent', () => {
544566
});
545567
});
546568

569+
it('should find an activity with given id & status: inactive', () => {
570+
571+
const expectedActivity = { id: 'fc5fab41-a21e-4155-9d05-511b956ebd08', tenant_id: 'ioet_2', deleted: null, name: 'ghi', status: 'inactive' };
572+
573+
component.entryToEdit = { ...entryToEdit, activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd08' };
574+
spyOn(component.entryForm, 'patchValue');
575+
576+
const foundActivity = component.findInactiveActivity(state.activities.data);
577+
expect(foundActivity).toEqual(expectedActivity);
578+
});
547579
/*
548580
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
549581
and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here:

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
44
import { ActionsSubject, select, Store } from '@ngrx/store';
55
import * as moment from 'moment';
66
import { ToastrService } from 'ngx-toastr';
7-
import { filter } from 'rxjs/operators';
7+
import { filter, map, mergeMap } from 'rxjs/operators';
88
import { getCreateError, getUpdateError } from 'src/app/modules/time-clock/store/entry.selectors';
9-
import { ActivityState, allActiveActivities, LoadActivities } from '../../../activities-management/store';
9+
import { ActivityState, allActiveActivities, allActivities, LoadActivities } from '../../../activities-management/store';
1010
import * as projectActions from '../../../customer-management/components/projects/components/store/project.actions';
1111
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
1212
import { getProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
@@ -21,6 +21,7 @@ import { get } from 'lodash';
2121
import { DATE_FORMAT, DATE_FORMAT_YEAR } from 'src/environments/environment';
2222
import { TechnologiesComponent } from '../technologies/technologies.component';
2323
import { MatDatepicker } from '@angular/material/datepicker';
24+
import { Observable } from 'rxjs';
2425

2526
type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
2627
@Component({
@@ -40,7 +41,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
4041
selectedTechnologies: string[] = [];
4142
isLoading = false;
4243
listProjects: Project[] = [];
43-
activities: Activity[] = [];
44+
activities$: Observable<Activity[]>;
4445
goingToWorkOnThis = false;
4546
shouldRestartEntry = false;
4647

@@ -79,10 +80,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
7980
});
8081

8182
this.store.dispatch(new LoadActivities());
82-
const activities$ = this.store.pipe(select(allActiveActivities));
83-
activities$.subscribe((response) => {
84-
this.activities = response;
85-
});
8683

8784
const updateError$ = this.store.pipe(select(getUpdateError));
8885
updateError$.subscribe((updateError) => {
@@ -145,6 +142,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
145142
ngOnChanges(): void {
146143
this.goingToWorkOnThis = this.entryToEdit ? this.entryToEdit.running : false;
147144
this.shouldRestartEntry = false;
145+
148146
if (this.entryToEdit) {
149147
this.selectedTechnologies = this.entryToEdit.technologies;
150148
const projectFound = this.listProjects.find((project) => project.id === this.entryToEdit.project_id);
@@ -160,6 +158,17 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
160158
uri: this.entryToEdit.uri,
161159
technology: '',
162160
});
161+
162+
this.activities$ = this.store.pipe(
163+
select(allActiveActivities),
164+
mergeMap(activeActivities => this.store.pipe(
165+
select(allActivities),
166+
map(activities => this.findInactiveActivity(activities) !== undefined
167+
? [...activeActivities, this.findInactiveActivity(activities)]
168+
: activeActivities
169+
)
170+
))
171+
);
163172
} else {
164173
this.cleanForm();
165174
}
@@ -188,6 +197,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
188197
this.cleanForm(true);
189198
}
190199

200+
findInactiveActivity(activities) {
201+
return activities.find(activity => activity.status === 'inactive' &&
202+
activity.id === this.entryToEdit.activity_id
203+
);
204+
}
205+
191206
onTechnologiesUpdated($event: string[]) {
192207
this.selectedTechnologies = $event;
193208
}

src/app/modules/time-entries/pages/time-entries.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
</button>
1313
</div>
1414
</div>
15-
<div style="height: 15px;"></div>
15+
<div style="height: 15px"></div>
1616
<app-month-picker (dateSelected)="dateSelected($event)"></app-month-picker>
17-
<div style="height: 15px;"></div>
17+
<div style="height: 15px"></div>
1818

19-
<table class="table table-sm table-striped mb-0" *ngIf="(timeEntriesDataSource$ | async) as dataSource">
19+
<table class="table table-sm table-striped mb-0" *ngIf="timeEntriesDataSource$ | async as dataSource">
2020
<thead class="thead-blue">
2121
<tr class="d-flex">
2222
<th class="col">Date</th>
@@ -73,7 +73,7 @@ <h5 class="modal-title">{{ entryId ? 'Edit Entry' : 'New Entry' }}</h5>
7373
[entryToEdit]="entry"
7474
(saveEntry)="saveEntry($event)"
7575
(projectSelected)="projectSelected($event)"
76-
[canMarkEntryAsWIP]='canMarkEntryAsWIP'
76+
[canMarkEntryAsWIP]="canMarkEntryAsWIP"
7777
#detailsFields
7878
>
7979
</app-details-fields>

0 commit comments

Comments
 (0)