mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Merge pull request #219 from ets-cfuhrman-pfe/JubaAzul/issue218
Some checks are pending
CI/CD Pipeline for Backend / build_and_push_backend (push) Waiting to run
CI/CD Pipeline for Nginx Router / build_and_push_nginx (push) Waiting to run
CI/CD Pipeline for Frontend / build_and_push_frontend (push) Waiting to run
Tests / tests (client) (push) Waiting to run
Tests / tests (server) (push) Waiting to run
Some checks are pending
CI/CD Pipeline for Backend / build_and_push_backend (push) Waiting to run
CI/CD Pipeline for Nginx Router / build_and_push_nginx (push) Waiting to run
CI/CD Pipeline for Frontend / build_and_push_frontend (push) Waiting to run
Tests / tests (client) (push) Waiting to run
Tests / tests (server) (push) Waiting to run
L'affichage de la bonne réponse dans les rétroactions ne fonctionne plus
This commit is contained in:
commit
4b9ded9a26
5 changed files with 146 additions and 39 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { act } from 'react';
|
||||
|
|
@ -17,21 +17,30 @@ const question = questions[0];
|
|||
|
||||
describe('MultipleChoiceQuestionDisplay', () => {
|
||||
const mockHandleOnSubmitAnswer = jest.fn();
|
||||
const sampleProps = {
|
||||
question: question,
|
||||
handleOnSubmitAnswer: mockHandleOnSubmitAnswer,
|
||||
showAnswer: false
|
||||
|
||||
const TestWrapper = ({ showAnswer }: { showAnswer: boolean }) => {
|
||||
const [showAnswerState, setShowAnswerState] = useState(showAnswer);
|
||||
|
||||
const handleOnSubmitAnswer = (answer: string) => {
|
||||
mockHandleOnSubmitAnswer(answer);
|
||||
setShowAnswerState(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<MemoryRouter>
|
||||
<MultipleChoiceQuestionDisplay
|
||||
question={question}
|
||||
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
||||
showAnswer={showAnswerState}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
);
|
||||
};
|
||||
|
||||
const choices = question.choices;
|
||||
|
||||
beforeEach(() => {
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<MultipleChoiceQuestionDisplay
|
||||
{...sampleProps}
|
||||
/>
|
||||
</MemoryRouter>);
|
||||
render(<TestWrapper showAnswer={false} />);
|
||||
});
|
||||
|
||||
test('renders the question and choices', () => {
|
||||
|
|
@ -55,7 +64,6 @@ describe('MultipleChoiceQuestionDisplay', () => {
|
|||
act(() => {
|
||||
fireEvent.click(choiceButton);
|
||||
});
|
||||
|
||||
const submitButton = screen.getByText('Répondre');
|
||||
act(() => {
|
||||
fireEvent.click(submitButton);
|
||||
|
|
@ -63,4 +71,51 @@ describe('MultipleChoiceQuestionDisplay', () => {
|
|||
|
||||
expect(mockHandleOnSubmitAnswer).toHaveBeenCalledWith('Choice 1');
|
||||
});
|
||||
});
|
||||
|
||||
it('should show ✅ next to the correct answer and ❌ next to the wrong answers when showAnswer is true', async () => {
|
||||
const choiceButton = screen.getByText('Choice 1').closest('button');
|
||||
if (!choiceButton) throw new Error('Choice button not found');
|
||||
|
||||
// Click on choiceButton
|
||||
act(() => {
|
||||
fireEvent.click(choiceButton);
|
||||
});
|
||||
|
||||
const button = screen.getByText("Répondre");
|
||||
|
||||
act(() => {
|
||||
fireEvent.click(button);
|
||||
});
|
||||
|
||||
// Wait for the DOM to update
|
||||
const correctAnswer = screen.getByText("Choice 1").closest('button');
|
||||
expect(correctAnswer).toBeInTheDocument();
|
||||
expect(correctAnswer?.textContent).toContain('✅');
|
||||
|
||||
const wrongAnswer1 = screen.getByText("Choice 2").closest('button');
|
||||
expect(wrongAnswer1).toBeInTheDocument();
|
||||
expect(wrongAnswer1?.textContent).toContain('❌');
|
||||
});
|
||||
|
||||
it('should not show ✅ or ❌ when repondre button is not clicked', async () => {
|
||||
const choiceButton = screen.getByText('Choice 1').closest('button');
|
||||
if (!choiceButton) throw new Error('Choice button not found');
|
||||
|
||||
// Click on choiceButton
|
||||
act(() => {
|
||||
fireEvent.click(choiceButton);
|
||||
});
|
||||
|
||||
// Check for correct answer
|
||||
const correctAnswer = screen.getByText("Choice 1").closest('button');
|
||||
expect(correctAnswer).toBeInTheDocument();
|
||||
expect(correctAnswer?.textContent).not.toContain('✅');
|
||||
|
||||
// Check for wrong answers
|
||||
const wrongAnswer1 = screen.getByText("Choice 2");
|
||||
expect(wrongAnswer1).toBeInTheDocument();
|
||||
expect(wrongAnswer1?.textContent).not.toContain('❌');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// TrueFalseQuestion.test.tsx
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { render, fireEvent, screen, act } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
|
|
@ -12,17 +12,28 @@ describe('TrueFalseQuestion Component', () => {
|
|||
const trueFalseQuestion =
|
||||
parse(`${sampleStem}{T}`)[0] as TrueFalseQuestion;
|
||||
|
||||
const sampleProps = {
|
||||
question: trueFalseQuestion,
|
||||
handleOnSubmitAnswer: mockHandleSubmitAnswer,
|
||||
showAnswer: false
|
||||
|
||||
const TestWrapper = ({ showAnswer }: { showAnswer: boolean }) => {
|
||||
const [showAnswerState, setShowAnswerState] = useState(showAnswer);
|
||||
|
||||
const handleOnSubmitAnswer = (answer: boolean) => {
|
||||
mockHandleSubmitAnswer(answer);
|
||||
setShowAnswerState(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<MemoryRouter>
|
||||
<TrueFalseQuestionDisplay
|
||||
question={trueFalseQuestion}
|
||||
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
||||
showAnswer={showAnswerState}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
);
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<TrueFalseQuestionDisplay {...sampleProps} />
|
||||
</MemoryRouter>);
|
||||
render(<TestWrapper showAnswer={false} />);
|
||||
});
|
||||
|
||||
it('renders correctly', () => {
|
||||
|
|
@ -73,4 +84,50 @@ describe('TrueFalseQuestion Component', () => {
|
|||
|
||||
expect(mockHandleSubmitAnswer).toHaveBeenCalledWith(false);
|
||||
});
|
||||
|
||||
|
||||
it('should show ✅ next to the correct answer and ❌ next to the wrong answers when showAnswer is true', async () => {
|
||||
const choiceButton = screen.getByText('Vrai').closest('button');
|
||||
if (!choiceButton) throw new Error('T button not found');
|
||||
|
||||
// Click on choiceButton
|
||||
act(() => {
|
||||
fireEvent.click(choiceButton);
|
||||
});
|
||||
|
||||
const button = screen.getByText("Répondre");
|
||||
|
||||
act(() => {
|
||||
fireEvent.click(button);
|
||||
});
|
||||
|
||||
// Wait for the DOM to update
|
||||
const correctAnswer = screen.getByText("Vrai").closest('button');
|
||||
expect(correctAnswer).toBeInTheDocument();
|
||||
expect(correctAnswer?.textContent).toContain('✅');
|
||||
|
||||
const wrongAnswer1 = screen.getByText("Faux").closest('button');
|
||||
expect(wrongAnswer1).toBeInTheDocument();
|
||||
expect(wrongAnswer1?.textContent).toContain('❌');
|
||||
});
|
||||
|
||||
it('should not show ✅ or ❌ when repondre button is not clicked', async () => {
|
||||
const choiceButton = screen.getByText('Vrai').closest('button');
|
||||
if (!choiceButton) throw new Error('Choice button not found');
|
||||
|
||||
// Click on choiceButton
|
||||
act(() => {
|
||||
fireEvent.click(choiceButton);
|
||||
});
|
||||
|
||||
// Check for correct answer
|
||||
const correctAnswer = screen.getByText("Vrai").closest('button');
|
||||
expect(correctAnswer).toBeInTheDocument();
|
||||
expect(correctAnswer?.textContent).not.toContain('✅');
|
||||
|
||||
// Check for wrong answers
|
||||
const wrongAnswer1 = screen.getByText("Faux");
|
||||
expect(wrongAnswer1).toBeInTheDocument();
|
||||
expect(wrongAnswer1?.textContent).not.toContain('❌');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ interface Props {
|
|||
}
|
||||
|
||||
const MultipleChoiceQuestionDisplay: React.FC<Props> = (props) => {
|
||||
|
||||
const { question, showAnswer, handleOnSubmitAnswer } = props;
|
||||
const [answer, setAnswer] = useState<string>();
|
||||
|
||||
|
|
@ -24,7 +23,6 @@ const MultipleChoiceQuestionDisplay: React.FC<Props> = (props) => {
|
|||
setAnswer(choice);
|
||||
};
|
||||
|
||||
|
||||
const alpha = Array.from(Array(26)).map((_e, i) => i + 65);
|
||||
const alphabet = alpha.map((x) => String.fromCharCode(x));
|
||||
return (
|
||||
|
|
@ -37,25 +35,23 @@ const MultipleChoiceQuestionDisplay: React.FC<Props> = (props) => {
|
|||
const selected = answer === choice.formattedText.text ? 'selected' : '';
|
||||
return (
|
||||
<div key={choice.formattedText.text + i} className="choice-container">
|
||||
<Button
|
||||
<Button
|
||||
variant="text"
|
||||
className="button-wrapper"
|
||||
onClick={() => !showAnswer && handleOnClickAnswer(choice.formattedText.text)}
|
||||
>
|
||||
{choice.formattedFeedback === null &&
|
||||
showAnswer &&
|
||||
(choice.isCorrect ? '✅' : '❌')}
|
||||
onClick={() => !showAnswer && handleOnClickAnswer(choice.formattedText.text)}>
|
||||
{showAnswer? (<div> {(choice.isCorrect ? '✅' : '❌')}</div>)
|
||||
:``}
|
||||
<div className={`circle ${selected}`}>{alphabet[i]}</div>
|
||||
<div className={`answer-text ${selected}`}>
|
||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(choice.formattedText) }} />
|
||||
</div>
|
||||
</Button>
|
||||
{choice.formattedFeedback && showAnswer && (
|
||||
{choice.formattedFeedback && showAnswer && (
|
||||
<div className="feedback-container mb-1 mt-1/2">
|
||||
{choice.isCorrect ? '✅' : '❌'}
|
||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(choice.formattedFeedback) }} />
|
||||
</div>
|
||||
)}
|
||||
</Button>
|
||||
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
|||
|
||||
const selectedTrue = answer ? 'selected' : '';
|
||||
const selectedFalse = answer !== undefined && !answer ? 'selected' : '';
|
||||
const correctAnswer = question.isTrue === answer;
|
||||
return (
|
||||
<div className="question-container">
|
||||
<div className="question content">
|
||||
|
|
@ -34,7 +33,7 @@ const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
|||
onClick={() => !showAnswer && setAnswer(true)}
|
||||
fullWidth
|
||||
>
|
||||
{showAnswer && (correctAnswer ? '✅' : '❌')}
|
||||
{showAnswer? (<div> {(question.isTrue ? '✅' : '❌')}</div>):``}
|
||||
<div className={`circle ${selectedTrue}`}>V</div>
|
||||
<div className={`answer-text ${selectedTrue}`}>Vrai</div>
|
||||
</Button>
|
||||
|
|
@ -43,7 +42,7 @@ const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
|||
onClick={() => !showAnswer && setAnswer(false)}
|
||||
fullWidth
|
||||
>
|
||||
{showAnswer && (!correctAnswer ? '✅' : '❌')}
|
||||
{showAnswer? (<div> {(!question.isTrue ? '✅' : '❌')}</div>):``}
|
||||
<div className={`circle ${selectedFalse}`}>F</div>
|
||||
<div className={`answer-text ${selectedFalse}`}>Faux</div>
|
||||
</Button>
|
||||
|
|
|
|||
2
server/package-lock.json
generated
2
server/package-lock.json
generated
|
|
@ -31,7 +31,7 @@
|
|||
"supertest": "^6.3.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": "18.x"
|
||||
"node": "20.x"
|
||||
}
|
||||
},
|
||||
"node_modules/@ampproject/remapping": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue