From d0b85c072218ec3ee586718dee678ad978b99649 Mon Sep 17 00:00:00 2001 From: Aaro Koivukangas Date: Mon, 27 Jul 2026 19:23:32 +0300 Subject: [PATCH] [Playwright] Change playwright to under e2e --- .gitignore | 2 + .../Completed_courses.ts | 5 +- {playwright => e2e}/Course_statistics.js | 0 {playwright => e2e}/Custom_population.js | 0 .../Degree_programme_overview.js | 0 {playwright => e2e}/Faculty_statistics.js | 0 {playwright => e2e}/Filters.js | 0 {playwright => e2e}/Language_center.js | 0 {playwright => e2e}/Numbers_match.js | 0 {playwright => e2e}/Population_statistics.js | 0 {playwright => e2e}/Routes.js | 0 {playwright => e2e}/Students.js | 0 {playwright => e2e}/Study_guidance_groups.js | 0 {playwright => e2e}/Teachers.js | 0 {playwright => e2e}/University.js | 0 {playwright => e2e}/plugins/index.js | 0 e2e/support/commands.ts | 91 +++++++++++++++++++ {playwright => e2e}/support/e2e.js | 0 playwright/Users.js | 79 ---------------- playwright/support/commands.js | 0 20 files changed, 97 insertions(+), 80 deletions(-) rename playwright/Completed_courses.js => e2e/Completed_courses.ts (99%) rename {playwright => e2e}/Course_statistics.js (100%) rename {playwright => e2e}/Custom_population.js (100%) rename {playwright => e2e}/Degree_programme_overview.js (100%) rename {playwright => e2e}/Faculty_statistics.js (100%) rename {playwright => e2e}/Filters.js (100%) rename {playwright => e2e}/Language_center.js (100%) rename {playwright => e2e}/Numbers_match.js (100%) rename {playwright => e2e}/Population_statistics.js (100%) rename {playwright => e2e}/Routes.js (100%) rename {playwright => e2e}/Students.js (100%) rename {playwright => e2e}/Study_guidance_groups.js (100%) rename {playwright => e2e}/Teachers.js (100%) rename {playwright => e2e}/University.js (100%) rename {playwright => e2e}/plugins/index.js (100%) create mode 100644 e2e/support/commands.ts rename {playwright => e2e}/support/e2e.js (100%) delete mode 100644 playwright/Users.js delete mode 100644 playwright/support/commands.js diff --git a/.gitignore b/.gitignore index 7623ffec2..2c29e34ba 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ yarn-error.log* lerna-debug.log* .pnpm-debug.log* +test-results + # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json diff --git a/playwright/Completed_courses.js b/e2e/Completed_courses.ts similarity index 99% rename from playwright/Completed_courses.js rename to e2e/Completed_courses.ts index db778f530..9dddda001 100644 --- a/playwright/Completed_courses.js +++ b/e2e/Completed_courses.ts @@ -1,24 +1,27 @@ import { test, expect } from '@playwright/test' -/// const openCompletedCoursesModal = async page => { page.locator('text=button', 'text=Search completed courses of students').click() } + const hasLanded = async page => { cy.contains('Search completed courses') cy.contains( 'Here you can search by a list of student and course numbers to see whether students have completed certain courses yet' ) } + const openSearch = async page => { cy.init('/completedcoursessearch') hasLanded(page) } + const selectSavedCourselist = async (page, name) => { cy.cs('history-search').click() cy.cs('history-search').type(name) cy.cs('history-search').type('{downarrow}') cy.cs('history-search').type('{enter}') } + const createCourseList = async (page, courseCodes, courseListName) => { openSearch(page) openCompletedCoursesModal(page) diff --git a/playwright/Course_statistics.js b/e2e/Course_statistics.js similarity index 100% rename from playwright/Course_statistics.js rename to e2e/Course_statistics.js diff --git a/playwright/Custom_population.js b/e2e/Custom_population.js similarity index 100% rename from playwright/Custom_population.js rename to e2e/Custom_population.js diff --git a/playwright/Degree_programme_overview.js b/e2e/Degree_programme_overview.js similarity index 100% rename from playwright/Degree_programme_overview.js rename to e2e/Degree_programme_overview.js diff --git a/playwright/Faculty_statistics.js b/e2e/Faculty_statistics.js similarity index 100% rename from playwright/Faculty_statistics.js rename to e2e/Faculty_statistics.js diff --git a/playwright/Filters.js b/e2e/Filters.js similarity index 100% rename from playwright/Filters.js rename to e2e/Filters.js diff --git a/playwright/Language_center.js b/e2e/Language_center.js similarity index 100% rename from playwright/Language_center.js rename to e2e/Language_center.js diff --git a/playwright/Numbers_match.js b/e2e/Numbers_match.js similarity index 100% rename from playwright/Numbers_match.js rename to e2e/Numbers_match.js diff --git a/playwright/Population_statistics.js b/e2e/Population_statistics.js similarity index 100% rename from playwright/Population_statistics.js rename to e2e/Population_statistics.js diff --git a/playwright/Routes.js b/e2e/Routes.js similarity index 100% rename from playwright/Routes.js rename to e2e/Routes.js diff --git a/playwright/Students.js b/e2e/Students.js similarity index 100% rename from playwright/Students.js rename to e2e/Students.js diff --git a/playwright/Study_guidance_groups.js b/e2e/Study_guidance_groups.js similarity index 100% rename from playwright/Study_guidance_groups.js rename to e2e/Study_guidance_groups.js diff --git a/playwright/Teachers.js b/e2e/Teachers.js similarity index 100% rename from playwright/Teachers.js rename to e2e/Teachers.js diff --git a/playwright/University.js b/e2e/University.js similarity index 100% rename from playwright/University.js rename to e2e/University.js diff --git a/playwright/plugins/index.js b/e2e/plugins/index.js similarity index 100% rename from playwright/plugins/index.js rename to e2e/plugins/index.js diff --git a/e2e/support/commands.ts b/e2e/support/commands.ts new file mode 100644 index 000000000..ac42d3627 --- /dev/null +++ b/e2e/support/commands.ts @@ -0,0 +1,91 @@ +// ! IMPORTANT: here we need to set keys to be all lowercase, since +// ! we're replacing headers after they've left browser / frontend. + +import { Page } from '@playwright/test' + +// All of these users are available in anon user-db +const adminUserHeaders = { + uid: 'admin', + displayname: 'Admin User', + 'shib-session-id': 'mock-cypress-session', + hygroupcn: 'grp-oodikone-users;grp-oodikone-basic-users;grp-toska', + mail: 'grp-toska+mockadminuser@helsinki.fi', + hypersonsisuid: 'hy-hlo-6666666', +} + +const basicUserHeaders = { + uid: 'basic', + displayname: 'Basic User', + 'shib-session-id': 'mock-cypress-session', + hygroupcn: 'grp-oodikone-users;grp-oodikone-basic-users', + mail: 'grp-toska+mockbasicuser@helsinki.fi', + hypersonsisuid: 'hy-hlo-1234567', +} + +const onlycoursestatisticsUserHeaders = { + uid: 'onlycoursestatistics', + displayname: 'Onlycoursestatistics User', + 'shib-session-id': 'mock-cypress-session', + hygroupcn: 'grp-oodikone-basic-users', + mail: 'grp-toska+mockonlycoursestatisticsuser@helsinki.fi', + hypersonsisuid: 'hy-hlo-7654321', +} + +const norightsUserHeaders = { + uid: 'norights', + displayname: 'Norights User', + 'shib-session-id': 'mock-cypress-session', + hygroupcn: 'grp-oodikone-users', + mail: 'grp-toska+mocknorightuser@helsinki.fi', + hypersonsisuid: 'hy-hlo-0000000', +} + +const onlyIamRightsUserHeaders = { + uid: 'onlyiamrights', + displayname: 'Only IAM rights user', + 'shib-session-id': 'mock-cypress-session', + hygroupcn: 'hy-employees;hy-mltdk-mat-jory', + mail: 'grp-toska+mockonlyiamrightsuser@helsinki.fi', + hypersonsisuid: 'hy-hlo-1111111', +} + +// Also has element detail of "KH50_005" for the study guidance groups to work +const onlyStudyGuidanceGroupsUser = { + uid: 'onlystudyguidancegroups', + displayname: 'Study Guidance Groups User', + 'shib-session-id': 'mock-cypress-session', + hygroupcn: 'grp-oodikone-users', + mail: 'grp-toska+mockonlystudyguidancegroupsuser@helsinki.fi', + hypersonsisuid: 'hy-hlo-2222222', +} + +export const userHeaders = [ + adminUserHeaders, + basicUserHeaders, + onlycoursestatisticsUserHeaders, + norightsUserHeaders, + onlyIamRightsUserHeaders, + onlyStudyGuidanceGroupsUser, +] + +type UserId = 'admin' | 'basic' | 'onlycoursestatistics' | 'norights' | 'onlyiamrights' | 'onlystudyguidancegroups' + +export const init = async (page: Page, path: string, userId: UserId) => { + const headersToUse = userHeaders.find(({ uid }) => uid === userId) + if (!headersToUse) throw Error(`${userId} is not valid user id!`) + + await page.route('**/api/**', async route => { + await route.continue({ + headers: { + ...route.request().headers(), + ...headersToUse, + }, + }) + }) + + await page.goto(path || '/') +} + +// export const cs = (page: Page, subject: string) => { +// const selector = `[data-cy="${name}"]` +// } diff --git a/playwright/support/e2e.js b/e2e/support/e2e.js similarity index 100% rename from playwright/support/e2e.js rename to e2e/support/e2e.js diff --git a/playwright/Users.js b/playwright/Users.js deleted file mode 100644 index f7981480b..000000000 --- a/playwright/Users.js +++ /dev/null @@ -1,79 +0,0 @@ -import { test, expect } from '@playwright/test' -/// -const visibleLinks = { - norights: ['University', 'Faculties', 'Special populations', 'Feedback'], - onlycoursestatistics: ['University', 'Courses', 'Special populations', 'Feedback'], -} -visibleLinks.basic = [...visibleLinks.onlycoursestatistics, 'Faculties', 'Programmes', 'Students'] -visibleLinks.admin = [...visibleLinks.basic, 'Teachers', 'Admin'] -const containsLinks = async (page, links) => { - cy.cs('nav-bar').within(() => { - for (const link of links) { - cy.contains(link) - } - }) -} -const userButtonWorks = async (page, username, mocking = false) => { - cy.cs('nav-bar-user-button').click() - cy.contains(mocking ? `Mocking as ${username}` : `Logged in as ${username}`) - cy.contains('Language') - cy.contains('suomi') - cy.contains('English') - cy.contains('svenska') - cy.contains(mocking ? 'Stop mocking' : 'Log out') -} -test.describe('Users tests', () => { - test.describe('Using as user with just grp-oodikone-user, no other rights', () => { - test('shows correct tabs', async ({ page }) => { - cy.init('', 'norights') - containsLinks(page) - userButtonWorks(page) - }) - }) - test.describe('Using as coursestatistics user', () => { - test('shows correct tabs', async ({ page }) => { - cy.init('', 'onlycoursestatistics') - containsLinks(page) - userButtonWorks(page) - }) - }) - test.describe('Using as basic user', () => { - test('shows correct tabs', async ({ page }) => { - cy.init('') - containsLinks(page) - userButtonWorks(page) - }) - }) - test.describe('Using as admin', () => { - test.beforeEach(async ({ page }) => { - cy.init('/users', 'admin') - }) - test('should see more stuff than others', async ({ page }) => { - containsLinks(page) - userButtonWorks(page) - }) - test.describe('can mock as other users', () => { - test.beforeEach(async ({ page }) => { - cy.cs('user-page-button-basic').click() - cy.cs('mock-button').click() - }) - test('user button shows mocked user', async ({ page }) => { - userButtonWorks(page) - }) - test("only the mocked user's programmes are visible", async ({ page }) => { - cy.intercept('/api/populationstatistics/studyprogrammes').as('studyprogrammes') - page.goto('/populations') - cy.wait('@studyprogrammes').its('response.statusCode').should('be.oneOf', [200, 304]) - cy.contains('h6', 'Degree programme') - cy.cs('population-programme-selector').within(() => - cy.get('input').should('have.attr', 'placeholder', 'Select degree programme') - ) - cy.cs('population-programme-selector-parent').click() - cy.cs('population-programme-selector-parent').within(() => cy.contains('Matemaattisten tieteiden kandiohjelma')) - cy.cs('population-programme-selector-parent').within(() => - cy.contains('Matematiikan ja tilastotieteen maisteriohjelma') - ) - }) - }) - }) -}) diff --git a/playwright/support/commands.js b/playwright/support/commands.js deleted file mode 100644 index e69de29bb..000000000