|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import { TemplateStorageHelper } from '../../helpers/db/template-storage-helper'; |
| 3 | +import { TemplateFactory } from '../../helpers/factories/template-factory'; |
| 4 | +import { Template } from '../../helpers/types'; |
| 5 | +import { |
| 6 | + createAuthHelper, |
| 7 | + TestUserId, |
| 8 | +} from '../../helpers/auth/cognito-auth-helper'; |
| 9 | +import { TemplateMgmtPreviewLetterPage } from '../../pages/letter/template-mgmt-preview-letter-page'; |
| 10 | + |
| 11 | +async function createTemplates() { |
| 12 | + const user = await createAuthHelper().getTestUser(TestUserId.User1); |
| 13 | + return { |
| 14 | + empty: { |
| 15 | + id: 'preview-page-invalid-letter-template', |
| 16 | + version: 1, |
| 17 | + createdAt: new Date().toISOString(), |
| 18 | + updatedAt: new Date().toISOString(), |
| 19 | + templateType: 'LETTER', |
| 20 | + templateStatus: 'NOT_YET_SUBMITTED', |
| 21 | + owner: user.userId, |
| 22 | + } as Template, |
| 23 | + valid: TemplateFactory.createLetterTemplate( |
| 24 | + 'valid-letter-preview-template', |
| 25 | + user.userId, |
| 26 | + 'test-template-letter' |
| 27 | + ), |
| 28 | + }; |
| 29 | +} |
| 30 | + |
| 31 | +test.describe('Preview Letter template Page', () => { |
| 32 | + let templates: { empty: Template; valid: Template }; |
| 33 | + |
| 34 | + const templateStorageHelper = new TemplateStorageHelper(); |
| 35 | + |
| 36 | + test.beforeAll(async () => { |
| 37 | + templates = await createTemplates(); |
| 38 | + await templateStorageHelper.seedTemplateData(Object.values(templates)); |
| 39 | + }); |
| 40 | + |
| 41 | + test.afterAll(async () => { |
| 42 | + await templateStorageHelper.deleteSeededTemplates(); |
| 43 | + }); |
| 44 | + |
| 45 | + test('when user visits page, then page is loaded', async ({ |
| 46 | + page, |
| 47 | + baseURL, |
| 48 | + }) => { |
| 49 | + const previewLetterTemplatePage = new TemplateMgmtPreviewLetterPage(page); |
| 50 | + |
| 51 | + await previewLetterTemplatePage.loadPage(templates.valid.id); |
| 52 | + |
| 53 | + await expect(page).toHaveURL( |
| 54 | + `${baseURL}/templates/${TemplateMgmtPreviewLetterPage.pageUrlSegment}/${templates.valid.id}` |
| 55 | + ); |
| 56 | + |
| 57 | + await expect(previewLetterTemplatePage.pageHeader).toContainText( |
| 58 | + 'test-template-letter' |
| 59 | + ); |
| 60 | + }); |
| 61 | + |
| 62 | + test.describe('Error handling', () => { |
| 63 | + test('when user visits page with missing data, then an invalid template error is displayed', async ({ |
| 64 | + baseURL, |
| 65 | + page, |
| 66 | + }) => { |
| 67 | + const previewLetterTemplatePage = new TemplateMgmtPreviewLetterPage(page); |
| 68 | + |
| 69 | + await previewLetterTemplatePage.loadPage(templates.empty.id); |
| 70 | + |
| 71 | + await expect(page).toHaveURL(`${baseURL}/templates/invalid-template`); |
| 72 | + }); |
| 73 | + |
| 74 | + test('when user visits page with a fake template, then an invalid template error is displayed', async ({ |
| 75 | + baseURL, |
| 76 | + page, |
| 77 | + }) => { |
| 78 | + const previewLetterTemplatePage = new TemplateMgmtPreviewLetterPage(page); |
| 79 | + |
| 80 | + await previewLetterTemplatePage.loadPage('/fake-template-id'); |
| 81 | + |
| 82 | + await expect(page).toHaveURL(`${baseURL}/templates/invalid-template`); |
| 83 | + }); |
| 84 | + }); |
| 85 | +}); |
0 commit comments