Skip to content

Commit

Permalink
Improve exam creation/deletion tests for better isolation and precise…
Browse files Browse the repository at this point in the history
… exam date differences
  • Loading branch information
muradium committed Dec 20, 2024
1 parent 11e21e5 commit e96a6d8
Showing 1 changed file with 54 additions and 55 deletions.
109 changes: 54 additions & 55 deletions src/test/playwright/e2e/exam/ExamCreationDeletion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,11 @@ import { Course } from 'app/entities/course.model';
import { dayjsToString, generateUUID, trimDate } from '../../support/utils';
import dayjs from 'dayjs';
import { expect } from '@playwright/test';
import { Exam } from 'app/entities/exam/exam.model';

/*
* Common primitives
*/
const examData = {
title: 'exam' + generateUUID(),
visibleDate: dayjs(),
startDate: dayjs().add(1, 'hour'),
endDate: dayjs().add(2, 'hour'),
numberOfExercisesInExam: 4,
examMaxPoints: 40,
startText: 'Exam start text',
endText: 'Exam end text',
confirmationStartText: 'Exam confirmation start text',
confirmationEndText: 'Exam confirmation end text',
};

const editedExamData = {
title: 'exam' + generateUUID(),
visibleDate: dayjs(),
startDate: dayjs().add(1, 'hour'),
endDate: dayjs().add(5, 'hour'),
numberOfExercisesInExam: 3,
examMaxPoints: 30,
startText: 'Edited exam start text',
endText: 'Edited exam end text',
confirmationStartText: 'Edited exam confirmation start text',
confirmationEndText: 'Edited exam confirmation end text',
};

const dateFormat = 'MMM D, YYYY HH:mm';

test.describe('Exam creation/deletion', { tag: '@fast' }, () => {
Expand All @@ -45,6 +20,19 @@ test.describe('Exam creation/deletion', { tag: '@fast' }, () => {
});

test('Creates an exam', async ({ navigationBar, courseManagement, examManagement, examCreation }) => {
const examData = {
title: 'exam' + generateUUID(),
visibleDate: dayjs(),
startDate: dayjs().add(1, 'hour'),
endDate: dayjs().add(2, 'hour'),
numberOfExercisesInExam: 4,
examMaxPoints: 40,
startText: 'Exam start text',
endText: 'Exam end text',
confirmationStartText: 'Exam confirmation start text',
confirmationEndText: 'Exam confirmation end text',
};

await navigationBar.openCourseManagement();
await courseManagement.openExamsOfCourse(course.id!);

Expand Down Expand Up @@ -78,48 +66,60 @@ test.describe('Exam creation/deletion', { tag: '@fast' }, () => {
});

test.describe('Exam deletion', () => {
let examId: number;
let exam: Exam;

test.beforeEach(async ({ examAPIRequests }) => {
examData.title = 'exam' + generateUUID();
const examConfig = {
course,
title: examData.title,
title: 'exam' + generateUUID(),
};
const examResponse = await examAPIRequests.createExam(examConfig);
examId = examResponse.id!;
exam = await examAPIRequests.createExam(examConfig);
});

test('Deletes an existing exam', async ({ navigationBar, courseManagement, examManagement, examDetails }) => {
await navigationBar.openCourseManagement();
await courseManagement.openExamsOfCourse(course.id!);
await examManagement.openExam(examId);
await examDetails.deleteExam(examData.title);
await expect(examManagement.getExamSelector(examData.title)).not.toBeVisible();
await examManagement.openExam(exam.id!);
await examDetails.deleteExam(exam.title!);
await expect(examManagement.getExamSelector(exam.title!)).not.toBeVisible();
});
});

test.describe('Edits an exam', () => {
let examId: number;
let exam: Exam;

test.beforeEach(async ({ examAPIRequests }) => {
examData.title = 'exam' + generateUUID();
const examConfig = {
course,
title: examData.title,
title: 'exam' + generateUUID(),
visibleDate: dayjs(),
startDate: dayjs().add(1, 'hour'),
};
const examResponse = await examAPIRequests.createExam(examConfig);
examId = examResponse.id!;
exam = await examAPIRequests.createExam(examConfig);
});

test('Edits an existing exam', async ({ navigationBar, courseManagement, examManagement, examCreation }) => {
const visibleDate = dayjs();
const startDate = visibleDate.add(1, 'hour');
const endDate = startDate.add(4, 'hour');

const editedExamData = {
title: 'exam' + generateUUID(),
visibleDate: visibleDate,
startDate: startDate,
endDate: endDate,
numberOfExercisesInExam: 3,
examMaxPoints: 30,
startText: 'Edited exam start text',
endText: 'Edited exam end text',
confirmationStartText: 'Edited exam confirmation start text',
confirmationEndText: 'Edited exam confirmation end text',
};

await navigationBar.openCourseManagement();
await courseManagement.openExamsOfCourse(course.id!);
await examManagement.openExam(examId);
await examManagement.openExam(exam.id!);

await expect(examManagement.getExamTitle()).toContainText(examData.title);
await expect(examManagement.getExamTitle()).toContainText(exam.title!);
await examManagement.clickEdit();

await examCreation.setTitle(editedExamData.title);
Expand All @@ -136,19 +136,18 @@ test.describe('Exam creation/deletion', { tag: '@fast' }, () => {

const response = await examCreation.update();
expect(response.status()).toBe(200);
const exam = await response.json();

examId = exam.id;
expect(exam.testExam).toBeFalsy();
expect(trimDate(exam.visibleDate)).toBe(trimDate(dayjsToString(editedExamData.visibleDate)));
expect(trimDate(exam.startDate)).toBe(trimDate(dayjsToString(editedExamData.startDate)));
expect(trimDate(exam.endDate)).toBe(trimDate(dayjsToString(editedExamData.endDate)));
expect(exam.numberOfExercisesInExam).toBe(editedExamData.numberOfExercisesInExam);
expect(exam.examMaxPoints).toBe(editedExamData.examMaxPoints);
expect(exam.startText).toBe(editedExamData.startText);
expect(exam.endText).toBe(editedExamData.endText);
expect(exam.confirmationStartText).toBe(editedExamData.confirmationStartText);
expect(exam.confirmationEndText).toBe(editedExamData.confirmationEndText);
const editedExam = await response.json();

expect(editedExam.testExam).toBeFalsy();
expect(trimDate(editedExam.visibleDate)).toBe(trimDate(dayjsToString(editedExamData.visibleDate)));
expect(trimDate(editedExam.startDate)).toBe(trimDate(dayjsToString(editedExamData.startDate)));
expect(trimDate(editedExam.endDate)).toBe(trimDate(dayjsToString(editedExamData.endDate)));
expect(editedExam.numberOfExercisesInExam).toBe(editedExamData.numberOfExercisesInExam);
expect(editedExam.examMaxPoints).toBe(editedExamData.examMaxPoints);
expect(editedExam.startText).toBe(editedExamData.startText);
expect(editedExam.endText).toBe(editedExamData.endText);
expect(editedExam.confirmationStartText).toBe(editedExamData.confirmationStartText);
expect(editedExam.confirmationEndText).toBe(editedExamData.confirmationEndText);

await expect(examManagement.getExamTitle()).toContainText(editedExamData.title);
await expect(examManagement.getExamVisibleDate()).toContainText(dayjs(editedExamData.visibleDate).format(dateFormat));
Expand Down

0 comments on commit e96a6d8

Please sign in to comment.