Skip to content

Commit

Permalink
Update automated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-elliott-nhsd committed Jan 3, 2025
1 parent 6da76a8 commit 6e01108
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 3 deletions.
19 changes: 19 additions & 0 deletions tests/test-team/pages/template-mgmt-delete-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Locator, type Page } from '@playwright/test';
import { TemplateMgmtBasePage } from './template-mgmt-base-page';

export class TemplateMgmtDeletePage extends TemplateMgmtBasePage {
readonly goBackButton: Locator;

readonly confirmButton: Locator;

constructor(page: Page) {
super(page);

this.goBackButton = page.getByText('No, go back');
this.confirmButton = page.getByText('Yes, delete template');
}

async loadPage(templateId: string) {
await this.navigateTo(`/templates/delete-template/${templateId}`);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { test, expect } from '@playwright/test';
import { TemplateMgmtDeletePage } from '../pages/template-mgmt-delete-page';
import {
assertFooterLinks,
assertGoBackLinkNotPresent,
assertLoginLink,
assertNotifyBannerLink,
assertSkipToMainContent,
} from './template-mgmt-common.steps';
import { TemplateStorageHelper } from '../helpers/template-storage-helper';
import { TemplateFactory } from '../helpers/template-factory';

const templates = {
goBack: {
...TemplateFactory.createEmailTemplate('delete-page-go-back'),
name: 'delete-page-go-back-name',
message: 'delete-page-go-back-message',
subject: 'template-subject',
},
confirm: {
...TemplateFactory.createEmailTemplate('delete-page-confirm'),
name: 'delete-page-confirm-name',
message: 'delete-page-confirm-message',
subject: 'template-subject',
},
};

const extraTemplateIds: string[] = [];

test.describe('Delete Template Page', () => {
const templateStorageHelper = new TemplateStorageHelper(
Object.values(templates)
);

test.beforeAll(async () => {
await templateStorageHelper.seedTemplateData();
});

test.afterAll(async () => {
await templateStorageHelper.deleteTemplateData(extraTemplateIds);
});

test('should land on "Delete Template" page when navigating to "/delete-template" url', async ({
page,
baseURL,
}) => {
const deleteTemplatePage = new TemplateMgmtDeletePage(page);

await deleteTemplatePage.loadPage(templates.goBack.id);

await expect(page).toHaveURL(
`${baseURL}/templates/delete-template/${templates.goBack.id}`
);
await expect(deleteTemplatePage.pageHeader).toHaveText(
`Are you sure you want to delete the template '${templates.goBack.name}'?`
);
});

test('common page tests', async ({ page, baseURL }) => {
const props = {
page: new TemplateMgmtDeletePage(page),
id: templates.goBack.id,
baseURL,
};

await assertSkipToMainContent(props);
await assertNotifyBannerLink(props);
await assertFooterLinks(props);
await assertLoginLink(props);
await assertGoBackLinkNotPresent(props);
});

test('should go back to manage-templates page with template still visible when "no" button selected', async ({
page,
}) => {
const deleteTemplatePage = new TemplateMgmtDeletePage(page);

await deleteTemplatePage.loadPage(templates.goBack.id);

await deleteTemplatePage.goBackButton.click();

await expect(page).toHaveURL('/templates/manage-templates');

await expect(page.getByText(templates.goBack.name)).toBeVisible();
});

test('should go back to manage-templates page with template no longer visible when "yes" button selected', async ({
page,
}) => {
const deleteTemplatePage = new TemplateMgmtDeletePage(page);

await deleteTemplatePage.loadPage(templates.confirm.id);

await deleteTemplatePage.confirmButton.click();

await expect(page).toHaveURL('/templates/manage-templates');

await expect(page.getByText(templates.confirm.name)).not.toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ test.describe('Manage templates page', () => {
);
const templateDeleteLink = templateRow.getByText('Delete', { exact: true });

// This will break and need updating during CCM-7572
expect(templateDeleteLink).toHaveAttribute('href', '#');
const deleteTemplateURL = `/templates/delete-template/${templates.emailNotYetSubmitted.id}`;
expect(templateDeleteLink).toHaveAttribute('href', deleteTemplateURL);
await templateDeleteLink.click();
await expect(page).toHaveURL(new RegExp('/templates/manage-templates'));
await expect(page).toHaveURL(new RegExp(deleteTemplateURL)); // eslint-disable-line security/detect-non-literal-regexp
});

test('Delete link not present for submitted templates', async ({
Expand Down

0 comments on commit 6e01108

Please sign in to comment.