starting quiz tests

This commit is contained in:
2024-08-21 15:43:16 -06:00
parent 7bb15126b6
commit 15c4a2241f
9 changed files with 514 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
import { describe, it, expect } from "vitest";
import { LocalCoursePage } from "../../page/localCoursePage";
import { pageMarkdown } from "../../page/pageMarkdown";
import { pageMarkdownUtils } from "../../page/pageMarkdownUtils";
describe("PageMarkdownTests", () => {
it("can parse page", () => {
@@ -10,9 +10,9 @@ describe("PageMarkdownTests", () => {
dueAt: new Date().toISOString(),
};
const pageMarkdownString = pageMarkdown.toMarkdown(page);
const pageMarkdownString = pageMarkdownUtils.toMarkdown(page);
const parsedPage = pageMarkdown.parseMarkdown(pageMarkdownString);
const parsedPage = pageMarkdownUtils.parseMarkdown(pageMarkdownString);
expect(parsedPage).toEqual(page);
});

View File

@@ -0,0 +1,110 @@
import { QuestionType } from '../../../../../models/local/quiz/localQuizQuestion';
import { quizMarkdownUtils } from '../../../../../models/local/quiz/utils/quizMarkdownUtils';
import { quizQuestionMarkdownUtils } from '../../../../../models/local/quiz/utils/quizQuestionMarkdownUtils';
import { describe, it, expect } from 'vitest';
describe('TextAnswerTests', () => {
it('can parse essay', () => {
const rawMarkdownQuiz = `
Name: Test Quiz
ShuffleAnswers: true
OneQuestionAtATime: false
DueAt: 2023-08-21T23:59:00
LockAt: 2023-08-21T23:59:00
AssignmentGroup: Assignments
AllowedAttempts: -1
Description: this is the
multi line
description
---
Which events are triggered when the user clicks on an input field?
essay
`;
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
const firstQuestion = quiz.questions[0];
expect(firstQuestion.points).toBe(1);
expect(firstQuestion.questionType).toBe(QuestionType.ESSAY);
expect(firstQuestion.text).not.toContain('essay');
});
it('can parse short answer', () => {
const rawMarkdownQuiz = `
Name: Test Quiz
ShuffleAnswers: true
OneQuestionAtATime: false
DueAt: 2023-08-21T23:59:00
LockAt: 2023-08-21T23:59:00
AssignmentGroup: Assignments
AllowedAttempts: -1
Description: this is the
multi line
description
---
Which events are triggered when the user clicks on an input field?
short answer
`;
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
const firstQuestion = quiz.questions[0];
expect(firstQuestion.points).toBe(1);
expect(firstQuestion.questionType).toBe(QuestionType.SHORT_ANSWER);
expect(firstQuestion.text).not.toContain('short answer');
});
it('short answer to markdown is correct', () => {
const rawMarkdownQuiz = `
Name: Test Quiz
ShuffleAnswers: true
OneQuestionAtATime: false
DueAt: 2023-08-21T23:59:00
LockAt: 2023-08-21T23:59:00
AssignmentGroup: Assignments
AllowedAttempts: -1
Description: this is the
multi line
description
---
Which events are triggered when the user clicks on an input field?
short answer
`;
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
const firstQuestion = quiz.questions[0];
const questionMarkdown = quizQuestionMarkdownUtils.toMarkdown(firstQuestion);
const expectedMarkdown = `Points: 1
Which events are triggered when the user clicks on an input field?
short_answer`;
expect(questionMarkdown).toContain(expectedMarkdown);
});
it('essay question to markdown is correct', () => {
const rawMarkdownQuiz = `
Name: Test Quiz
ShuffleAnswers: true
OneQuestionAtATime: false
DueAt: 2023-08-21T23:59:00
LockAt: 2023-08-21T23:59:00
AssignmentGroup: Assignments
AllowedAttempts: -1
Description: this is the
multi line
description
---
Which events are triggered when the user clicks on an input field?
essay
`;
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
const firstQuestion = quiz.questions[0];
const questionMarkdown = quizQuestionMarkdownUtils.toMarkdown(firstQuestion);
const expectedMarkdown = `Points: 1
Which events are triggered when the user clicks on an input field?
essay`;
expect(questionMarkdown).toContain(expectedMarkdown);
});
});