mirror of
https://github.com/UniversityOfHelsinkiCS/oodikone.git
synced 2026-10-12 19:03:39 +03:00
[E2E] Fix tests with newPage
This commit is contained in:
committed by
Aaro Koivukangas
parent
58f2d3068e
commit
56fda867c2
@@ -756,6 +756,13 @@ test.describe('Degree programme overview', () => {
|
||||
test.describe('Adding tags to students and removing them works', () => {
|
||||
const studentInput = '477806,478275; 478953 479239\n 480080'
|
||||
const studentNumbers = studentInput.match(/[^\s,;]+/g)!
|
||||
|
||||
test.beforeEach(async ({ page, context }) => {
|
||||
await init(page, '/study-programme', 'basic', context)
|
||||
await page.getByRole('link', { name: 'Matemaattisten tieteiden kandiohjelma' }).click()
|
||||
await page.getByTestId('TagsTab').click()
|
||||
})
|
||||
|
||||
test('can add tags to students', async ({ page, context }) => {
|
||||
// NOTE: Navigating to each students' page takes time, fix?
|
||||
test.slow()
|
||||
|
||||
@@ -46,6 +46,8 @@ test.describe('Teachers page tests', () => {
|
||||
})
|
||||
|
||||
test('Can check teacher page', async ({ page, context }) => {
|
||||
// Re-init with context so the tab opened from the teacher link gets mocked headers too.
|
||||
await init(page, '/teachers', 'admin', context)
|
||||
await page.getByTestId('Search').click()
|
||||
await page.getByTestId('teacher-search').getByPlaceholder('Search by entering a name or an id').fill(teacher2)
|
||||
|
||||
@@ -54,7 +56,7 @@ test.describe('Teachers page tests', () => {
|
||||
|
||||
// Change to other tab
|
||||
const pagePromise = context.waitForEvent('page')
|
||||
await page.getByText(teacher2).click()
|
||||
await page.getByRole('link', { name: teacher2 }).click()
|
||||
const newPage = await pagePromise
|
||||
|
||||
await newPage.waitForURL('**/teachers/hy-hlo-49026530')
|
||||
@@ -66,9 +68,9 @@ test.describe('Teachers page tests', () => {
|
||||
await expect(newPage.getByText('MAT22002')).toBeVisible()
|
||||
await expect(newPage.getByText('MAT22003')).toBeVisible()
|
||||
|
||||
const courseRow = newPage.locator('tr').getByText('MAT12004')
|
||||
const courseRow = newPage.locator('tr').filter({ hasText: 'MAT12004' })
|
||||
const rowContent = ['MAT12004', 'Tilastollinen päättely I', '120', '0', '92.31%']
|
||||
rowContent.map(content => expect(courseRow.getByText(content)))
|
||||
await expect(courseRow.locator('td')).toHaveText(rowContent)
|
||||
})
|
||||
|
||||
test('Check leaderboad works', async ({ page }) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// ! IMPORTANT: here we need to set keys to be all lowercase, since
|
||||
// ! we're replacing headers after they've left browser / frontend.
|
||||
|
||||
import { expect, Page } from '@playwright/test'
|
||||
import { BrowserContext, expect, Page } from '@playwright/test'
|
||||
|
||||
// All of these users are available in anon user-db
|
||||
const adminUserHeaders = {
|
||||
@@ -70,11 +70,14 @@ export const userHeaders = [
|
||||
|
||||
type UserId = 'admin' | 'basic' | 'onlycoursestatistics' | 'norights' | 'onlyiamrights' | 'onlystudyguidancegroups'
|
||||
|
||||
export const init = async (page: Page, path: string, userId: UserId = 'basic') => {
|
||||
export const init = async (page: Page, path: string, userId: UserId = 'basic', context?: BrowserContext) => {
|
||||
const headersToUse = userHeaders.find(({ uid }) => uid === userId)
|
||||
if (!headersToUse) throw Error(`${userId} is not valid user id!`)
|
||||
|
||||
await page.route('**/api/**', async route => {
|
||||
// Prefer context-level routing when provided so new tabs inherit header injection.
|
||||
const routeTarget = context ?? page
|
||||
|
||||
await routeTarget.route('**/api/**', async route => {
|
||||
await route.continue({
|
||||
headers: {
|
||||
...route.request().headers(),
|
||||
|
||||
Reference in New Issue
Block a user