Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curriculum UI tests #427

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions web/src/routes/admin/(resources)/curriculums/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@
if (selectedGrade) {
try {
curriculum = await getCurriculum(selectedGrade.curriculumId);
lessonsCounts = curriculum.lessonsCounts;
lessonsCounts = curriculum.lessonsCounts.sort((count0, count1) => {
let a = count0.subject?.name.toLowerCase() ?? '';
let b = count1.subject?.name.toLowerCase() ?? '';
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
});
} catch {
error(400, { message: 'could not get curriculum' });
}
Expand Down Expand Up @@ -64,7 +74,10 @@
<div class="grid grid-cols-4 w-fit gap-8">
{#await getCurriculumFromGrade() then}
{#each lessonsCounts as lessonCount}
<div class="bg-white shadow-custom p-4 w-[15vw] break-words rounded-md flex flex-col gap-2 justify-between">
<div
aria-label="lessonCount"
class="bg-white shadow-custom p-4 w-[15vw] break-words rounded-md flex flex-col gap-2 justify-between"
>
<div class="text-center m-1">{lessonCount.subject?.name}</div>
<div class="flex-row flex justify-center gap-2">
<button
Expand Down Expand Up @@ -103,15 +116,16 @@
<Button
on:click={async () => {
if (selectedGrade) {
let test = {
let requestDto = {
gradeId: selectedGrade.id,
lessonsCounts: curriculum.lessonsCounts.map((lessonsCount) => ({
count: lessonsCount.count || 0,
subjectId: lessonsCount.subject ? lessonsCount.subject.id : '',
})),
name: selectedGrade.name,
};
await updateCurriculum(curriculum.id, test);
console.log(requestDto);
await updateCurriculum(curriculum.id, requestDto);
toast(true, 'Curriculum erfolgreich gespeichert.');
}
}}
Expand Down
154 changes: 154 additions & 0 deletions web/tests/curriculum.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import {
createGrade,
createSubject,
deleteGrades,
deleteStudentGroup,
deleteSubjects,
getGrades,
getStudentGroups,
getSubjects,
} from '$lib/sdk/fetch-client';
import { expect, test, type Locator, type Page } from '@playwright/test';

let page: Page;
let countLocator: Locator;

test.describe.configure({ mode: 'serial' });

test.describe('Curriculum', () => {
test.beforeAll('Delete existing entities', async ({ browser }) => {
page = await browser.newPage();
const subjects = await getSubjects({});
if (subjects.length > 0) {
await deleteSubjects(subjects.map((subject) => subject.id));
}
const groups = await getStudentGroups({ page: 0 }).then(({ content }) => content ?? []);
if (groups.length > 0) {
for (const group of groups) {
await deleteStudentGroup(group.id);
}
}
const grades = await getGrades({});
if (grades.length > 0) {
await deleteGrades(grades.map((grade) => grade.id));
}

for (let i = 0; i < 5; i++) {
await createSubject({ name: `subject${i}`, tagIds: [] });
}
for (let i = 0; i < 5; i++) {
await createGrade({ name: `grade${i}`, tagIds: [], studentGroupIds: [] }).then(({ id }) => id);
}
await page.goto('/');
await page.getByRole('link').first().click();
await page.getByRole('link', { name: 'Curriculum' }).click();
});

test('set curriculum', async () => {
countLocator = page.getByLabel('lessonCount');
await expect(countLocator).toHaveCount(5);
await countLocator.first().getByRole('button').nth(1).click({ clickCount: 6 });
await countLocator.nth(2).getByRole('button').nth(1).click({ clickCount: 9 });
await countLocator.nth(4).getByRole('button').nth(1).click({ clickCount: 4 });
await expect(countLocator.first()).toContainText(' 6');
await expect(countLocator.nth(1)).toContainText(' 0');
await expect(countLocator.nth(2)).toContainText(' 9');
await expect(countLocator.nth(3)).toContainText(' 0');
await expect(countLocator.nth(4)).toContainText(' 4');
await page.getByText('Speichern').click();
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'grade1' }).first().click();
await expect(countLocator.first()).toContainText(' 0');
await expect(countLocator.nth(1)).toContainText(' 0');
await expect(countLocator.nth(2)).toContainText(' 0');
await expect(countLocator.nth(3)).toContainText(' 0');
await expect(countLocator.nth(4)).toContainText(' 0');
await countLocator.first().getByRole('button').nth(1).click({ clickCount: 8 });
await countLocator.nth(1).getByRole('button').nth(1).click({ clickCount: 2 });
await countLocator.nth(3).getByRole('button').nth(1).click({ clickCount: 5 });
await expect(countLocator.first()).toContainText(' 8');
await expect(countLocator.nth(1)).toContainText(' 2');
await expect(countLocator.nth(2)).toContainText(' 0');
await expect(countLocator.nth(3)).toContainText(' 5');
await expect(countLocator.nth(4)).toContainText(' 0');
await page.getByText('Speichern').click();
});

test('switch grades', async () => {
countLocator = page.getByLabel('lessonCount');
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'grade4' }).first().click();
await expect(countLocator.first()).toContainText('0');
await expect(countLocator.nth(1)).toContainText(' 0');
await expect(countLocator.nth(2)).toContainText(' 0');
await expect(countLocator.nth(3)).toContainText(' 0');
await expect(countLocator.nth(4)).toContainText(' 0');
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'grade0' }).first().click();
await expect(countLocator.first()).toContainText(' 6');
await expect(countLocator.nth(1)).toContainText(' 0');
await expect(countLocator.nth(2)).toContainText(' 9');
await expect(countLocator.nth(3)).toContainText(' 0');
await expect(countLocator.nth(4)).toContainText(' 4');
await page.getByRole('combobox').click();
await page.getByRole('option', { name: 'grade1' }).first().click();
await expect(countLocator.first()).toContainText(' 8');
await expect(countLocator.nth(1)).toContainText(' 2');
await expect(countLocator.nth(2)).toContainText(' 0');
await expect(countLocator.nth(3)).toContainText(' 5');
await expect(countLocator.nth(4)).toContainText(' 0');
});

test('check non-negative', async () => {
countLocator = page.getByLabel('lessonCount');
await countLocator.first().getByRole('button').first().click({ clickCount: 12 });
await countLocator.nth(1).getByRole('button').first().click({ clickCount: 5 });
await countLocator.nth(2).getByRole('button').first().click({ clickCount: 9 });
await countLocator.nth(3).getByRole('button').first().click({ clickCount: 7 });
await countLocator.nth(4).getByRole('button').first().click({ clickCount: 4 });
await expect(countLocator.first()).toContainText(' 0');
await expect(countLocator.nth(1)).toContainText(' 0');
await expect(countLocator.nth(2)).toContainText(' 0');
await expect(countLocator.nth(3)).toContainText(' 0');
await expect(countLocator.nth(4)).toContainText(' 0');
});

test('add subjects', async () => {
for (let i = 0; i < 5; i++) {
await createSubject({ name: `subject1${i}`, tagIds: [] });
}
await page.reload();
await expect(countLocator).toHaveCount(10);
await expect(countLocator.nth(2)).toContainText(' 0');
await expect(countLocator.nth(3)).toContainText(' 0');
await expect(countLocator.nth(4)).toContainText(' 0');
await expect(countLocator.nth(5)).toContainText(' 0');
await expect(countLocator.nth(6)).toContainText(' 0');
});

test('remove subjects', async () => {
const subjects = await getSubjects({ sort: ['name,asc'] });
await deleteSubjects(subjects.slice(-3).map((subject) => subject.id));
await page.reload();
await expect(countLocator).toHaveCount(7);
await expect(countLocator.first()).toContainText(' 6');
await expect(countLocator.nth(1)).toContainText(' 0');
await expect(countLocator.nth(2)).toContainText(' 0');
await expect(countLocator.nth(3)).toContainText(' 0');
await expect(countLocator.nth(4)).toContainText(' 0');
await expect(countLocator.nth(5)).toContainText(' 0');
await expect(countLocator.nth(6)).toContainText(' 0');

const subjects2 = await getSubjects({ sort: ['name,asc'] });
await deleteSubjects(subjects2.map((subject) => subject.id));
await page.reload();
await expect(countLocator).toHaveCount(0);
await expect(page.locator('body')).toContainText('Keine Fächer vorhanden.');
await expect(page.getByText('Speichern')).toBeDisabled();
const grades = await getGrades({});
await deleteGrades(grades.map((grade) => grade.id));
await page.reload();
await expect(page.locator('body')).toContainText('Keine Stufen vorhanden.');
await expect(page.getByText('Speichern')).toBeDisabled();
});
});