mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Compare commits
2 commits
ffa2200606
...
00e45f0f09
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00e45f0f09 | ||
|
|
54dc6b48a6 |
17 changed files with 66 additions and 56 deletions
|
|
@ -1,10 +1,10 @@
|
|||
import React from 'react';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import MultipleChoiceQuestionDisplay from 'src/components/Questions/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay';
|
||||
import { act } from 'react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { MultipleChoiceQuestion, parse } from 'gift-pegjs';
|
||||
import MultipleChoiceQuestionDisplay from 'src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay';
|
||||
|
||||
const questions = parse(
|
||||
`::Sample Question 1:: Question stem
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
// NumericalQuestion.test.tsx
|
||||
import React from 'react';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import NumericalQuestionDisplay from 'src/components/Questions/NumericalQuestionDisplay/NumericalQuestionDisplay';
|
||||
import { NumericalQuestion, parse, ParsedGIFTQuestion } from 'gift-pegjs';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import NumericalQuestionDisplay from 'src/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay';
|
||||
|
||||
const questions = parse(
|
||||
`
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
import React from 'react';
|
||||
import { render, screen, fireEvent, within } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import QuestionDisplay from 'src/components/Questions/QuestionDisplay';
|
||||
import QuestionDisplay from 'src/components/QuestionsDisplay/QuestionDisplay';
|
||||
import { parse, Question } from 'gift-pegjs';
|
||||
|
||||
describe('Questions Component', () => {
|
||||
|
|
@ -29,13 +29,23 @@ describe('Questions Component', () => {
|
|||
render(<QuestionDisplay question={question} {...sampleProps} />);
|
||||
};
|
||||
|
||||
it('parsed questions correctly', () => {
|
||||
expect(sampleTrueFalseQuestion.type).toBe('TF');
|
||||
expect(sampleMultipleChoiceQuestion.type).toBe('MC');
|
||||
expect(sampleNumericalQuestion.type).toBe('Numerical');
|
||||
expect(sampleShortAnswerQuestion.type).toBe('Short');
|
||||
});
|
||||
describe('question type parsing', () => {
|
||||
it('parses true/false question type correctly', () => {
|
||||
expect(sampleTrueFalseQuestion.type).toBe('TF');
|
||||
});
|
||||
|
||||
it('parses multiple choice question type correctly', () => {
|
||||
expect(sampleMultipleChoiceQuestion.type).toBe('MC');
|
||||
});
|
||||
|
||||
it('parses numerical question type correctly', () => {
|
||||
expect(sampleNumericalQuestion.type).toBe('Numerical');
|
||||
});
|
||||
|
||||
it('parses short answer question type correctly', () => {
|
||||
expect(sampleShortAnswerQuestion.type).toBe('Short');
|
||||
});
|
||||
});
|
||||
it('renders correctly for True/False question', () => {
|
||||
renderComponent(sampleTrueFalseQuestion);
|
||||
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
// ShortAnswerQuestion.test.tsx
|
||||
import React from 'react';
|
||||
import { render, screen, fireEvent, within } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import ShortAnswerQuestionDisplay from 'src/components/Questions/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay';
|
||||
import { parse, ShortAnswerQuestion } from 'gift-pegjs';
|
||||
import ShortAnswerQuestionDisplay from 'src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay';
|
||||
|
||||
describe('ShortAnswerQuestion Component', () => {
|
||||
const mockHandleSubmitAnswer = jest.fn();
|
||||
|
|
@ -2,8 +2,8 @@
|
|||
import React from 'react';
|
||||
import { render, fireEvent, screen, act } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import TrueFalseQuestion from 'src/components/Questions/TrueFalseQuestion/TrueFalseQuestion';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import TrueFalseQuestion from 'src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay';
|
||||
|
||||
describe('TrueFalseQuestion Component', () => {
|
||||
const mockHandleSubmitAnswer = jest.fn();
|
||||
|
|
@ -3,7 +3,7 @@ import React from 'react';
|
|||
import { render, fireEvent, act } from '@testing-library/react';
|
||||
import { screen } from '@testing-library/dom';
|
||||
import '@testing-library/jest-dom';
|
||||
import { parse } from 'gift-pegjs';
|
||||
import { MultipleChoiceQuestion, parse } from 'gift-pegjs';
|
||||
|
||||
import TeacherModeQuiz from 'src/components/TeacherModeQuiz/TeacherModeQuiz';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
|
|
@ -14,7 +14,11 @@ const mockGiftQuestions = parse(
|
|||
|
||||
|
||||
describe('TeacherModeQuiz', () => {
|
||||
const mockQuestion = mockGiftQuestions[0];
|
||||
it ('renders the initial question as MultipleChoiceQuestion', () => {
|
||||
expect(mockGiftQuestions[0].type).toBe('MC');
|
||||
});
|
||||
|
||||
const mockQuestion = mockGiftQuestions[0] as MultipleChoiceQuestion;
|
||||
mockQuestion.id = '1';
|
||||
|
||||
const mockSubmitAnswer = jest.fn();
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
import { TemplateOptions, Description as DescriptionType } from './types';
|
||||
import QuestionContainer from './QuestionContainer';
|
||||
import Title from './Title';
|
||||
import textType from './TextType';
|
||||
import { ParagraphStyle } from '../constants';
|
||||
import { state } from '.';
|
||||
|
||||
type DescriptionOptions = TemplateOptions & DescriptionType;
|
||||
|
||||
export default function Description({ title, stem }: DescriptionOptions): string {
|
||||
return `${QuestionContainer({
|
||||
children: [
|
||||
Title({
|
||||
type: 'Description',
|
||||
title: title
|
||||
}),
|
||||
`<p style="${ParagraphStyle(state.theme)}">${textType({
|
||||
text: stem
|
||||
})}</p>`
|
||||
]
|
||||
})}`;
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import { TemplateOptions } from './types';
|
||||
import QuestionContainer from './QuestionContainer';
|
||||
import Title from './Title';
|
||||
import { textType } from './TextType';
|
||||
import { ParagraphStyle } from '../constants';
|
||||
import { state } from '.';
|
||||
import { Description } from 'gift-pegjs';
|
||||
|
||||
type DescriptionOptions = TemplateOptions & Description;
|
||||
|
||||
export default function DescriptionTemplate({ title, formattedStem}: DescriptionOptions): string {
|
||||
return `${QuestionContainer({
|
||||
children: [
|
||||
Title({
|
||||
type: 'Description',
|
||||
title: title
|
||||
}),
|
||||
`<p style="${ParagraphStyle(state.theme)}">
|
||||
${textType(formattedStem)}
|
||||
</p>`
|
||||
]
|
||||
})}`;
|
||||
}
|
||||
|
|
@ -1,10 +1,7 @@
|
|||
import { marked } from 'marked';
|
||||
import katex from 'katex';
|
||||
import { TemplateOptions, TextFormat } from './types';
|
||||
import { TextFormat } from 'gift-pegjs';
|
||||
|
||||
interface TextTypeOptions extends TemplateOptions {
|
||||
text: TextFormat;
|
||||
}
|
||||
|
||||
export function formatLatex(text: string): string {
|
||||
return text
|
||||
|
|
@ -28,10 +25,10 @@ export function formatLatex(text: string): string {
|
|||
* @see marked
|
||||
* @see katex
|
||||
*/
|
||||
export function textType({ text }: TextTypeOptions) {
|
||||
const formatText = formatLatex(text.text.trim()); // latex needs pure "&", ">", etc. Must not be escaped
|
||||
export function textType(formattedText: TextFormat): string {
|
||||
const formatText = formatLatex(formattedText.text.trim()); // latex needs pure "&", ">", etc. Must not be escaped
|
||||
let parsedText = '';
|
||||
switch (text.format) {
|
||||
switch (formattedText.format) {
|
||||
case 'moodle':
|
||||
case 'plain':
|
||||
// Replace newlines with <br> tags
|
||||
|
|
@ -43,6 +40,6 @@ export function textType({ text }: TextTypeOptions) {
|
|||
parsedText = marked.parse(formatText, { breaks: true }) as string; // https://github.com/markedjs/marked/discussions/3219
|
||||
return parsedText.replace(/(^<p>)(.*?)(<\/p>)$/gm, '$2');
|
||||
default:
|
||||
throw new Error(`Unsupported text format: ${text.format}`);
|
||||
throw new Error(`Unsupported text format: ${formattedText.format}`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import Category from './Category';
|
||||
import Description from './Description';
|
||||
import DescriptionTemplate from './Description';
|
||||
import Essay from './Essay';
|
||||
import Matching from './Matching';
|
||||
import MultipleChoice from './MultipleChoice';
|
||||
|
|
@ -67,7 +67,7 @@ export function ErrorTemplate(text: string, options?: Partial<DisplayOptions>):
|
|||
|
||||
export {
|
||||
Category,
|
||||
Description,
|
||||
DescriptionTemplate as Description,
|
||||
Essay,
|
||||
Matching,
|
||||
MultipleChoice,
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ export interface DisplayOptions {
|
|||
preview: boolean;
|
||||
}
|
||||
|
||||
export {
|
||||
QuestionType, FormatType, NumericalType, TextFormat, NumericalFormat, TextChoice, NumericalChoice, Question, Description, Category, MultipleChoice, ShortAnswer, Numerical, Essay, TrueFalse,
|
||||
Matching, Match, GIFTQuestion } from 'gift-pegjs';
|
||||
// export {
|
||||
// QuestionType, FormatType, NumericalType, TextFormat, NumericalFormat, TextChoice, NumericalChoice, Question, Description, Category, MultipleChoice, ShortAnswer, Numerical, Essay, TrueFalse,
|
||||
// Matching, Match, GIFTQuestion } from 'gift-pegjs';
|
||||
|
||||
export interface Choice {
|
||||
isCorrect: boolean;
|
||||
weight: number | null;
|
||||
text: TextFormat | NumericalFormat;
|
||||
feedback: TextFormat | null;
|
||||
}
|
||||
// export interface Choice {
|
||||
// isCorrect: boolean;
|
||||
// weight: number | null;
|
||||
// text: TextFormat | NumericalFormat;
|
||||
// feedback: TextFormat | null;
|
||||
// }
|
||||
|
|
|
|||
Loading…
Reference in a new issue