Skip to content

Commit

Permalink
UI test for hakukohde and subpages
Browse files Browse the repository at this point in the history
  • Loading branch information
SalamaGofore committed May 8, 2024
1 parent cd0d974 commit eb5df93
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/app/haku/[oid]/hakukohde/[hakukohde]/hakeneet/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function HakeneetPage({

return (
<TabContainer>
<p>Hakeneet</p>
<h3>Hakeneet</h3>
<p>Hakukohde oid: {hakukohde.oid}</p>
</TabContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function HakijaryhmatPage({

return (
<TabContainer>
<p>Hakijaryhmat</p>
<h3>Hakijaryhmat</h3>
<p>Hakukohde oid: {hakukohde.oid}</p>
</TabContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const StyledTabs = styled('div')({
},
});

type BasicTab = {
export type BasicTab = {
title: string;
route: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function HarkinnanvaraisetPage({

return (
<TabContainer>
<p>Harkinnanvaraiset</p>
<h3>Harkinnanvaraiset</h3>
<p>Hakukohde oid: {hakukohde.oid}</p>
</TabContainer>
);
Expand Down
4 changes: 2 additions & 2 deletions src/app/haku/[oid]/hakukohde/[hakukohde]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function HakuLayout({
}) {
return (
<>
<main
<div
className="mainContainer"
style={{
display: 'flex',
Expand All @@ -21,7 +21,7 @@ export default function HakuLayout({
>
<HakukohdeTabs hakukohdeOid={params.hakukohde} />
{children}
</main>
</div>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function PerustiedotTab({

return (
<TabContainer>
<h3>Perustiedot</h3>
<p>Hakukohde oid: {hakukohde.oid}</p>
</TabContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function PisteSyottoPage({

return (
<TabContainer>
<p>Pistesyöttö</p>
<h3>Pistesyöttö</h3>
<p>Hakukohde oid: {hakukohde.oid}</p>
</TabContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function SijoittelunTuloksetPage({

return (
<TabContainer>
<p>Sijoittelun Tulokset</p>
<h3>Sijoittelun tulokset</h3>
<p>Hakukohde oid: {hakukohde.oid}</p>
</TabContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ValinnanHallintaPage({

return (
<TabContainer>
<p>Valinnan Hallinta</p>
<h3>Valinnan hallinta</h3>
<p>Hakukohde oid: {hakukohde.oid}</p>
</TabContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ValintakoekutsutPage({

return (
<TabContainer>
<p>Valintakoekutsut</p>
<h3>Valintakoekutsut</h3>
<p>Hakukohde oid: {hakukohde.oid}</p>
</TabContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ValintalaskennanTulosPage({

return (
<TabContainer>
<p>Valintalaskennan Tulos</p>
<h3>Valintalaskennan tulos</h3>
<p>Hakukohde oid: {hakukohde.oid}</p>
</TabContainer>
);
Expand Down
75 changes: 75 additions & 0 deletions tests/e2e/hakukohde.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { test, expect } from '@playwright/test';
import {
expectAllSpinnersHidden,
expectPageAccessibilityOk,
} from './playwright-utils';
import { BasicTab } from '@/app/haku/[oid]/hakukohde/[hakukohde]/hakukohde-tabs';

const ToinenAsteTabs: BasicTab[] = [
{ title: 'Hakeneet', route: 'hakeneet' },
{ title: 'Valinnan hallinta', route: 'valinnan-hallinta' },
{ title: 'Valintakoekutsut', route: 'valintakoekutsut' },
{ title: 'Pistesyöttö', route: 'pistesyotto' },
{ title: 'Harkinnanvaraiset', route: 'harkinnanvaraiset' },
{ title: 'Valintalaskennan tulos', route: 'valintalaskennan-tulos' },
{ title: 'Sijoittelun tulokset', route: 'sijoittelun-tulokset' },
];

test.beforeEach(async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle(/Valintojen Toteuttaminen/);
});

test('navigates to hakukohde tabs', async ({ page }) => {
await page.goto(
'/valintojen-toteuttaminen/haku/1.2.246.562.29.00000000000000045102',
);
await expect(page.locator('h1')).toHaveText(
'> Tampere University Separate Admission/ Finnish MAOL Competition Route 2024',
);
await expect(page.locator('.organizationLabel')).toHaveCount(3);
await page.locator('.organizationLabel').first().click();
await expect(page.locator('h2.organisaatioLabel')).toHaveText(
'Tampereen yliopisto, Rakennetun ympäristön tiedekunta',
);
await expect(page.locator('h2.hakukohdeLabel')).toHaveText(
'Finnish MAOL competition route, Technology, Sustainable Urban Development, Bachelor and Master of Science (Technology) (3 + 2 yrs)',
);
await expect(page.locator('h3')).toHaveText('Perustiedot');
});

test('Hakukohde-page accessibility', async ({ page }) => {
await page.goto(
'/valintojen-toteuttaminen/haku/1.2.246.562.29.00000000000000045102/hakukohde/1.2.246.562.20.00000000000000045105/perustiedot',
);
await expectAllSpinnersHidden(page);
await expectPageAccessibilityOk(page);
});

test.describe('Hakukohde tabs', () => {
for (const tab of ToinenAsteTabs) {
test(`Navigates to ${tab.title}`, async ({ page }) => {
await page.goto(
'/valintojen-toteuttaminen/haku/1.2.246.562.29.00000000000000045102',
);
await page.locator('.organizationLabel').first().click();
await page.getByText(tab.title).click();
await expect(page.locator('h3')).toHaveText(tab.title);
});

test(`Navigates directly to ${tab.title}`, async ({ page }) => {
await page.goto(
`/valintojen-toteuttaminen/haku/1.2.246.562.29.00000000000000045102/hakukohde/1.2.246.562.20.00000000000000045105/${tab.route}`,
);
await expect(page.locator('h3')).toHaveText(tab.title);
});

test(`${tab.title} page accessibility`, async ({ page }) => {
await page.goto(
`/valintojen-toteuttaminen/haku/1.2.246.562.29.00000000000000045102/hakukohde/1.2.246.562.20.00000000000000045105/${tab.route}`,
);
await expectAllSpinnersHidden(page);
await expectPageAccessibilityOk(page);
});
}
});
7 changes: 7 additions & 0 deletions tests/e2e/playwright.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export default async function playwrightSetup() {
);
response.end();
return;
} else if (request.url.includes('kouta-internal/hakukohde/')) {
const hakukohdeOid = request.url.split('/').reverse()[0];
response.write(
JSON.stringify(HAKUKOHTEET.find((hk) => hk.oid === hakukohdeOid)),
);
response.end();
return;
} else if (request.url.includes(`kouta-internal/haku/`)) {
const hakuId = request.url.split('haku/')[1];
const haku = HAUT.find((hakuData) => hakuData.oid === hakuId);
Expand Down

0 comments on commit eb5df93

Please sign in to comment.