Skip to content
Open
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
6 changes: 5 additions & 1 deletion tests/common/calculators/calculatorsInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const fillHouseholdSize = (page: Page, value: string, label: string = 'Talouden
await page.getByLabel(label).fill(String(value));
});

const fillGrossIncomePerMonth = (page: Page, value: string, label: string = 'Talouden bruttotulot kuukaudessa (euroa)') =>
const fillGrossIncomePerMonth = (
page: Page,
value: string,
label: string = 'Talouden bruttotulot kuukaudessa (euroa)',
) =>
test.step('Fill gross income per month', async () => {
await page.getByLabel(label).fill(String(value));
});
Expand Down
25 changes: 15 additions & 10 deletions tests/sites/emergency-site/staticGeneration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,21 @@ test('Static generation test', async ({ page }) => {
// up to 45 mins for the azure purge process to finish, but content should
// be visible much sooner.
const staticPage = await page.context().newPage();
await expect.poll(async () => {
const response = await staticPage.request.get(staticNewsItemUrl);
return response.status();
}, {
message: 'Make sure news item is eventually visible in static version.',
// Poll every 10 seconds.
intervals: [10 * 1000],
// Use the same timeout as the test.
timeout: timeout,
}).toBe(200);
await expect
.poll(
async () => {
const response = await staticPage.request.get(staticNewsItemUrl);
return response.status();
},
{
message: 'Make sure news item is eventually visible in static version.',
// Poll every 10 seconds.
intervals: [10 * 1000],
// Use the same timeout as the test.
timeout: timeout,
},
)
.toBe(200);

// Remove test content.
await page.goto(announcementUrl);
Expand Down
107 changes: 46 additions & 61 deletions tests/sites/etusivu/globalNavigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ async function apiResponse(language: string, baseURL: string) {
let response: GlobalMenuResponse;

try {
response = await fetchJsonApiRequest<GlobalMenuResponse>(
baseURL,
`/${language}/api/v1/global-mobile-menu`,
);
response = await fetchJsonApiRequest<GlobalMenuResponse>(baseURL, `/${language}/api/v1/global-mobile-menu`);

// Verify that the response contains at least one menu root.
expect(Object.keys(response).length).toBeGreaterThan(0);
Expand Down Expand Up @@ -145,70 +142,58 @@ const navigateMobileMenuDown = async (page: Page, path: MenuLink[]) => {
throw new Error('Cannot navigate an empty path');
}

await test.step(
`Navigate mobile menu down: ${path.map((link) => link.name).join(' → ')}`,
async () => {
// Handle case where path contains only a single panel.
if (path.length === 1) {
const panel = path[0];
await test.step(`Navigate mobile menu down: ${path.map((link) => link.name).join(' → ')}`, async () => {
// Handle case where path contains only a single panel.
if (path.length === 1) {
const panel = path[0];

await test.step(`Assert single panel item is visible: ${panel.name}`, async () => {
const panelLink = page.locator(
`section.mmenu__panel--current a.mmenu__item-link[href="${panel.url}"]`,
);
await test.step(`Assert single panel item is visible: ${panel.name}`, async () => {
const panelLink = page.locator(`section.mmenu__panel--current a.mmenu__item-link[href="${panel.url}"]`);

await expect(panelLink).toBeVisible();
await expect(panelLink.locator('.mmenu__link__text')).toHaveText(panel.name);
});
await expect(panelLink).toBeVisible();
await expect(panelLink.locator('.mmenu__link__text')).toHaveText(panel.name);
});

return;
}
return;
}

// Get all links from path except the last one.
const pathToPanelParent = path.slice(0, -1);
// Get the last link from path.
const panel = path[path.length - 1];

await pathToPanelParent.reduce<Promise<void>>(
async (previous, link) => {
await previous;

await test.step(`Open submenu: ${link.name}`, async () => {
const forwardButton = page.locator(
`section.mmenu__panel--current button.mmenu__forward[value="${link.id}"]`,
);
await forwardButton.click();

// Assert that panel title matches current link.
const title = page.locator('section.mmenu__panel--current .mmenu__title-link');
await expect(title).toHaveAttribute('href', link.url);
await expect(title.locator('.mmenu__link__text')).toHaveText(link.name);
});
},
Promise.resolve(),
);
// Get all links from path except the last one.
const pathToPanelParent = path.slice(0, -1);
// Get the last link from path.
const panel = path[path.length - 1];

// The current panel should contain the final panel from the path.
await test.step(`Assert panel item is visible: ${panel.name}`, async () => {
// Try locating the panel link inside list items.
const panelItem = page.locator(
`section.mmenu__panel--current a.mmenu__item-link[href="${panel.url}"]`,
);

// If found in the list, assert visibility and text.
if (await panelItem.count()) {
await expect(panelItem).toBeVisible();
await expect(panelItem.locator('.mmenu__link__text')).toHaveText(panel.name);
return;
}
await pathToPanelParent.reduce<Promise<void>>(async (previous, link) => {
await previous;

await test.step(`Open submenu: ${link.name}`, async () => {
const forwardButton = page.locator(`section.mmenu__panel--current button.mmenu__forward[value="${link.id}"]`);
await forwardButton.click();

// If the panel link is not in the list, it must be the title link.
const panelTitle = page.locator('section.mmenu__panel--current .mmenu__title-link');
await expect(panelTitle).toHaveAttribute('href', panel.url);
await expect(panelTitle.locator('.mmenu__link__text')).toHaveText(panel.name);
// Assert that panel title matches current link.
const title = page.locator('section.mmenu__panel--current .mmenu__title-link');
await expect(title).toHaveAttribute('href', link.url);
await expect(title.locator('.mmenu__link__text')).toHaveText(link.name);
});
},
);
}, Promise.resolve());

// The current panel should contain the final panel from the path.
await test.step(`Assert panel item is visible: ${panel.name}`, async () => {
// Try locating the panel link inside list items.
const panelItem = page.locator(`section.mmenu__panel--current a.mmenu__item-link[href="${panel.url}"]`);

// If found in the list, assert visibility and text.
if (await panelItem.count()) {
await expect(panelItem).toBeVisible();
await expect(panelItem.locator('.mmenu__link__text')).toHaveText(panel.name);
return;
}

// If the panel link is not in the list, it must be the title link.
const panelTitle = page.locator('section.mmenu__panel--current .mmenu__title-link');
await expect(panelTitle).toHaveAttribute('href', panel.url);
await expect(panelTitle.locator('.mmenu__link__text')).toHaveText(panel.name);
});
});
};

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/sites/etusivu/newsArchive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ test.describe('News archive', () => {
})();

// Get the initial results text.
const initialText = await page.locator(resultSelector).textContent() || '';
const initialText = (await page.locator(resultSelector).textContent()) || '';

await clickSubmitButton(page);
await expectResult(page, initialText, testCase);
Expand Down
19 changes: 11 additions & 8 deletions tests/sites/etusivu/utils/newsArchiveInput.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { expect, type Page, test } from '@playwright/test';
import { DOMParser } from '@xmldom/xmldom';
import type {TestCase } from './newsArchiveTestCases';
import type { TestCase } from './newsArchiveTestCases';

const resultSelector = '.hdbt-search--react__results--title';

/**
* Helper function for the dropdowns on news archive page.
*/
async function fillDropdown(page: Page, selector: string, values: string[]) {
const dropdownButton = page.locator(`.hdbt-search--react__dropdown-filters > *:nth-child(${selector}) button[role="combobox"]`);
const dropdownButton = page.locator(
`.hdbt-search--react__dropdown-filters > *:nth-child(${selector}) button[role="combobox"]`,
);

// Open the dropdown.
await dropdownButton.click();
Expand All @@ -18,7 +20,9 @@ async function fillDropdown(page: Page, selector: string, values: string[]) {
await values.reduce<Promise<void>>(
(chain, value) =>
chain.then(async () => {
const option = page.locator(`.hdbt-search--react__dropdown-filters > *:nth-child(${selector}) li[aria-label="${value}"]`);
const option = page.locator(
`.hdbt-search--react__dropdown-filters > *:nth-child(${selector}) li[aria-label="${value}"]`,
);

// As playwright click won't work for this case, we use evaluate to click the element.
await option.evaluate((el) => {
Expand Down Expand Up @@ -68,7 +72,8 @@ const expectResult = async (page: Page, initialText: string, testCase?: TestCase
await resultLocator.waitFor({ state: 'visible' });

// Check if all filters are null
const areAllFiltersNull = testCase &&
const areAllFiltersNull =
testCase &&
testCase.TEXT_FILTER === null &&
testCase.TOPICS === null &&
testCase.CITY_DISTRICTS === null &&
Expand Down Expand Up @@ -108,9 +113,7 @@ const expectRss = async (page: Page) =>
const rssLink = page.locator('.news-archive__rss-link');

// Make sure the link is visible.
expect(
await rssLink.isVisible()
).toBeTruthy();
expect(await rssLink.isVisible()).toBeTruthy();

// Get the url of the RSS feed from the link.
const rssUrl = await rssLink.getAttribute('href');
Expand All @@ -119,7 +122,7 @@ const expectRss = async (page: Page) =>
// Fetch the RSS feed.
if (rssUrl) {
const response = await page.request.get(rssUrl, {
ignoreHTTPSErrors: true
ignoreHTTPSErrors: true,
});
expect(response.status()).toBe(200);

Expand Down
1 change: 0 additions & 1 deletion tests/sites/etusivu/utils/newsArchiveTestCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ interface TestCase {
TARGET_GROUPS: string[] | null;
}


const testCases: TestCases = [
{
NAME: 'should work without filters',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ async function selectRadioOptionMultiple(group: Locator, option: 'yes_full_servi
await label.click();

const input =
option === 'yes_full_service' ? group.locator('input[type="radio"]').first() : option === 'yes_partial_service' ? group.locator('input[type="radio"]').nth(1) : group.locator('input[type="radio"]').last();
option === 'yes_full_service'
? group.locator('input[type="radio"]').first()
: option === 'yes_partial_service'
? group.locator('input[type="radio"]').nth(1)
: group.locator('input[type="radio"]').last();

await expect(input).toBeChecked();
}
Expand Down Expand Up @@ -82,25 +86,24 @@ const selectMealServiceFull = (page: Page) =>
await selectRadioOptionMultiple(group, 'yes_full_service');
});

const selectMealServicePartial = (page: Page) =>
test.step('Select meal service', async () => {
const group = page.getByRole('group', {
name: 'Laske arvioon ateriapalvelu',
});
const selectMealServicePartial = (page: Page) =>
test.step('Select meal service', async () => {
const group = page.getByRole('group', {
name: 'Laske arvioon ateriapalvelu',
});

await selectRadioOptionMultiple(group, 'yes_partial_service');
});

const selectNoMealService = (page: Page) =>
test.step('Select meal service', async () => {
const group = page.getByRole('group', {
name: 'Laske arvioon ateriapalvelu',
});
const selectNoMealService = (page: Page) =>
test.step('Select meal service', async () => {
const group = page.getByRole('group', {
name: 'Laske arvioon ateriapalvelu',
});

await selectRadioOptionMultiple(group, 'no');
});


export {
selectSafetyPhone,
selectNoSafetyPhone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { expect, test } from '@playwright/test';
import { existsBeforeEach, testUnfilledFields } from '../../../common/calculators/calculatorsCommon';

test.beforeEach(
existsBeforeEach(
'/fi/sosiaali-ja-terveyspalvelut/yhteisollisen-ja-tuetun-asumisen-asiakasmaksulaskuri',
),
existsBeforeEach('/fi/sosiaali-ja-terveyspalvelut/yhteisollisen-ja-tuetun-asumisen-asiakasmaksulaskuri'),
);

test('Test unfilled fields', async ({ page }) => {
Expand Down Expand Up @@ -104,5 +102,3 @@ test('Meal service input must be selected', async ({ page }) => {
await page.getByRole('button', { name: 'Laske arvio' }).click();
expect(await page.getByText('Valinta on pakollinen: Laske arvioon ateriapalvelu.').isVisible()).toBeTruthy();
});


Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { test } from '@playwright/test';
import { clickResultsButton, existsBeforeEach, expectResult } from '../../../common/calculators/calculatorsCommon';
import { fillHouseholdSize, fillGrossIncomePerMonth, fillMonthlyUsage } from '../../../common/calculators/calculatorsInput';
import {
fillHouseholdSize,
fillGrossIncomePerMonth,
fillMonthlyUsage,
} from '../../../common/calculators/calculatorsInput';
import {
selectSafetyPhone,
selectNoSafetyPhone,
Expand Down Expand Up @@ -67,9 +71,7 @@ const TEST_CASES = [

test.describe.configure({ mode: 'parallel' });
test.beforeEach(
existsBeforeEach(
'/fi/sosiaali-ja-terveyspalvelut/yhteisollisen-ja-tuetun-asumisen-asiakasmaksulaskuri',
),
existsBeforeEach('/fi/sosiaali-ja-terveyspalvelut/yhteisollisen-ja-tuetun-asumisen-asiakasmaksulaskuri'),
);

TEST_CASES.forEach((testCase) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { test } from '@playwright/test';
import { clickResultsButton, expectResult, publishedBeforeEach } from '../../../common/calculators/calculatorsCommon';
import { fillHouseholdSize, fillGrossIncomePerMonth, fillMonthlyUsage } from '../../../common/calculators/calculatorsInput';
import {
fillHouseholdSize,
fillGrossIncomePerMonth,
fillMonthlyUsage,
} from '../../../common/calculators/calculatorsInput';

const TEST_CASES = [
{
Expand Down
6 changes: 5 additions & 1 deletion tests/sites/sote/home-care-client-fee/results.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { test } from '@playwright/test';
import { clickResultsButton, expectResult, publishedBeforeEach } from '../../../common/calculators/calculatorsCommon';
import { fillGrossIncomePerMonth, fillHouseholdSize, fillMonthlyUsage } from '../../../common/calculators/calculatorsInput';
import {
fillGrossIncomePerMonth,
fillHouseholdSize,
fillMonthlyUsage,
} from '../../../common/calculators/calculatorsInput';
import {
fillMealServicePerWeek,
selectGroceryDeliveryService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const selectHasSpouseYes = (page: Page) =>
const group = page.getByRole('group', {
name: 'Onko asiakkaalla puolisoa',
});
await selectRadioOption(group, 'yes');
});
await selectRadioOption(group, 'yes');
});

const selectHasSpouseNo = (page: Page) =>
test.step('Select has spouse: no', async () => {
Expand Down Expand Up @@ -132,8 +132,7 @@ const fillSpouseShareOfHousingCosts = (page: Page, value: string) =>
await page.getByLabel('Puolison asumiskulujen omavastuu (euroa)', { exact: true }).fill(String(value));
});


export {
export {
fillEarnedIncome,
fillClientBenefits,
fillCapitalIncome,
Expand All @@ -156,4 +155,4 @@ const fillSpouseShareOfHousingCosts = (page: Page, value: string) =>
fillSpouseMaintenancePayments,
fillSpouseMedicationCosts,
fillSpouseShareOfHousingCosts,
};
};
Loading