= {};
+// return {
+// getItem: (key: string) => store[key] || null,
+// setItem: (key: string, value: string) => (store[key] = value.toString()),
+// clear: () => (store = {}),
+// };
+// })();
+// Object.defineProperty(window, 'localStorage', { value: localStorageMock });
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: jest.fn(),
}));
+// NOTE: these tests are for an old version that kept quizzes in local storage and had no login
describe.skip('Dashboard Component', () => {
- beforeEach(() => {
- localStorage.setItem('quizzes', JSON.stringify([]));
- });
+ // beforeEach(() => {
+ // localStorage.setItem('quizzes', JSON.stringify([]));
+ // });
test('renders Dashboard with default state', () => {
render(
@@ -33,7 +35,7 @@ describe.skip('Dashboard Component', () => {
expect(screen.getByText(/Tableau de bord/i)).toBeInTheDocument();
});
- test('adds a quiz and checks if it is displayed', () => {
+ test.skip('adds a quiz and checks if it is displayed', () => {
const mockQuizzes = [
{
id: '1',
@@ -52,17 +54,18 @@ describe.skip('Dashboard Component', () => {
expect(screen.getByText(/Sample Quiz/i)).toBeInTheDocument();
});
- test('opens ImportModal when "Importer" button is clicked', async () => {
+ test.skip('opens ImportModal when "Importer" button is clicked', async () => {
render(
);
- fireEvent.click(screen.getByText(/Importer/i));
- await waitFor(() => {
- expect(screen.getByText(/Importation de quiz/i)).toBeInTheDocument();
+ act(() => {
+ fireEvent.click(screen.getByText(/Importer/i));
});
+
+ expect(screen.getByText(/Importation de quiz/i)).toBeInTheDocument();
});
});
diff --git a/client/src/__tests__/services/QuizService.test.tsx b/client/src/__tests__/services/QuizService.test.tsx
index 5806e14..10ed28d 100644
--- a/client/src/__tests__/services/QuizService.test.tsx
+++ b/client/src/__tests__/services/QuizService.test.tsx
@@ -28,6 +28,7 @@ Object.defineProperty(window, 'localStorage', {
value: localStorageMock
});
+// NOTE: this suite seems to be designed around local storage of quizzes (older version, before a database)
describe.skip('QuizService', () => {
const mockQuizzes: QuizType[] = [
{ folderId: 'test', userId: 'user', _id: 'quiz1', title: 'Quiz One', content: ['Q1', 'Q2'], created_at: new Date('2024-09-15'), updated_at: new Date('2024-09-15') },
diff --git a/client/src/components/GiftTemplate/index.ts b/client/src/components/GiftTemplate/index.ts
index fc79c92..1f39302 100644
--- a/client/src/components/GiftTemplate/index.ts
+++ b/client/src/components/GiftTemplate/index.ts
@@ -67,8 +67,8 @@ const multiple: GIFTQuestion[] = [
hasEmbeddedAnswers: false,
globalFeedback: null,
isTrue: false,
- incorrectFeedback: null,
- correctFeedback: null
+ falseFeedback: null,
+ trueFeedback: null
},
{
type: 'Short',
diff --git a/client/src/components/GiftTemplate/templates/TextType.ts b/client/src/components/GiftTemplate/templates/TextType.ts
index 3d6b31d..045c78b 100644
--- a/client/src/components/GiftTemplate/templates/TextType.ts
+++ b/client/src/components/GiftTemplate/templates/TextType.ts
@@ -28,7 +28,7 @@ function formatLatex(text: string): string {
* @see marked
* @see katex
*/
-export default function TextType({ text }: TextTypeOptions): string {
+export default function TextType({ text }: TextTypeOptions) {
const formatText = formatLatex(text.text.trim()); // latex needs pure "&", ">", etc. Must not be escaped
switch (text.format) {
@@ -40,12 +40,8 @@ export default function TextType({ text }: TextTypeOptions): string {
// Strip outer paragraph tags (not a great approach with regex)
return formatText.replace(/(^)(.*?)(<\/p>)$/gm, '$2');
case 'markdown':
- return (
- marked
- .parse(formatText, { breaks: true }) // call marked.parse instead of marked
- // Strip outer paragraph tags
- .replace(/(^
)(.*?)(<\/p>)$/gm, '$2')
- );
+ const 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}`);
}
diff --git a/client/src/components/GiftTemplate/templates/TrueFalse.ts b/client/src/components/GiftTemplate/templates/TrueFalse.ts
index 378976a..2318dde 100644
--- a/client/src/components/GiftTemplate/templates/TrueFalse.ts
+++ b/client/src/components/GiftTemplate/templates/TrueFalse.ts
@@ -13,8 +13,8 @@ export default function TrueFalse({
title,
isTrue,
stem,
- correctFeedback,
- incorrectFeedback,
+ trueFeedback: trueFeedback,
+ falseFeedback: falseFeedback,
globalFeedback
}: TrueFalseOptions): string {
const choices: TextChoice[] = [
@@ -25,7 +25,7 @@ export default function TrueFalse({
},
isCorrect: isTrue,
weight: null,
- feedback: isTrue ? correctFeedback : incorrectFeedback
+ feedback: isTrue ? trueFeedback : falseFeedback
},
{
text: {
@@ -34,7 +34,7 @@ export default function TrueFalse({
},
isCorrect: !isTrue,
weight: null,
- feedback: !isTrue ? correctFeedback : incorrectFeedback
+ feedback: !isTrue ? trueFeedback : falseFeedback
}
];
diff --git a/client/src/components/GiftTemplate/templates/types.d.ts b/client/src/components/GiftTemplate/templates/types.d.ts
index 03d5cbd..f7160fd 100644
--- a/client/src/components/GiftTemplate/templates/types.d.ts
+++ b/client/src/components/GiftTemplate/templates/types.d.ts
@@ -12,31 +12,9 @@ export interface DisplayOptions {
preview: boolean;
}
-export type QuestionType =
- | 'Description'
- | 'Category'
- | 'MC'
- | 'Numerical'
- | 'Short'
- | 'Essay'
- | 'TF'
- | 'Matching';
-
-export type FormatType = 'moodle' | 'html' | 'markdown' | 'plain';
-export type NumericalType = 'simple' | 'range' | 'high-low';
-
-export interface TextFormat {
- format: FormatType;
- text: string;
-}
-
-export interface NumericalFormat {
- type: NumericalType;
- number?: number;
- range?: number;
- numberHigh?: number;
- numberLow?: number;
-}
+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;
@@ -44,77 +22,3 @@ export interface Choice {
text: TextFormat | NumericalFormat;
feedback: TextFormat | null;
}
-
-export interface TextChoice extends Choice {
- text: TextFormat;
-}
-
-export interface NumericalChoice extends Choice {
- text: NumericalFormat;
-}
-
-export interface Question {
- type: QuestionType;
- title: string | null;
- stem: TextFormat;
- hasEmbeddedAnswers: boolean;
- globalFeedback: TextFormat | null;
-}
-
-export interface Description {
- type: Extract;
- title: string | null;
- stem: TextFormat;
- hasEmbeddedAnswers: boolean;
-}
-
-export interface Category {
- type: Extract;
- title: string;
-}
-
-export interface MultipleChoice extends Question {
- type: Extract;
- choices: TextChoice[];
-}
-
-export interface ShortAnswer extends Question {
- type: Extract;
- choices: TextChoice[];
-}
-
-export interface Numerical extends Question {
- type: Extract;
- choices: NumericalChoice[] | NumericalFormat;
-}
-
-export interface Essay extends Question {
- type: Extract;
-}
-
-export interface TrueFalse extends Question {
- type: Extract;
- isTrue: boolean;
- incorrectFeedback: TextFormat | null;
- correctFeedback: TextFormat | null;
-}
-
-export interface Matching extends Question {
- type: Extract;
- matchPairs: Match[];
-}
-
-export interface Match {
- subquestion: TextFormat;
- subanswer: string;
-}
-
-export type GIFTQuestion =
- | Description
- | Category
- | MultipleChoice
- | ShortAnswer
- | Numerical
- | Essay
- | TrueFalse
- | Matching;
diff --git a/client/src/components/Questions/MultipleChoiceQuestion/MultipleChoiceQuestion.tsx b/client/src/components/Questions/MultipleChoiceQuestion/MultipleChoiceQuestion.tsx
index 5e303be..9e4fb50 100644
--- a/client/src/components/Questions/MultipleChoiceQuestion/MultipleChoiceQuestion.tsx
+++ b/client/src/components/Questions/MultipleChoiceQuestion/MultipleChoiceQuestion.tsx
@@ -14,7 +14,7 @@ type Choices = {
};
interface Props {
- questionContent: TextFormat;
+ questionStem: TextFormat;
choices: Choices[];
globalFeedback?: string | undefined;
handleOnSubmitAnswer?: (answer: string) => void;
@@ -22,7 +22,7 @@ interface Props {
}
const MultipleChoiceQuestion: React.FC = (props) => {
- const { questionContent, choices, showAnswer, handleOnSubmitAnswer, globalFeedback } = props;
+ const { questionStem: questionContent, choices, showAnswer, handleOnSubmitAnswer, globalFeedback } = props;
const [answer, setAnswer] = useState();
useEffect(() => {
diff --git a/client/src/components/Questions/Question.tsx b/client/src/components/Questions/Question.tsx
index 28e4d9b..c5af0a6 100644
--- a/client/src/components/Questions/Question.tsx
+++ b/client/src/components/Questions/Question.tsx
@@ -41,7 +41,7 @@ const Question: React.FC = ({
case 'MC':
questionTypeComponent = (
= (props) => {
return (