Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 11 additions & 37 deletions e2e/pages/results.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,42 +70,16 @@ export const sw1in30PdText =
// Risk profiles
export const riskIntro = 'In your proposed development site there is a risk of flooding from:'
const surfaceWaterRisk = 'surface water'
export const riskProfilesSection = '[data-testid="risk-profiles"]' // Selector for the risk profiles section
export const riskProfiles = {
surfaceWater: [riskIntro, surfaceWaterRisk],
fluvialAndSurfaceWater: [riskIntro, 'rivers (fluvial)', surfaceWaterRisk],
tidalAndSurfaceWater: [riskIntro, 'the sea (tidal)', surfaceWaterRisk],
fluvialTidalAndSurfaceWater: [riskIntro, 'rivers and the sea (fluvial and tidal)', surfaceWaterRisk],
fluvialAndTidal: [riskIntro, 'rivers and the sea (fluvial and tidal)'],
fluvial: [riskIntro, 'rivers (fluvial)'],
tidal: [riskIntro, 'the sea (tidal)'],
climateChange: [riskIntro, 'rivers and the sea (fluvial or tidal) due to climate change'],
climateChangeAndSurfaceWater: [riskIntro, 'rivers and the sea (fluvial or tidal) due to climate change', surfaceWaterRisk]
}
export const allRiskLines = [...new Set(Object.values(riskProfiles).flat().filter((line) => line !== riskIntro))]

// Risk profile assertion
export const expectRiskProfileTexts = async (page, expectedTexts, allTexts) => {
const { expect } = await import('@playwright/test')
const main = page.getByRole('main')
const [introText, ...expectedRiskItems] = expectedTexts

const riskIntroLocator = main.getByText(introText, { exact: true }).first()
await expect(riskIntroLocator).toBeVisible()

// Risk lines are shown in the first list within the same content block as the intro text.
const riskList = riskIntroLocator.locator('..').getByRole('list').first()

await expect(riskList).toBeVisible()

for (const text of expectedRiskItems) {
await expect(riskList.getByText(text, { exact: true })).toBeVisible()
}

const allRiskItems = allTexts.filter((text) => text !== introText)
for (const text of allRiskItems) {
if (!expectedRiskItems.includes(text)) {
await expect(riskList.getByText(text, { exact: true })).toHaveCount(0)
}
}
surfaceWater: [surfaceWaterRisk],
fluvialAndSurfaceWater: ['rivers (fluvial)', surfaceWaterRisk],
tidalAndSurfaceWater: ['the sea (tidal)', surfaceWaterRisk],
fluvialTidalAndSurfaceWater: ['rivers and the sea (fluvial and tidal)', surfaceWaterRisk],
fluvialAndTidal: ['rivers and the sea (fluvial and tidal)'],
fluvial: ['rivers (fluvial)'],
tidal: ['the sea (tidal)'],
climateChange: ['rivers and the sea (fluvial or tidal) due to climate change'],
climateChangeAndSurfaceWater: ['rivers and the sea (fluvial or tidal) due to climate change', surfaceWaterRisk]
}
export const allRiskLines = [...new Set(Object.values(riskProfiles).flat())]
export const riskProfilesSection = '#riskFloodingFrom + ul' // locator for risk profiles list, used to scope text assertions
27 changes: 20 additions & 7 deletions e2e/test-runner-api/form-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ export class FormDriver {
await expect(this.page.getByRole('heading', { name: pageDef.title, exact: true })).toBeVisible()
}

async expectText (text) {
await expect(this.page.getByRole('main')).toContainText(text)
async expectText (text, scope) {
await expect(this.#getTextScope(scope)).toContainText(text)
}

async expectTextNotExists (text) {
await expect(this.page.getByRole('main')).not.toContainText(text)
async expectTextNotExists (text, scope) {
await expect(this.#getTextScope(scope)).not.toContainText(text)
}

async expectOnlyTexts (expectedTexts, allTexts) {
async expectOnlyTexts (expectedTexts, allTexts, scope) {
for (const text of allTexts) {
if (expectedTexts.includes(text)) {
await this.expectText(text)
await this.expectText(text, scope)
} else {
await this.expectTextNotExists(text)
await this.expectTextNotExists(text, scope)
}
}
}
Expand Down Expand Up @@ -166,4 +166,17 @@ export class FormDriver {
}
throw new Error(`Unsupported link type '${link.type}'`)
}

#getTextScope (scope) {
if (!scope) {
return this.page.getByRole('main')
}
if (typeof scope === 'string') {
return this.page.locator(scope)
}
if (typeof scope === 'object' && typeof scope.locator === 'function') {
return scope
}
throw new Error(`Unsupported text scope '${String(scope)}'`)
}
}
9 changes: 6 additions & 3 deletions e2e/tests/pages/results-page-conditional-content.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,24 @@ test.describe('Results page - Flood zone 2 and 3 content', () => {
await steps.open(pages.results.pageForPolygon('2', floodZonedata.FZ2_With_SW_and_S_and_R))
await steps.expectText(pages.results.fraRequiredText)
await steps.expectLinkExists(pages.results.orderFloodRiskDataButton)
await pages.results.expectRiskProfileTexts(steps.page, pages.results.riskProfiles.fluvialTidalAndSurfaceWater, pages.results.allRiskLines)
await steps.expectText(pages.results.riskIntro)
await steps.expectOnlyTexts(pages.results.riskProfiles.fluvialTidalAndSurfaceWater, pages.results.allRiskLines, pages.results.riskProfilesSection)
})

test('shows FRA required messaging and order flood risk data link in Flood Zone 3 with fluvial and surface water', async ({ steps }) => {
await steps.open(pages.results.pageForPolygon('3', floodZonedata.FZ3_With_SW_and_R))
await steps.expectText(pages.results.fraRequiredText)
await steps.expectLinkExists(pages.results.orderFloodRiskDataButton)
await pages.results.expectRiskProfileTexts(steps.page, pages.results.riskProfiles.fluvialAndSurfaceWater, pages.results.allRiskLines)
await steps.expectText(pages.results.riskIntro)
await steps.expectOnlyTexts(pages.results.riskProfiles.fluvialAndSurfaceWater, pages.results.allRiskLines, pages.results.riskProfilesSection)
})

test('shows FRA required messaging and order flood risk data link in Flood Zone 3 with fluvial only', async ({ steps }) => {
await steps.open(pages.results.pageForPolygon('3', floodZonedata.FZ3_With_R))
await steps.expectText(pages.results.fraRequiredText)
await steps.expectLinkExists(pages.results.orderFloodRiskDataButton)
await pages.results.expectRiskProfileTexts(steps.page, pages.results.riskProfiles.fluvial, pages.results.allRiskLines)
await steps.expectText(pages.results.riskIntro)
await steps.expectOnlyTexts(pages.results.riskProfiles.fluvial, pages.results.allRiskLines, pages.results.riskProfilesSection)
})
})

Expand Down
Loading