diff --git a/tests/test-team/pages/template-mgmt-delete-page.ts b/tests/test-team/pages/template-mgmt-delete-page.ts new file mode 100644 index 00000000..0fd2c114 --- /dev/null +++ b/tests/test-team/pages/template-mgmt-delete-page.ts @@ -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}`); + } +} diff --git a/tests/test-team/template-mgmt-component-tests/template-mgmt-delete-page.component.ts b/tests/test-team/template-mgmt-component-tests/template-mgmt-delete-page.component.ts new file mode 100644 index 00000000..f8886cdb --- /dev/null +++ b/tests/test-team/template-mgmt-component-tests/template-mgmt-delete-page.component.ts @@ -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(); + }); +}); diff --git a/tests/test-team/template-mgmt-component-tests/template-mgmt-manage-templates-page.component.ts b/tests/test-team/template-mgmt-component-tests/template-mgmt-manage-templates-page.component.ts index 10831a9b..ed8540d1 100644 --- a/tests/test-team/template-mgmt-component-tests/template-mgmt-manage-templates-page.component.ts +++ b/tests/test-team/template-mgmt-component-tests/template-mgmt-manage-templates-page.component.ts @@ -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 ({