mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
updating tests
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { LocalQuiz } from "../localQuiz";
|
||||||
import { quizQuestionMarkdownUtils } from "./quizQuestionMarkdownUtils";
|
import { quizQuestionMarkdownUtils } from "./quizQuestionMarkdownUtils";
|
||||||
|
|
||||||
const extractLabelValue = (input: string, label: string): string => {
|
const extractLabelValue = (input: string, label: string): string => {
|
||||||
|
|||||||
@@ -153,13 +153,31 @@ export const quizQuestionMarkdownUtils = {
|
|||||||
|
|
||||||
const linesWithoutPoints = firstLineIsPoints ? lines.slice(1) : lines;
|
const linesWithoutPoints = firstLineIsPoints ? lines.slice(1) : lines;
|
||||||
|
|
||||||
const linesWithoutAnswers = linesWithoutPoints.filter(
|
// const linesWithoutAnswers = linesWithoutPoints.filter(
|
||||||
(line, index) =>
|
// (line, index) =>
|
||||||
!_validFirstAnswerDelimiters.some((prefix) =>
|
// !_validFirstAnswerDelimiters.some((prefix) =>
|
||||||
line.trimStart().startsWith(prefix)
|
// line.trimStart().startsWith(prefix)
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
|
|
||||||
|
const { linesWithoutAnswers } = linesWithoutPoints.reduce(
|
||||||
|
({ linesWithoutAnswers, taking }, currentLine) => {
|
||||||
|
if (!taking)
|
||||||
|
return { linesWithoutAnswers: linesWithoutAnswers, taking: false };
|
||||||
|
|
||||||
|
const lineIsAnswer = _validFirstAnswerDelimiters.some((prefix) =>
|
||||||
|
currentLine.trimStart().startsWith(prefix)
|
||||||
|
);
|
||||||
|
if (lineIsAnswer)
|
||||||
|
return { linesWithoutAnswers: linesWithoutAnswers, taking: false };
|
||||||
|
|
||||||
|
return {
|
||||||
|
linesWithoutAnswers: [...linesWithoutAnswers, currentLine],
|
||||||
|
taking: true,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{ linesWithoutAnswers: [] as string[], taking: true }
|
||||||
|
);
|
||||||
const questionType = getQuestionType(linesWithoutPoints, questionIndex);
|
const questionType = getQuestionType(linesWithoutPoints, questionIndex);
|
||||||
|
|
||||||
const questionTypesWithoutAnswers = [
|
const questionTypesWithoutAnswers = [
|
||||||
|
|||||||
@@ -0,0 +1,193 @@
|
|||||||
|
import { describe, it, expect } from "vitest";
|
||||||
|
import { LocalQuiz } from "../../../../../models/local/quiz/localQuiz";
|
||||||
|
import { quizMarkdownUtils } from "../../../../../models/local/quiz/utils/quizMarkdownUtils";
|
||||||
|
import { QuestionType } from "@/models/local/quiz/localQuizQuestion";
|
||||||
|
|
||||||
|
// Test suite for deterministic checks on LocalQuiz
|
||||||
|
describe("QuizDeterministicChecks", () => {
|
||||||
|
it("SerializationIsDeterministic_EmptyQuiz", () => {
|
||||||
|
const quiz: LocalQuiz = {
|
||||||
|
name: "Test Quiz",
|
||||||
|
description: "quiz description",
|
||||||
|
lockAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
dueAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
shuffleAnswers: true,
|
||||||
|
oneQuestionAtATime: true,
|
||||||
|
localAssignmentGroupName: "Assignments",
|
||||||
|
questions: [],
|
||||||
|
allowedAttempts: -1,
|
||||||
|
showCorrectAnswers: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const quizMarkdown = quizMarkdownUtils.toMarkdown(quiz);
|
||||||
|
const parsedQuiz = quizMarkdownUtils.parseMarkdown(quizMarkdown);
|
||||||
|
|
||||||
|
expect(parsedQuiz).toEqual(quiz);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("SerializationIsDeterministic_ShowCorrectAnswers", () => {
|
||||||
|
const quiz: LocalQuiz = {
|
||||||
|
name: "Test Quiz",
|
||||||
|
description: "quiz description",
|
||||||
|
lockAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
dueAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
showCorrectAnswers: false,
|
||||||
|
shuffleAnswers: true,
|
||||||
|
oneQuestionAtATime: true,
|
||||||
|
localAssignmentGroupName: "Assignments",
|
||||||
|
questions: [],
|
||||||
|
allowedAttempts: -1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const quizMarkdown = quizMarkdownUtils.toMarkdown(quiz);
|
||||||
|
const parsedQuiz = quizMarkdownUtils.parseMarkdown(quizMarkdown);
|
||||||
|
|
||||||
|
expect(parsedQuiz).toEqual(quiz);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("SerializationIsDeterministic_ShortAnswer", () => {
|
||||||
|
const quiz: LocalQuiz = {
|
||||||
|
name: "Test Quiz",
|
||||||
|
description: "quiz description",
|
||||||
|
lockAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
dueAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
shuffleAnswers: true,
|
||||||
|
oneQuestionAtATime: true,
|
||||||
|
localAssignmentGroupName: "Assignments",
|
||||||
|
questions: [
|
||||||
|
{
|
||||||
|
text: "test short answer",
|
||||||
|
questionType: QuestionType.SHORT_ANSWER,
|
||||||
|
points: 1,
|
||||||
|
answers: []
|
||||||
|
},
|
||||||
|
],
|
||||||
|
allowedAttempts: -1,
|
||||||
|
showCorrectAnswers: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const quizMarkdown = quizMarkdownUtils.toMarkdown(quiz);
|
||||||
|
const parsedQuiz = quizMarkdownUtils.parseMarkdown(quizMarkdown);
|
||||||
|
|
||||||
|
expect(parsedQuiz).toEqual(quiz);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("SerializationIsDeterministic_Essay", () => {
|
||||||
|
const quiz: LocalQuiz = {
|
||||||
|
name: "Test Quiz",
|
||||||
|
description: "quiz description",
|
||||||
|
lockAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
dueAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
shuffleAnswers: true,
|
||||||
|
oneQuestionAtATime: true,
|
||||||
|
localAssignmentGroupName: "Assignments",
|
||||||
|
questions: [
|
||||||
|
{
|
||||||
|
text: "test essay",
|
||||||
|
questionType: QuestionType.ESSAY,
|
||||||
|
points: 1,
|
||||||
|
answers: []
|
||||||
|
},
|
||||||
|
],
|
||||||
|
allowedAttempts: -1,
|
||||||
|
showCorrectAnswers: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const quizMarkdown = quizMarkdownUtils.toMarkdown(quiz);
|
||||||
|
const parsedQuiz = quizMarkdownUtils.parseMarkdown(quizMarkdown);
|
||||||
|
|
||||||
|
expect(parsedQuiz).toEqual(quiz);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("SerializationIsDeterministic_MultipleAnswer", () => {
|
||||||
|
const quiz: LocalQuiz = {
|
||||||
|
name: "Test Quiz",
|
||||||
|
description: "quiz description",
|
||||||
|
lockAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
dueAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
shuffleAnswers: true,
|
||||||
|
oneQuestionAtATime: true,
|
||||||
|
localAssignmentGroupName: "Assignments",
|
||||||
|
questions: [
|
||||||
|
{
|
||||||
|
text: "test multiple answer",
|
||||||
|
questionType: QuestionType.MULTIPLE_ANSWERS,
|
||||||
|
points: 1,
|
||||||
|
answers: [
|
||||||
|
{ text: "yes", correct: true },
|
||||||
|
{ text: "no", correct: true },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
allowedAttempts: -1,
|
||||||
|
showCorrectAnswers: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const quizMarkdown = quizMarkdownUtils.toMarkdown(quiz);
|
||||||
|
const parsedQuiz = quizMarkdownUtils.parseMarkdown(quizMarkdown);
|
||||||
|
|
||||||
|
expect(parsedQuiz).toEqual(quiz);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("SerializationIsDeterministic_MultipleChoice", () => {
|
||||||
|
const quiz: LocalQuiz = {
|
||||||
|
name: "Test Quiz",
|
||||||
|
description: "quiz description",
|
||||||
|
lockAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
dueAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
shuffleAnswers: true,
|
||||||
|
oneQuestionAtATime: true,
|
||||||
|
password: undefined,
|
||||||
|
localAssignmentGroupName: "Assignments",
|
||||||
|
questions: [
|
||||||
|
{
|
||||||
|
text: "test multiple choice",
|
||||||
|
questionType: QuestionType.MULTIPLE_CHOICE,
|
||||||
|
points: 1,
|
||||||
|
answers: [
|
||||||
|
{ text: "yes", correct: true },
|
||||||
|
{ text: "no", correct: false },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
allowedAttempts: -1,
|
||||||
|
showCorrectAnswers: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const quizMarkdown = quizMarkdownUtils.toMarkdown(quiz);
|
||||||
|
const parsedQuiz = quizMarkdownUtils.parseMarkdown(quizMarkdown);
|
||||||
|
|
||||||
|
expect(parsedQuiz).toEqual(quiz);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("SerializationIsDeterministic_Matching", () => {
|
||||||
|
const quiz: LocalQuiz = {
|
||||||
|
name: "Test Quiz",
|
||||||
|
description: "quiz description",
|
||||||
|
lockAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
dueAt: new Date(2022, 9, 3, 12, 5, 0).toISOString(),
|
||||||
|
shuffleAnswers: true,
|
||||||
|
oneQuestionAtATime: true,
|
||||||
|
password: undefined,
|
||||||
|
localAssignmentGroupName: "Assignments",
|
||||||
|
questions: [
|
||||||
|
{
|
||||||
|
text: "test matching",
|
||||||
|
questionType: QuestionType.MATCHING,
|
||||||
|
points: 1,
|
||||||
|
answers: [
|
||||||
|
{ text: "yes", correct: true, matchedText: "testing yes" },
|
||||||
|
{ text: "no", correct: true, matchedText: "testing no" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
allowedAttempts: -1,
|
||||||
|
showCorrectAnswers: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const quizMarkdown = quizMarkdownUtils.toMarkdown(quiz);
|
||||||
|
const parsedQuiz = quizMarkdownUtils.parseMarkdown(quizMarkdown);
|
||||||
|
|
||||||
|
expect(parsedQuiz).toEqual(quiz);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { LocalQuiz } from "../../../../../models/local/quiz/localQuiz";
|
import { LocalQuiz } from "../../../../../models/local/quiz/localQuiz";
|
||||||
import { quizMarkdownUtils } from "../../../../../models/local/quiz/utils/quizMarkdownUtils";
|
import { quizMarkdownUtils } from "../../../../../models/local/quiz/utils/quizMarkdownUtils";
|
||||||
|
import { QuestionType } from "@/models/local/quiz/localQuizQuestion";
|
||||||
|
import { quizQuestionMarkdownUtils } from "@/models/local/quiz/utils/quizQuestionMarkdownUtils";
|
||||||
|
|
||||||
// Test suite for QuizMarkdown
|
// Test suite for QuizMarkdown
|
||||||
describe("QuizMarkdownTests", () => {
|
describe("QuizMarkdownTests", () => {
|
||||||
@@ -49,7 +51,7 @@ description
|
|||||||
---
|
---
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const quiz = LocalQuiz.parseMarkdown(rawMarkdownQuiz);
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||||
|
|
||||||
const expectedDescription = `
|
const expectedDescription = `
|
||||||
this is the
|
this is the
|
||||||
@@ -80,7 +82,7 @@ description
|
|||||||
---
|
---
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const quiz = LocalQuiz.parseMarkdown(rawMarkdownQuiz);
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||||
|
|
||||||
expect(quiz.password).toBe(password);
|
expect(quiz.password).toBe(password);
|
||||||
});
|
});
|
||||||
@@ -101,7 +103,7 @@ description
|
|||||||
---
|
---
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const quiz = LocalQuiz.parseMarkdown(rawMarkdownQuiz);
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||||
|
|
||||||
expect(quiz.showCorrectAnswers).toBe(false);
|
expect(quiz.showCorrectAnswers).toBe(false);
|
||||||
});
|
});
|
||||||
@@ -133,7 +135,7 @@ b) false
|
|||||||
|
|
||||||
endline`;
|
endline`;
|
||||||
|
|
||||||
const quiz = LocalQuiz.parseMarkdown(rawMarkdownQuiz);
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||||
const firstQuestion = quiz.questions[0];
|
const firstQuestion = quiz.questions[0];
|
||||||
|
|
||||||
expect(firstQuestion.questionType).toBe(QuestionType.MULTIPLE_CHOICE);
|
expect(firstQuestion.questionType).toBe(QuestionType.MULTIPLE_CHOICE);
|
||||||
@@ -168,7 +170,7 @@ Points: 2
|
|||||||
b) false
|
b) false
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const quiz = LocalQuiz.parseMarkdown(rawMarkdownQuiz);
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||||
const firstQuestion = quiz.questions[0];
|
const firstQuestion = quiz.questions[0];
|
||||||
expect(firstQuestion.points).toBe(1);
|
expect(firstQuestion.points).toBe(1);
|
||||||
expect(firstQuestion.questionType).toBe(QuestionType.MULTIPLE_ANSWERS);
|
expect(firstQuestion.questionType).toBe(QuestionType.MULTIPLE_ANSWERS);
|
||||||
@@ -195,12 +197,12 @@ Which events are triggered when the user clicks on an input field?
|
|||||||
short answer
|
short answer
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const quiz = LocalQuiz.parseMarkdown(rawMarkdownQuiz);
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||||
const firstQuestion = quiz.questions[0];
|
const firstQuestion = quiz.questions[0];
|
||||||
|
|
||||||
const questionMarkdown = firstQuestion.toMarkdown();
|
const questionMarkdown =
|
||||||
const expectedMarkdown = `
|
quizQuestionMarkdownUtils.toMarkdown(firstQuestion);
|
||||||
Points: 1
|
const expectedMarkdown = `Points: 1
|
||||||
Which events are triggered when the user clicks on an input field?
|
Which events are triggered when the user clicks on an input field?
|
||||||
short_answer`;
|
short_answer`;
|
||||||
expect(questionMarkdown).toContain(expectedMarkdown);
|
expect(questionMarkdown).toContain(expectedMarkdown);
|
||||||
@@ -224,7 +226,7 @@ Which events are triggered when the user clicks on an input field?
|
|||||||
short answer
|
short answer
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const quiz = LocalQuiz.parseMarkdown(rawMarkdownQuiz);
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||||
const firstQuestion = quiz.questions[0];
|
const firstQuestion = quiz.questions[0];
|
||||||
expect(firstQuestion.points).toBe(-4);
|
expect(firstQuestion.points).toBe(-4);
|
||||||
});
|
});
|
||||||
@@ -247,7 +249,7 @@ Which events are triggered when the user clicks on an input field?
|
|||||||
short answer
|
short answer
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const quiz = LocalQuiz.parseMarkdown(rawMarkdownQuiz);
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||||
const firstQuestion = quiz.questions[0];
|
const firstQuestion = quiz.questions[0];
|
||||||
expect(firstQuestion.points).toBe(4.56);
|
expect(firstQuestion.points).toBe(4.56);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import { defineConfig } from 'vitest/config'
|
import { defineConfig } from "vitest/config";
|
||||||
import react from '@vitejs/plugin-react'
|
import react from "@vitejs/plugin-react";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
test: {
|
resolve: {
|
||||||
environment: 'jsdom',
|
alias: {
|
||||||
|
"@": "/src",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
test: {
|
||||||
|
environment: "jsdom",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user