mirror of
https://github.com/UniversityOfHelsinkiCS/oodikone.git
synced 2026-10-12 19:03:39 +03:00
[Playwright] Change playwright to under e2e
This commit is contained in:
committed by
Aaro Koivukangas
parent
42d8c529a3
commit
d0b85c0722
@@ -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
|
||||
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
/// <reference types="cypress" />
|
||||
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)
|
||||
@@ -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}"]`
|
||||
// }
|
||||
@@ -1,79 +0,0 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
/// <reference types="cypress" />
|
||||
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')
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user