Skip to content

Commit

Permalink
Remove code with was overwriting variable on add-edit-training
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrome committed Dec 14, 2023
1 parent a590f26 commit 8b81c07
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,28 @@ describe('AddEditTrainingComponent', () => {
});

describe('Delete button', () => {
it('should navigate to delete confirmation page', async () => {
const { component, routerSpy, getByTestId } = await setup();
const deleteTrainingRecord = getByTestId('delete-this-training-record');
it('should navigate to delete confirmation page with training category', async () => {
const { component, routerSpy, getByTestId, fixture } = await setup();
const deleteTrainingRecord = getByTestId('deleteButton');
component.trainingCategory = { id: 2, category: 'First aid' };
fixture.detectChanges();

fireEvent.click(deleteTrainingRecord);
expect(routerSpy).toHaveBeenCalledWith([
'/workplace',
component.workplace.uid,
'training-and-qualifications-record',
component.worker.uid,
'training',
component.trainingRecordId,
{ trainingCategory: JSON.stringify(component.trainingCategory) },
'delete',
]);
});

it('should navigate to delete confirmation page without training category', async () => {
const { component, routerSpy, getByTestId } = await setup();
const deleteTrainingRecord = getByTestId('deleteButton');
fireEvent.click(deleteTrainingRecord);
expect(routerSpy).toHaveBeenCalledWith([
'/workplace',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ describe('MultipleTrainingDetailsComponent', () => {
await setup();

const categoryOption = component.categories[0].id.toString();

userEvent.selectOptions(getByLabelText('Training category'), categoryOption);
userEvent.type(getByLabelText('Training name'), 'Training');
userEvent.click(getByLabelText('Yes'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ <h1 class="govuk-fieldset__heading">
draggable="false"
(click)="navigateToDeleteTrainingRecord()"
data-testid="deleteButton"
data-testid="delete-this-training-record"
>
<img src="/assets/images/bin.svg" alt="" />
<span class="govuk-!-margin-left-1"> Delete this training record </span></a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ export class AddEditTrainingDirective implements OnInit, AfterViewInit {
this.setBackLink();
this.getCategories();
this.setupFormErrorsMap();

this.trainingRecordId = this.route.snapshot.params.trainingRecordId;
}

ngAfterViewInit(): void {
Expand Down Expand Up @@ -287,14 +285,27 @@ export class AddEditTrainingDirective implements OnInit, AfterViewInit {
}

protected navigateToDeleteTrainingRecord(): void {
this.router.navigate([
'/workplace',
this.workplace.uid,
'training-and-qualifications-record',
this.worker.uid,
'training',
this.trainingRecordId,
'delete',
]);
if (this.trainingCategory) {
this.router.navigate([
'/workplace',
this.workplace.uid,
'training-and-qualifications-record',
this.worker.uid,
'training',
this.trainingRecordId,
{ trainingCategory: JSON.stringify(this.trainingCategory) },
'delete',
]);
} else {
this.router.navigate([
'/workplace',
this.workplace.uid,
'training-and-qualifications-record',
this.worker.uid,
'training',
this.trainingRecordId,
'delete',
]);
}
}
}

0 comments on commit 8b81c07

Please sign in to comment.