-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ea1c61
commit ae1099c
Showing
10 changed files
with
340 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,7 @@ bower_components | |
|
||
# tests | ||
report/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
const API_URL = process.env.API_URL || 'https://kerrokantasi.api.dev.hel.ninja'; | ||
|
||
const fetchHearing = async () => { | ||
const res = await fetch(`${API_URL}/v1/hearing/`); | ||
const json = await res.json(); | ||
const openHearings = json.results.filter((hearing) => !hearing.closed); | ||
const hearingId = openHearings[0].id; | ||
const hearing = await fetch(`${API_URL}/v1/hearing/${hearingId}/`); | ||
|
||
return hearing.json(); | ||
}; | ||
|
||
const hearingContainsQuestions = (hearing) => Boolean(hearing.sections.some((s) => s.questions.length)); | ||
|
||
test.describe('Hearing', () => { | ||
let page; | ||
let hearing; | ||
|
||
test.beforeAll(async ({ browser }) => { | ||
hearing = await fetchHearing(); | ||
page = await browser.newPage(); | ||
await page.goto(hearing.slug); | ||
await page.getByTestId('cookie-consent-approve-required-button').click(); | ||
}); | ||
|
||
test.beforeEach(async () => { | ||
await page.goto(hearing.slug); | ||
}); | ||
|
||
test('should display Finnish title', async () => { | ||
await expect(page.locator('main')).toContainText(hearing.title.fi); | ||
}); | ||
|
||
test('should have comment link', async () => { | ||
const link = page.locator('.internal-link:has-text("Kirjoita kommentti")'); | ||
await expect(link).toBeVisible(); | ||
}); | ||
|
||
test('should display comment count', async () => { | ||
await expect(page.getByTestId('comment-summary')).toContainText(`Yhteensä ${hearing.n_comments} kommentti`); | ||
}); | ||
|
||
test('should have Swedish link if available', async () => { | ||
const noSwedishTitle = !hearing.title.sv; | ||
test.skip(noSwedishTitle, 'No Swedish title available'); | ||
|
||
await expect(page.getByTestId('language-select')).toContainText('Hörandet tillgängligt på svenska'); | ||
}); | ||
|
||
test('should have English link if available', async () => { | ||
const noEnglishTitle = !hearing.title.en; | ||
test.skip(noEnglishTitle, 'No English title available'); | ||
|
||
await expect(page.getByTestId('language-select')).toContainText('Hearing available in English'); | ||
}); | ||
|
||
test('should display label', async () => { | ||
const firstFinnishLabel = hearing.labels[0].label.fi; | ||
|
||
if (firstFinnishLabel) { | ||
await expect(page.locator('[aria-label="Asiasanat"]')).toContainText(firstFinnishLabel); | ||
} | ||
}); | ||
|
||
test('should display contact person name', async () => { | ||
const contactPerson = hearing.contact_persons[0]; | ||
await expect(page.locator('.hearing-contacts')).toContainText(contactPerson.name); | ||
}); | ||
|
||
test('should have image with caption', async () => { | ||
const img = page.locator('.section-image img'); | ||
await expect(img).toHaveAttribute('alt', hearing.main_image.caption.fi); | ||
}); | ||
|
||
test('should have Excel link for comment summary', async () => { | ||
const link = page.locator('a:has-text("Lataa yhteenveto kommenteista Excel-muodossa")'); | ||
await expect(link).toBeVisible(); | ||
}); | ||
|
||
test('should have comment button', async () => { | ||
const button = page.locator('.comment-form-container button'); | ||
await expect(button).toBeVisible(); | ||
}); | ||
|
||
test('verify visibility of questions and their options', async () => { | ||
test.skip(!hearingContainsQuestions(hearing), 'No questions found'); | ||
|
||
await page.getByRole('button', { name: 'Äänestä ja kommentoi' }).last().click(); | ||
|
||
const mainSection = hearing.sections.find((s) => s.type === 'main'); | ||
test.skip(!mainSection, 'No main section found'); | ||
const firstQuestion = mainSection.questions[0]; | ||
const questionText = firstQuestion.text.fi; | ||
const options = firstQuestion.options.map((o) => o.text.fi); | ||
await expect(page.locator('.comment-form')).toContainText(questionText); | ||
await expect(page.getByTestId('question-form-group').locator('.radio')).toContainText(options); | ||
}); | ||
|
||
test('user can successfully submit a comment', async () => { | ||
await page.locator('.comment-form-container button').click(); | ||
await page.locator('.comment-form textarea').fill('Tämä on selaintestin kirjoittama viesti'); | ||
await page.getByPlaceholder('Anonyymi').fill('Testi Testinen'); | ||
await page.getByRole('button', { name: 'Lähetä' }).click(); | ||
await expect(page.getByText('Kommenttisi on vastaanotettu')).toBeVisible(); | ||
}); | ||
|
||
test('check Finnish title in first subsection if subsections exist', async () => { | ||
const hasSectionCard = hearing.sections.filter((s) => s.type === 'part').length > 0; | ||
test.skip(!hasSectionCard, 'Hearing does not contain subsections'); | ||
|
||
if (hasSectionCard) { | ||
const button = await page.locator('.section-card button').first(); | ||
await button.click(); | ||
|
||
const partSection = hearing.sections.find((s) => s.type === 'part'); | ||
await expect(page.locator('main')).toContainText(partSection.title.fi); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('Hearing list page', () => { | ||
let page; | ||
|
||
test.beforeAll(async ({ browser }) => { | ||
page = await browser.newPage(); | ||
await page.goto('/hearings/list?lang=fi'); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await page.close(); | ||
}); | ||
|
||
test('should have correct title', async () => { | ||
await expect(page).toHaveTitle(/.*kuulemiset/); | ||
}); | ||
|
||
test('should display all headings', async () => { | ||
await expect(page.getByRole('heading', { name: 'Kaikki kuulemiset' })).toBeVisible(); | ||
}); | ||
|
||
test('should have search controls visibility', async () => { | ||
await expect.soft(page.getByText('Etsi otsikoista')).toBeVisible(); | ||
await expect.soft(page.getByText('Hae aiheista')).toBeVisible(); | ||
await expect.soft(page.getByRole('button', { name: 'Etsi', exact: true })).toBeEnabled(); | ||
}); | ||
|
||
test('should perform a search', async () => { | ||
const searchTextInput = page.getByRole('combobox', { name: 'Etsi otsikoista' }); | ||
|
||
// Check the default state of the select input | ||
const input = page.locator('#formControlsSearchSelect'); | ||
await expect.soft(input).toHaveValue(''); | ||
|
||
// Perform a search and validate the input value | ||
const SEARCH_TEXT = 'Hello'; | ||
await searchTextInput.fill(SEARCH_TEXT); | ||
await expect(searchTextInput).toHaveValue(SEARCH_TEXT); | ||
}); | ||
|
||
test('swedish translations', async () => { | ||
await page.goto('/hearings/list?lang=sv'); | ||
|
||
await expect(page).toHaveTitle(/.*Alla höranden/); | ||
await expect(page.getByRole('heading', { name: 'Alla höranden' })).toBeVisible(); | ||
await expect.soft(page.getByRole('button', { name: 'Sök', exact: true })).toBeEnabled(); | ||
await expect.soft(page.getByText('Sök bland rubrikerna')).toBeVisible(); | ||
await expect.soft(page.getByText('Sök bland ämnena')).toBeVisible(); | ||
}); | ||
|
||
test('english translations', async () => { | ||
await page.goto('/hearings/list?lang=en'); | ||
|
||
await expect(page).toHaveTitle(/.*All hearings/); | ||
await expect(page.getByRole('heading', { name: 'All hearings' })).toBeVisible(); | ||
await expect.soft(page.getByRole('button', { name: 'Search', exact: true })).toBeEnabled(); | ||
await expect.soft(page.getByText('Search from titles')).toBeVisible(); | ||
await expect.soft(page.getByText('Search labels')).toBeVisible(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,52 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('Info page', () => { | ||
let page; | ||
|
||
test.beforeAll(async ({ browser }) => { | ||
page = await browser.newPage(); | ||
test.describe('Info page - Fi', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/info?lang=fi'); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await page.close(); | ||
test('Title', async ({ page }) => { | ||
await expect(page).toHaveTitle(/.*Tietoa palvelusta/); | ||
}); | ||
|
||
test('Title', async () => { | ||
const pageTitle = await page.title(); | ||
expect(pageTitle).toContain('Tietoa palvelusta'); | ||
test('Headings', async ({ page }) => { | ||
await expect(page.getByRole('heading', { name: 'Tietoa Kerrokantasi.hel.fi' })).toBeVisible(); | ||
await expect(page.getByRole('heading', { name: 'Palvelun käyttö' })).toBeVisible(); | ||
await expect(page.getByRole('heading', { name: 'Tietosuoja' })).toBeVisible(); | ||
await expect(page.getByRole('heading', { name: 'Evästeet' })).toBeVisible(); | ||
}); | ||
}); | ||
|
||
test('Headings', async () => { | ||
await expect(page.getByRole('heading', { name: 'Tietoa Kerrokantasi.hel.fi' })).toBeVisible(); | ||
test.describe('Info page - Sv', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/info?lang=sv'); | ||
}); | ||
|
||
test('Title', async ({ page }) => { | ||
await expect(page).toHaveTitle(/.*Information om tjänsten/); | ||
}); | ||
|
||
test('Headings', async ({ page }) => { | ||
await expect(page.getByRole('heading', { name: 'Information om tjänsten Kerrokantasi' })).toBeVisible(); | ||
await expect(page.getByRole('heading', { name: 'Använda tjänsten' })).toBeVisible(); | ||
await expect(page.getByRole('heading', { name: 'Dataskyddsbeskrivning' })).toBeVisible(); | ||
await expect(page.getByRole('heading', { name: 'Om kakor' })).toBeVisible(); | ||
}); | ||
}); | ||
|
||
test.describe('Info page - En', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/info?lang=en'); | ||
}); | ||
|
||
test('Title', async ({ page }) => { | ||
await expect(page).toHaveTitle(/.*About service/); | ||
}); | ||
|
||
test('Headings', async ({ page }) => { | ||
await expect(page.getByRole('heading', { name: 'Terms of use for the Kerrokantasi service' })).toBeVisible(); | ||
await expect(page.getByRole('heading', { name: 'Using the service' })).toBeVisible(); | ||
await expect(page.getByRole('heading', { name: 'Data protection notices' })).toBeVisible(); | ||
await expect(page.getByRole('heading', { name: 'About cookies' })).toBeVisible(); | ||
}); | ||
}); |
Oops, something went wrong.