Skip to content

Commit

Permalink
Merge pull request #6015 from NMDSdevopsServiceAdm/fix/deleteTraining…
Browse files Browse the repository at this point in the history
…Records

Fix/delete training records
  • Loading branch information
ssrome authored Dec 14, 2023
2 parents ae3e931 + 534511b commit 1c5c711
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 18 deletions.
23 changes: 8 additions & 15 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ module.exports = function (config) {
logLevel: config.LOG_INFO,
autoWatch: !isCI,
singleRun: isCI,
// browsers: ['ChromeHeadlessNoSandbox', 'ChromeNoSandbox'],
browsers: ['ChromeNoSandbox'],
//browsers: ['ChromeHeadlessNoSandbox', 'ChromeNoSandbox'],
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
// ChromeHeadlessNoSandbox: {
// base: 'ChromeHeadless',
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox'],
},
// ChromeNoSandbox: {
// base: 'Chrome',
// flags: [
// '--no-sandbox',
// '--user-data-dir=/tmp/chrome-test-profile',
Expand All @@ -77,17 +81,6 @@ module.exports = function (config) {
// ],
// debug: true,
// },
ChromeNoSandbox: {
base: 'Chrome',
flags: [
'--no-sandbox',
'--user-data-dir=/tmp/chrome-test-profile',
'--disable-web-security',
'--remote-debugging-address=0.0.0.0',
'--remote-debugging-port=9222',
],
debug: true,
},
},
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,42 @@ describe('AddEditTrainingComponent', () => {
});
});

describe('Delete button', () => {
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',
component.workplace.uid,
'training-and-qualifications-record',
component.worker.uid,
'training',
component.trainingRecordId,
'delete',
]);
});
});

describe('Cancel button', () => {
it('should call navigate when pressing cancel', async () => {
const { component, fixture, getByText, routerSpy } = await setup();
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 @@ -175,8 +175,7 @@ <h1 class="govuk-fieldset__heading">
class="govuk-button govuk-button--link govuk__flex govuk__align-items-center"
*ngIf="trainingRecordId"
draggable="false"
href="#"
[routerLink]="['../delete']"
(click)="navigateToDeleteTrainingRecord()"
data-testid="deleteButton"
>
<img src="/assets/images/bin.svg" alt="" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,29 @@ export class AddEditTrainingDirective implements OnInit, AfterViewInit {
event.preventDefault();
this.router.navigate(this.previousUrl);
}

protected navigateToDeleteTrainingRecord(): void {
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 1c5c711

Please sign in to comment.