Skip to content

Commit 5c19c86

Browse files
fix: TT-208 display the required activities when clicking on time entry with inactive activity
1 parent a62c980 commit 5c19c86

File tree

4 files changed

+65
-25
lines changed

4 files changed

+65
-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
@@ -133,7 +133,7 @@
133133
id="end_hour"
134134
class="timepicker-input"
135135
[class.timepicker-input--disabled]="!(project_id.value && project_name.value)"
136-
></ngx-timepicker-field>
136+
></ngx-timepicker-field>
137137
</div>
138138
</div>
139139

@@ -142,26 +142,18 @@
142142
(technologyRemoved)="onTechnologiesUpdated($event)"
143143
[selectedTechnologies]="selectedTechnologies"
144144
#technologies
145-
>
145+
>
146146
</app-technologies>
147147

148148
<div class="form-group text-left">
149149
<label for="NotesTextarea">Description:</label>
150-
<textarea
151-
maxlength="1500"
152-
formControlName="description"
153-
class="form-control"
154-
id="NotesTextarea"
155-
rows="3"
156-
>
150+
<textarea maxlength="1500" formControlName="description" class="form-control" id="NotesTextarea" rows="3">
157151
</textarea>
158152
</div>
159153
</fieldset>
160154
</div>
161155
<div class="modal-footer">
162156
<button type="submit" class="btn btn-primary">Save</button>
163-
<button #closeModal type="button" class="btn btn-secondary" data-dismiss="modal">
164-
Close
165-
</button>
157+
<button #closeModal type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
166158
</div>
167159
</form>

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

Lines changed: 34 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;
@@ -512,6 +534,17 @@ describe('DetailsFieldsComponent', () => {
512534
expect(endDateInput.id).toEqual('end_date');
513535
expect(endDateInput.max).toEqual(expectedDate);
514536
});
537+
538+
it('should find an activity with given id & status: inactive', () => {
539+
540+
const expectedActivity = { id: 'fc5fab41-a21e-4155-9d05-511b956ebd08', tenant_id: 'ioet_2', deleted: null, name: 'ghi', status: 'inactive' };
541+
542+
component.entryToEdit = { ...entryToEdit, activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd08' };
543+
spyOn(component.entryForm, 'patchValue');
544+
545+
const foundActivity = component.findInactiveActivity(state.activities.data);
546+
expect(foundActivity).toEqual(expectedActivity);
547+
});
515548
/*
516549
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
517550
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';
@@ -20,6 +20,7 @@ import { ProjectSelectedEvent } from './project-selected-event';
2020
import { get } from 'lodash';
2121
import { DATE_FORMAT } from 'src/environments/environment';
2222
import { TechnologiesComponent } from '../technologies/technologies.component';
23+
import { Observable } from 'rxjs';
2324

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

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

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

8683
const updateError$ = this.store.pipe(select(getUpdateError));
8784
updateError$.subscribe((updateError) => {
@@ -133,6 +130,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
133130
ngOnChanges(): void {
134131
this.goingToWorkOnThis = this.entryToEdit ? this.entryToEdit.running : false;
135132
this.shouldRestartEntry = false;
133+
136134
if (this.entryToEdit) {
137135
this.selectedTechnologies = this.entryToEdit.technologies;
138136
const projectFound = this.listProjects.find((project) => project.id === this.entryToEdit.project_id);
@@ -148,6 +146,17 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
148146
uri: this.entryToEdit.uri,
149147
technology: '',
150148
});
149+
150+
this.activities$ = this.store.pipe(
151+
select(allActiveActivities),
152+
mergeMap(activeActivities => this.store.pipe(
153+
select(allActivities),
154+
map(activities => this.findInactiveActivity(activities) !== undefined
155+
? [...activeActivities, this.findInactiveActivity(activities)]
156+
: activeActivities
157+
)
158+
))
159+
);
151160
} else {
152161
this.cleanForm();
153162
}
@@ -176,6 +185,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
176185
this.cleanForm(true);
177186
}
178187

188+
findInactiveActivity(activities) {
189+
return activities.find(activity => activity.status === 'inactive' &&
190+
activity.id === this.entryToEdit.activity_id
191+
);
192+
}
193+
179194
onTechnologiesUpdated($event: string[]) {
180195
this.selectedTechnologies = $event;
181196
}

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)