Files
oodikone/services/frontend/tests/pages/CourseStatistics/index.spec.tsx
T

163 lines
5.5 KiB
TypeScript

import { test, expect } from '@playwright/experimental-ct-react'
import { CourseStatistics } from '@/pages/CourseStatistics'
import { ReduxWrapper } from '../../ReduxWrapper'
test.describe('Course statistics search', () => {
test.beforeEach(async ({ page, router }) => {
// Set time to spring 2026 so that curriculums work
await page.clock.setSystemTime('2026-03-06')
void (await router.route('**/api/login', async route => {
const json = { user: { roles: ['admin'] } }
await route.fulfill({ json })
}))
void (await router.route('**/api/courseyearlystats*', async route => {
const json = {}
void (await route.fulfill({ json }))
}))
void (await router.route('**/api/codes', async route => {
const json = {}
void (await route.fulfill({ json }))
}))
void (await router.route('**/api/maxYearsToCreatePopulationFrom*', async route => {
const json = {}
void (await route.fulfill({ json }))
}))
void (await router.route('**/api/courseyearlystats*', async route => {
const json = {}
void (await route.fulfill({ json }))
}))
void (await router.route('**/api/coursesmulti*', async route => {
const json = {
courses: [
{
id: 'tkt10002-id',
groupId: 'hy-CU-tkt10002',
code: 'TKT10002',
name: { fi: 'Ohjelmoinnin perusteet' },
substitutionGroups: [],
minAttainmentDate: new Date('2021-08-01').toISOString(),
maxAttainmentDate: new Date('2022-08-01').toISOString(),
},
{
id: 'tkt10003-id',
groupId: 'hy-CU-tkt10003',
code: 'TKT10003',
name: { fi: 'Ohjelmoinnin jatkokurssi' },
substitutionGroups: [],
minAttainmentDate: new Date('2021-08-01').toISOString(),
maxAttainmentDate: new Date('2022-08-01').toISOString(),
},
],
}
void (await route.fulfill({ json }))
}))
})
test('should mount correctly', async ({ mount }) => {
const component = await mount(<ReduxWrapper component={<CourseStatistics />} />)
await expect(component).toContainText('Course statistics')
})
test('should return courses with matching name', async ({ mount }) => {
const component = await mount(<ReduxWrapper component={<CourseStatistics />} />)
await expect(component).toContainText('Search for courses')
await component.getByLabel('Name').fill('Ohjelmoinnin')
await expect(component).toContainText('Ohjelmoinnin perusteet')
await expect(component).toContainText('Ohjelmoinnin jatkokurssi')
})
test('should return courses with matching code', async ({ mount }) => {
const component = await mount(<ReduxWrapper component={<CourseStatistics />} />)
await expect(component).toContainText('Search for courses')
await component.getByLabel('Code').fill('TKT')
await expect(component).toContainText('Ohjelmoinnin perusteet')
await expect(component).toContainText('Ohjelmoinnin jatkokurssi')
})
})
test.describe('Course statistics', () => {
test.beforeEach(async ({ router }) => {
void (await router.route('**/api/login', async route => {
const json = { user: { roles: ['admin'] } }
await route.fulfill({ json })
}))
void (await router.route('**/api/courseyearlystats*', async route => {
const json = {}
void (await route.fulfill({ json }))
}))
void (await router.route('**/api/codes', async route => {
const json = {}
void (await route.fulfill({ json }))
}))
void (await router.route('**/api/maxYearsToCreatePopulationFrom*', async route => {
const json = {}
void (await route.fulfill({ json }))
}))
void (await router.route('**/api/courseyearlystats*', async route => {
const json = [
{
unifyStats: {
courseCode: 'TKT10002',
name: { fi: 'Ohjelmoinnin perusteet' },
statistics: [],
},
regularStats: {},
openStats: {},
},
]
void (await route.fulfill({ json }))
}))
void (await router.route('**/api/coursesmulti*', async route => {
const json = {
courses: [
{
id: 'tkt10002-id',
groupId: 'hy-CU-tkt10002',
code: 'TKT10002',
name: { fi: 'Ohjelmoinnin perusteet' },
substitutionGroups: [],
minAttainmentDate: new Date('2021-08-01').toISOString(),
maxAttainmentDate: new Date('2022-08-01').toISOString(),
},
{
id: 'tkt10003-id',
groupId: 'hy-CU-tkt10003',
code: 'TKT10003',
name: { fi: 'Ohjelmoinnin jatkokurssi' },
substitutionGroups: [],
minAttainmentDate: new Date('2021-08-01').toISOString(),
maxAttainmentDate: new Date('2022-08-01').toISOString(),
},
],
}
void (await route.fulfill({ json }))
}))
})
// TODO: Finish this
test.skip('should open a course when clicked', async ({ mount }) => {
const component = await mount(<ReduxWrapper component={<CourseStatistics />} />)
await expect(component).toContainText('Search for courses')
await component.getByLabel('Combine substitutions').click()
await component.getByLabel('Code').fill('TKT')
await expect(component).toContainText('Ohjelmoinnin perusteet')
await component.getByRole('cell', { name: 'Ohjelmoinnin perusteet' }).click()
await expect(component).toContainText('Selected course')
})
})