diff --git a/client/src/__tests__/components/Questions/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.test.tsx b/client/src/__tests__/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.test.tsx similarity index 96% rename from client/src/__tests__/components/Questions/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.test.tsx rename to client/src/__tests__/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.test.tsx index be6c8e9..f4198ed 100644 --- a/client/src/__tests__/components/Questions/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.test.tsx +++ b/client/src/__tests__/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.test.tsx @@ -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 diff --git a/client/src/__tests__/components/Questions/NumericalQuestionDisplay/NumericalQuestionDisplay.test.tsx b/client/src/__tests__/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay.test.tsx similarity index 94% rename from client/src/__tests__/components/Questions/NumericalQuestionDisplay/NumericalQuestionDisplay.test.tsx rename to client/src/__tests__/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay.test.tsx index 50741d8..639537a 100644 --- a/client/src/__tests__/components/Questions/NumericalQuestionDisplay/NumericalQuestionDisplay.test.tsx +++ b/client/src/__tests__/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay.test.tsx @@ -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( ` diff --git a/client/src/__tests__/components/Questions/Question.test.tsx b/client/src/__tests__/components/QuestionsDisplay/Question.test.tsx similarity index 85% rename from client/src/__tests__/components/Questions/Question.test.tsx rename to client/src/__tests__/components/QuestionsDisplay/Question.test.tsx index dc88b53..8c7546f 100644 --- a/client/src/__tests__/components/Questions/Question.test.tsx +++ b/client/src/__tests__/components/QuestionsDisplay/Question.test.tsx @@ -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(); }; - 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); diff --git a/client/src/__tests__/components/Questions/ShortAnswerQuestion/ShortAnswerQuestion.test.tsx b/client/src/__tests__/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.test.tsx similarity index 96% rename from client/src/__tests__/components/Questions/ShortAnswerQuestion/ShortAnswerQuestion.test.tsx rename to client/src/__tests__/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.test.tsx index 709e9d5..c4326eb 100644 --- a/client/src/__tests__/components/Questions/ShortAnswerQuestion/ShortAnswerQuestion.test.tsx +++ b/client/src/__tests__/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.test.tsx @@ -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(); diff --git a/client/src/__tests__/components/Questions/TrueFalseQuestion/TrueFalseQuestion.test.tsx b/client/src/__tests__/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.test.tsx similarity index 95% rename from client/src/__tests__/components/Questions/TrueFalseQuestion/TrueFalseQuestion.test.tsx rename to client/src/__tests__/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.test.tsx index 2a6ad77..9f60d6c 100644 --- a/client/src/__tests__/components/Questions/TrueFalseQuestion/TrueFalseQuestion.test.tsx +++ b/client/src/__tests__/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.test.tsx @@ -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(); diff --git a/client/src/__tests__/pages/Student/TeacherModeQuiz/TeacherModeQuiz.test.tsx b/client/src/__tests__/pages/Student/TeacherModeQuiz/TeacherModeQuiz.test.tsx index 2339a70..f3b3e57 100644 --- a/client/src/__tests__/pages/Student/TeacherModeQuiz/TeacherModeQuiz.test.tsx +++ b/client/src/__tests__/pages/Student/TeacherModeQuiz/TeacherModeQuiz.test.tsx @@ -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(); diff --git a/client/src/components/GiftTemplate/templates/Description.ts b/client/src/components/GiftTemplate/templates/Description.ts index b4e5d6e..52c18ed 100644 --- a/client/src/components/GiftTemplate/templates/Description.ts +++ b/client/src/components/GiftTemplate/templates/Description.ts @@ -1,22 +1,23 @@ -import { TemplateOptions, Description as DescriptionType } from './types'; +import { TemplateOptions } from './types'; import QuestionContainer from './QuestionContainer'; import Title from './Title'; -import textType from './TextType'; +import { textType } from './TextType'; import { ParagraphStyle } from '../constants'; import { state } from '.'; +import { Description } from 'gift-pegjs'; -type DescriptionOptions = TemplateOptions & DescriptionType; +type DescriptionOptions = TemplateOptions & Description; -export default function Description({ title, stem }: DescriptionOptions): string { +export default function DescriptionTemplate({ title, formattedStem}: DescriptionOptions): string { return `${QuestionContainer({ children: [ Title({ type: 'Description', title: title }), - `

${textType({ - text: stem - })}

` + `

+ ${textType(formattedStem)} +

` ] })}`; } diff --git a/client/src/components/GiftTemplate/templates/TextType.ts b/client/src/components/GiftTemplate/templates/TextType.ts index 0247d3f..799981f 100644 --- a/client/src/components/GiftTemplate/templates/TextType.ts +++ b/client/src/components/GiftTemplate/templates/TextType.ts @@ -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
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>)$/gm, '$2'); default: - throw new Error(`Unsupported text format: ${text.format}`); + throw new Error(`Unsupported text format: ${formattedText.format}`); } } diff --git a/client/src/components/GiftTemplate/templates/index.ts b/client/src/components/GiftTemplate/templates/index.ts index f5f5fde..555b99d 100644 --- a/client/src/components/GiftTemplate/templates/index.ts +++ b/client/src/components/GiftTemplate/templates/index.ts @@ -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): export { Category, - Description, + DescriptionTemplate as Description, Essay, Matching, MultipleChoice, diff --git a/client/src/components/GiftTemplate/templates/types.d.ts b/client/src/components/GiftTemplate/templates/types.d.ts index f7160fd..23081c8 100644 --- a/client/src/components/GiftTemplate/templates/types.d.ts +++ b/client/src/components/GiftTemplate/templates/types.d.ts @@ -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; +// } diff --git a/client/src/components/Questions/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx b/client/src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx similarity index 100% rename from client/src/components/Questions/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx rename to client/src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx diff --git a/client/src/components/Questions/NumericalQuestionDisplay/NumericalQuestionDisplay.tsx b/client/src/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay.tsx similarity index 100% rename from client/src/components/Questions/NumericalQuestionDisplay/NumericalQuestionDisplay.tsx rename to client/src/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay.tsx diff --git a/client/src/components/Questions/QuestionDisplay.tsx b/client/src/components/QuestionsDisplay/QuestionDisplay.tsx similarity index 100% rename from client/src/components/Questions/QuestionDisplay.tsx rename to client/src/components/QuestionsDisplay/QuestionDisplay.tsx diff --git a/client/src/components/Questions/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx b/client/src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx similarity index 100% rename from client/src/components/Questions/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx rename to client/src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx diff --git a/client/src/components/Questions/TrueFalseQuestion/TrueFalseQuestion.tsx b/client/src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.tsx similarity index 100% rename from client/src/components/Questions/TrueFalseQuestion/TrueFalseQuestion.tsx rename to client/src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.tsx diff --git a/client/src/components/Questions/questionStyle.css b/client/src/components/QuestionsDisplay/questionStyle.css similarity index 100% rename from client/src/components/Questions/questionStyle.css rename to client/src/components/QuestionsDisplay/questionStyle.css