|
| 1 | +import { expect, Locator, type Page } from '@playwright/test' |
| 2 | + |
| 3 | +export class AuthErrorPage { |
| 4 | + readonly page: Page |
| 5 | + readonly heading: Locator |
| 6 | + readonly errorLine: Locator |
| 7 | + readonly errorText: Locator |
| 8 | + readonly subText: Locator |
| 9 | + readonly backButton: Locator |
| 10 | + readonly errorBorder: Locator |
| 11 | + readonly relatedLinksSidebar: Locator |
| 12 | + readonly relatedLinksFooter: Locator |
| 13 | + readonly announcements: Locator |
| 14 | + |
| 15 | + constructor(page: Page) { |
| 16 | + this.page = page |
| 17 | + this.heading = this.page.locator('main').getByRole('heading', { level: 1 }) |
| 18 | + this.errorLine = this.page.locator('.text-red').first() |
| 19 | + this.errorText = this.page.locator('.border-l-red').locator('[data-testid="rich-text"]').first() |
| 20 | + this.subText = this.page.locator('main').locator('[data-testid="rich-text"]').nth(1) |
| 21 | + this.backButton = this.page.getByRole('link', { name: /back/i }) |
| 22 | + this.errorBorder = this.page.locator('.border-l-\\[9px\\].border-l-red') |
| 23 | + this.relatedLinksSidebar = this.page.locator('.govuk-grid-column-one-quarter-from-desktop') |
| 24 | + this.relatedLinksFooter = this.page.locator('main > div:last-child') |
| 25 | + this.announcements = this.page.locator('[data-testid="announcements"]') |
| 26 | + } |
| 27 | + |
| 28 | + async goto(slug: string = 'authentication-error') { |
| 29 | + await this.page.goto(`/${slug}`) |
| 30 | + } |
| 31 | + |
| 32 | + async isAuthErrorPage(slug: string = 'authentication-error') { |
| 33 | + await expect(this.page).toHaveURL(new RegExp(`/${slug}/?$`)) |
| 34 | + } |
| 35 | + |
| 36 | + async checkHeadingExists(expectedText: string) { |
| 37 | + await expect(this.heading).toBeVisible() |
| 38 | + await expect(this.heading).toHaveText(expectedText) |
| 39 | + } |
| 40 | + |
| 41 | + async checkErrorLineExists(expectedText: string) { |
| 42 | + await expect(this.errorLine).toBeVisible() |
| 43 | + await expect(this.errorLine).toHaveText(expectedText) |
| 44 | + } |
| 45 | + |
| 46 | + async checkErrorTextExists() { |
| 47 | + await expect(this.errorText).toBeVisible() |
| 48 | + } |
| 49 | + |
| 50 | + async checkSubTextExists() { |
| 51 | + await expect(this.subText).toBeVisible() |
| 52 | + } |
| 53 | + |
| 54 | + async checkBackButtonExists() { |
| 55 | + await expect(this.backButton).toBeVisible() |
| 56 | + } |
| 57 | + |
| 58 | + async checkBackButtonHasCorrectHref() { |
| 59 | + await expect(this.backButton).toHaveAttribute('href', '/start') |
| 60 | + } |
| 61 | + |
| 62 | + async clickBackButton() { |
| 63 | + await this.backButton.click() |
| 64 | + } |
| 65 | + |
| 66 | + async checkErrorBorderStyling() { |
| 67 | + await expect(this.errorBorder).toBeVisible() |
| 68 | + await expect(this.errorBorder).toHaveClass(/border-l-\[9px\]/) |
| 69 | + await expect(this.errorBorder).toHaveClass(/border-l-red/) |
| 70 | + await expect(this.errorBorder).toHaveClass(/pl-9/) |
| 71 | + } |
| 72 | + |
| 73 | + async checkRelatedLinksSidebarExists() { |
| 74 | + await expect(this.relatedLinksSidebar).toBeVisible() |
| 75 | + } |
| 76 | + |
| 77 | + async checkRelatedLinksSidebarNotExists() { |
| 78 | + await expect(this.relatedLinksSidebar).not.toBeVisible() |
| 79 | + } |
| 80 | + |
| 81 | + async checkRelatedLinksFooterExists() { |
| 82 | + const footerLinks = this.page.locator('[data-testid="related-links-footer"]') |
| 83 | + await expect(footerLinks).toBeVisible() |
| 84 | + } |
| 85 | + |
| 86 | + async checkRelatedLinksFooterNotExists() { |
| 87 | + const footerLinks = this.page.locator('[data-testid="related-links-footer"]') |
| 88 | + await expect(footerLinks).not.toBeVisible() |
| 89 | + } |
| 90 | + |
| 91 | + async checkAnnouncementsExist() { |
| 92 | + await expect(this.announcements).toBeVisible() |
| 93 | + } |
| 94 | + |
| 95 | + async checkAnnouncementsCount(expectedCount: number) { |
| 96 | + const announcements = this.page.locator('[role="alert"]') |
| 97 | + await expect(announcements).toHaveCount(expectedCount) |
| 98 | + } |
| 99 | + |
| 100 | + async hasMainContent() { |
| 101 | + await expect(this.page.locator('main')).toBeVisible() |
| 102 | + } |
| 103 | + |
| 104 | + async checkBackButtonIcon() { |
| 105 | + const svg = this.backButton.locator('svg') |
| 106 | + await expect(svg).toBeVisible() |
| 107 | + await expect(svg).toHaveAttribute('width', '20') |
| 108 | + await expect(svg).toHaveAttribute('height', '20') |
| 109 | + } |
| 110 | + |
| 111 | + async checkPageContainsText(text: string) { |
| 112 | + await expect(this.page.locator('main')).toContainText(text) |
| 113 | + } |
| 114 | + |
| 115 | + async checkRelatedLinksCount(count: number) { |
| 116 | + const links = this.page.locator('[data-testid*="related-links"] a') |
| 117 | + await expect(links).toHaveCount(count) |
| 118 | + } |
| 119 | + |
| 120 | + async clickRelatedLink(linkText: string) { |
| 121 | + await this.page.getByRole('link', { name: linkText }).click() |
| 122 | + } |
| 123 | +} |
0 commit comments