mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
short_answer= tested and implemented; local preview works, but canvas isn't getting the answers
This commit is contained in:
@@ -11,6 +11,7 @@ export enum QuestionType {
|
|||||||
SHORT_ANSWER = "short_answer",
|
SHORT_ANSWER = "short_answer",
|
||||||
MATCHING = "matching",
|
MATCHING = "matching",
|
||||||
NONE = "",
|
NONE = "",
|
||||||
|
SHORT_ANSWER_WITH_ANSWERS = "short_answer=",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const zodQuestionType = z.enum([
|
export const zodQuestionType = z.enum([
|
||||||
@@ -20,6 +21,7 @@ export const zodQuestionType = z.enum([
|
|||||||
QuestionType.SHORT_ANSWER,
|
QuestionType.SHORT_ANSWER,
|
||||||
QuestionType.MATCHING,
|
QuestionType.MATCHING,
|
||||||
QuestionType.NONE,
|
QuestionType.NONE,
|
||||||
|
QuestionType.SHORT_ANSWER_WITH_ANSWERS,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export interface LocalQuizQuestion {
|
export interface LocalQuizQuestion {
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ const getQuestionType = (
|
|||||||
"short_answer"
|
"short_answer"
|
||||||
)
|
)
|
||||||
return QuestionType.SHORT_ANSWER;
|
return QuestionType.SHORT_ANSWER;
|
||||||
|
if (
|
||||||
|
linesWithoutPoints[linesWithoutPoints.length - 1].toLowerCase().trim() ===
|
||||||
|
"short_answer="
|
||||||
|
)
|
||||||
|
return QuestionType.SHORT_ANSWER_WITH_ANSWERS;
|
||||||
|
|
||||||
const answerLines = getAnswerStringsWithMultilineSupport(
|
const answerLines = getAnswerStringsWithMultilineSupport(
|
||||||
linesWithoutPoints,
|
linesWithoutPoints,
|
||||||
@@ -97,6 +102,7 @@ const getAnswers = (
|
|||||||
questionIndex: number,
|
questionIndex: number,
|
||||||
questionType: string
|
questionType: string
|
||||||
): LocalQuizQuestionAnswer[] => {
|
): LocalQuizQuestionAnswer[] => {
|
||||||
|
if (questionType == QuestionType.SHORT_ANSWER_WITH_ANSWERS) linesWithoutPoints = linesWithoutPoints.slice(0, linesWithoutPoints.length - 1);
|
||||||
const answerLines = getAnswerStringsWithMultilineSupport(
|
const answerLines = getAnswerStringsWithMultilineSupport(
|
||||||
linesWithoutPoints,
|
linesWithoutPoints,
|
||||||
questionIndex
|
questionIndex
|
||||||
@@ -149,6 +155,8 @@ export const quizQuestionMarkdownUtils = {
|
|||||||
question.questionType === "essay" ||
|
question.questionType === "essay" ||
|
||||||
question.questionType === "short_answer"
|
question.questionType === "short_answer"
|
||||||
? question.questionType
|
? question.questionType
|
||||||
|
: question.questionType === QuestionType.SHORT_ANSWER_WITH_ANSWERS
|
||||||
|
? `\n${QuestionType.SHORT_ANSWER_WITH_ANSWERS}`
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
return `Points: ${question.points}\n${question.text}\n${answersText}${distractorText}${questionTypeIndicator}`;
|
return `Points: ${question.points}\n${question.text}\n${answersText}${distractorText}${questionTypeIndicator}`;
|
||||||
@@ -214,6 +222,7 @@ export const quizQuestionMarkdownUtils = {
|
|||||||
"multiple_choice",
|
"multiple_choice",
|
||||||
"multiple_answers",
|
"multiple_answers",
|
||||||
"matching",
|
"matching",
|
||||||
|
"short_answer=",
|
||||||
];
|
];
|
||||||
const answers = typesWithAnswers.includes(questionType)
|
const answers = typesWithAnswers.includes(questionType)
|
||||||
? getAnswers(linesWithoutPoints, questionIndex, questionType)
|
? getAnswers(linesWithoutPoints, questionIndex, questionType)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { QuestionType } from "../../quiz/localQuizQuestion";
|
import { getQuestionType } from "@/services/canvas/canvasQuizService";
|
||||||
|
import { QuestionType, zodQuestionType } from "../../quiz/localQuizQuestion";
|
||||||
import { quizMarkdownUtils } from "../../quiz/utils/quizMarkdownUtils";
|
import { quizMarkdownUtils } from "../../quiz/utils/quizMarkdownUtils";
|
||||||
import { quizQuestionMarkdownUtils } from "../../quiz/utils/quizQuestionMarkdownUtils";
|
import { quizQuestionMarkdownUtils } from "../../quiz/utils/quizQuestionMarkdownUtils";
|
||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
@@ -83,6 +84,39 @@ short_answer`;
|
|||||||
expect(questionMarkdown).toContain(expectedMarkdown);
|
expect(questionMarkdown).toContain(expectedMarkdown);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("short_answer= to markdown is correct", () => {
|
||||||
|
|
||||||
|
const name = "Test Quiz"
|
||||||
|
const rawMarkdownQuiz = `
|
||||||
|
ShuffleAnswers: true
|
||||||
|
OneQuestionAtATime: false
|
||||||
|
DueAt: 08/21/2023 23:59:00
|
||||||
|
LockAt: 08/21/2023 23: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?
|
||||||
|
*a) yes
|
||||||
|
*b) Yes
|
||||||
|
short_answer=
|
||||||
|
`;
|
||||||
|
|
||||||
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz, name);
|
||||||
|
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?
|
||||||
|
*a) yes
|
||||||
|
*b) Yes
|
||||||
|
short_answer=`;
|
||||||
|
expect(questionMarkdown).toContain(expectedMarkdown);
|
||||||
|
});
|
||||||
|
|
||||||
it("essay question to markdown is correct", () => {
|
it("essay question to markdown is correct", () => {
|
||||||
const name = "Test Quiz"
|
const name = "Test Quiz"
|
||||||
const rawMarkdownQuiz = `
|
const rawMarkdownQuiz = `
|
||||||
@@ -111,28 +145,85 @@ essay`;
|
|||||||
expect(questionMarkdown).toContain(expectedMarkdown);
|
expect(questionMarkdown).toContain(expectedMarkdown);
|
||||||
});
|
});
|
||||||
|
|
||||||
// it("Can parse short answer with auto graded answers", () => {
|
it("Can parse short answer with auto graded answers", () => {
|
||||||
// const rawMarkdownQuiz = `
|
const name = "Test Quiz"
|
||||||
// Name: Test Quiz
|
const rawMarkdownQuiz = `
|
||||||
// ShuffleAnswers: true
|
ShuffleAnswers: true
|
||||||
// OneQuestionAtATime: false
|
OneQuestionAtATime: false
|
||||||
// DueAt: 08/21/2023 23:59:00
|
DueAt: 08/21/2023 23:59:00
|
||||||
// LockAt: 08/21/2023 23:59:00
|
LockAt: 08/21/2023 23:59:00
|
||||||
// AssignmentGroup: Assignments
|
AssignmentGroup: Assignments
|
||||||
// AllowedAttempts: -1
|
AllowedAttempts: -1
|
||||||
// Description: this is the
|
Description: this is the
|
||||||
// multi line
|
multi line
|
||||||
// description
|
description
|
||||||
// ---
|
---
|
||||||
// Which events are triggered when the user clicks on an input field?
|
Which events are triggered when the user clicks on an input field?
|
||||||
// *a) test
|
*a) test
|
||||||
// short_answer=
|
*b) other
|
||||||
// `;
|
short_answer=
|
||||||
|
`;
|
||||||
|
|
||||||
// const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz, name);
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz, name);
|
||||||
// const firstQuestion = quiz.questions[0];
|
const firstQuestion = quiz.questions[0];
|
||||||
|
expect(firstQuestion.questionType).toBe(QuestionType.SHORT_ANSWER_WITH_ANSWERS)
|
||||||
|
expect(firstQuestion.answers.length).toBe(2);
|
||||||
|
expect(firstQuestion.answers[0].text).toBe("test");
|
||||||
|
expect(firstQuestion.answers[1].text).toBe("other");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Can parse short answer with auto graded answers", () => {
|
||||||
|
const name = "Test Quiz"
|
||||||
|
const rawMarkdownQuiz = `
|
||||||
|
ShuffleAnswers: true
|
||||||
|
OneQuestionAtATime: false
|
||||||
|
DueAt: 08/21/2023 23:59:00
|
||||||
|
LockAt: 08/21/2023 23: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?
|
||||||
|
*a) test
|
||||||
|
*b) other
|
||||||
|
short_answer=
|
||||||
|
`;
|
||||||
|
|
||||||
// expect(firstQuestion.questionType).toBe(QuestionType.SHORT_ANSWER_WITH_ANSWERS)
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz, name);
|
||||||
// });
|
const firstQuestion = quiz.questions[0];
|
||||||
|
expect(firstQuestion.questionType).toBe(QuestionType.SHORT_ANSWER_WITH_ANSWERS)
|
||||||
|
expect(firstQuestion.answers.length).toBe(2);
|
||||||
|
expect(firstQuestion.answers[0].text).toBe("test");
|
||||||
|
expect(firstQuestion.answers[1].text).toBe("other");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Has short_answer= type at the same position in types and zod types", () => {
|
||||||
|
expect(Object.values(zodQuestionType.Enum)).toEqual(Object.values(QuestionType));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Associates short_answer= questions with short_answer_question canvas question type", () => {
|
||||||
|
const name = "Test Quiz"
|
||||||
|
const rawMarkdownQuiz = `
|
||||||
|
ShuffleAnswers: true
|
||||||
|
OneQuestionAtATime: false
|
||||||
|
DueAt: 08/21/2023 23:59:00
|
||||||
|
LockAt: 08/21/2023 23: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?
|
||||||
|
*a) test
|
||||||
|
*b) other
|
||||||
|
short_answer=
|
||||||
|
`;
|
||||||
|
|
||||||
|
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz, name);
|
||||||
|
const firstQuestion = quiz.questions[0];
|
||||||
|
expect(getQuestionType(firstQuestion)).toBe("short_answer_question");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ const getAnswers = (
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getQuestionType = (
|
||||||
|
question: LocalQuizQuestion
|
||||||
|
) => {
|
||||||
|
return `${question.questionType.replace("=", "")}_question`;
|
||||||
|
}
|
||||||
|
|
||||||
const createQuestionOnly = async (
|
const createQuestionOnly = async (
|
||||||
canvasCourseId: number,
|
canvasCourseId: number,
|
||||||
canvasQuizId: number,
|
canvasQuizId: number,
|
||||||
@@ -41,7 +47,7 @@ const createQuestionOnly = async (
|
|||||||
const body = {
|
const body = {
|
||||||
question: {
|
question: {
|
||||||
question_text: markdownToHTMLSafe(question.text, settings),
|
question_text: markdownToHTMLSafe(question.text, settings),
|
||||||
question_type: `${question.questionType}_question`,
|
question_type: getQuestionType(question),
|
||||||
points_possible: question.points,
|
points_possible: question.points,
|
||||||
position,
|
position,
|
||||||
answers: getAnswers(question, settings),
|
answers: getAnswers(question, settings),
|
||||||
|
|||||||
Reference in New Issue
Block a user