mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Compare commits
No commits in common. "731841a315679bf5660170ed78ca22ea1acd31c4" and "61a5cf13301efcf6d3e4d17927e7201a0e00de01" have entirely different histories.
731841a315
...
61a5cf1330
9 changed files with 54 additions and 131 deletions
|
|
@ -1,21 +1,44 @@
|
||||||
import '@testing-library/jest-dom';
|
|
||||||
import { render, screen, fireEvent } from '@testing-library/react';
|
|
||||||
import { parse, NumericalQuestion } from 'gift-pegjs';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { render, screen, fireEvent } from '@testing-library/react';
|
||||||
|
import '@testing-library/jest-dom';
|
||||||
|
import { NumericalQuestion, parse, ParsedGIFTQuestion } from 'gift-pegjs';
|
||||||
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import NumericalQuestionDisplay from 'src/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay';
|
import NumericalQuestionDisplay from 'src/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay';
|
||||||
|
|
||||||
describe('NumericalQuestionDisplay Component', () => {
|
const questions = parse(
|
||||||
|
`
|
||||||
|
::Sample Question 1:: Question stem
|
||||||
|
{
|
||||||
|
#5..10
|
||||||
|
}`
|
||||||
|
) as ParsedGIFTQuestion[];
|
||||||
|
|
||||||
|
const question = questions[0] as NumericalQuestion;
|
||||||
|
|
||||||
|
describe('NumericalQuestion parse', () => {
|
||||||
|
const q = questions[0];
|
||||||
|
|
||||||
|
it('The question is Numerical', () => {
|
||||||
|
expect(q.type).toBe('Numerical');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('NumericalQuestion Component', () => {
|
||||||
const mockHandleOnSubmitAnswer = jest.fn();
|
const mockHandleOnSubmitAnswer = jest.fn();
|
||||||
const question =
|
|
||||||
parse('::Sample Numerical Question:: What is 2+2? {#4}')[0] as NumericalQuestion;
|
|
||||||
|
|
||||||
const sampleProps = {
|
const sampleProps = {
|
||||||
|
question: question,
|
||||||
handleOnSubmitAnswer: mockHandleOnSubmitAnswer,
|
handleOnSubmitAnswer: mockHandleOnSubmitAnswer,
|
||||||
showAnswer: false
|
showAnswer: false
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
render(<NumericalQuestionDisplay question={question} {...sampleProps} />);
|
render(
|
||||||
|
<MemoryRouter>
|
||||||
|
<NumericalQuestionDisplay
|
||||||
|
{...sampleProps}
|
||||||
|
/>
|
||||||
|
</MemoryRouter>);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders correctly', () => {
|
it('renders correctly', () => {
|
||||||
|
|
@ -32,13 +55,13 @@ describe('NumericalQuestionDisplay Component', () => {
|
||||||
expect(inputElement.value).toBe('7');
|
expect(inputElement.value).toBe('7');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Submit button should be disabled if nothing is entered', () => {
|
it('Submit button should be disable if nothing is entered', () => {
|
||||||
const submitButton = screen.getByText('Répondre');
|
const submitButton = screen.getByText('Répondre');
|
||||||
|
|
||||||
expect(submitButton).toBeDisabled();
|
expect(submitButton).toBeDisabled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not submit answer if nothing is entered', () => {
|
it('not submited answer if nothing is entered', () => {
|
||||||
const submitButton = screen.getByText('Répondre');
|
const submitButton = screen.getByText('Répondre');
|
||||||
|
|
||||||
fireEvent.click(submitButton);
|
fireEvent.click(submitButton);
|
||||||
|
|
@ -56,52 +79,4 @@ describe('NumericalQuestionDisplay Component', () => {
|
||||||
|
|
||||||
expect(mockHandleOnSubmitAnswer).toHaveBeenCalledWith(7);
|
expect(mockHandleOnSubmitAnswer).toHaveBeenCalledWith(7);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
it('renders correctly with the correct answer shown', () => {
|
|
||||||
render(<NumericalQuestionDisplay question={question} {...sampleProps} showAnswer={true} passedAnswer={4} />);
|
|
||||||
expect(screen.getByText('Réponse(s) accepté(es):')).toBeInTheDocument();
|
|
||||||
expect(screen.getAllByText('4')).toHaveLength(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('handles input change and checks if the answer is correct', () => {
|
|
||||||
const inputElement = screen.getByTestId('number-input') as HTMLInputElement;
|
|
||||||
|
|
||||||
fireEvent.change(inputElement, { target: { value: '4' } });
|
|
||||||
|
|
||||||
expect(inputElement.value).toBe('4');
|
|
||||||
|
|
||||||
const submitButton = screen.getByText('Répondre');
|
|
||||||
fireEvent.click(submitButton);
|
|
||||||
|
|
||||||
expect(mockHandleOnSubmitAnswer).toHaveBeenCalledWith(4);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('submits the correct answer', () => {
|
|
||||||
const inputElement = screen.getByTestId('number-input') as HTMLInputElement;
|
|
||||||
|
|
||||||
fireEvent.change(inputElement, { target: { value: '4' } });
|
|
||||||
|
|
||||||
const submitButton = screen.getByText('Répondre');
|
|
||||||
fireEvent.click(submitButton);
|
|
||||||
|
|
||||||
expect(mockHandleOnSubmitAnswer).toHaveBeenCalledWith(4);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('submits an incorrect answer', () => {
|
|
||||||
const inputElement = screen.getByTestId('number-input') as HTMLInputElement;
|
|
||||||
|
|
||||||
fireEvent.change(inputElement, { target: { value: '5' } });
|
|
||||||
|
|
||||||
const submitButton = screen.getByText('Répondre');
|
|
||||||
fireEvent.click(submitButton);
|
|
||||||
|
|
||||||
expect(mockHandleOnSubmitAnswer).toHaveBeenCalledWith(5);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('displays feedback when the answer is shown', () => {
|
|
||||||
render(<NumericalQuestionDisplay question={question} {...sampleProps} showAnswer={true} passedAnswer={5} />);
|
|
||||||
expect(screen.getByText('❌ Incorrect!')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('Réponse(s) accepté(es):')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('5')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import '@testing-library/jest-dom';
|
|
||||||
import { render, screen, fireEvent } from '@testing-library/react';
|
|
||||||
import { parse, ShortAnswerQuestion } from 'gift-pegjs';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { render, screen, fireEvent, within } from '@testing-library/react';
|
||||||
|
import '@testing-library/jest-dom';
|
||||||
|
import { parse, ShortAnswerQuestion } from 'gift-pegjs';
|
||||||
import ShortAnswerQuestionDisplay from 'src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay';
|
import ShortAnswerQuestionDisplay from 'src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay';
|
||||||
|
|
||||||
describe('ShortAnswerQuestion Component', () => {
|
describe('ShortAnswerQuestion Component', () => {
|
||||||
|
|
@ -20,26 +20,28 @@ describe('ShortAnswerQuestion Component', () => {
|
||||||
|
|
||||||
it('renders correctly', () => {
|
it('renders correctly', () => {
|
||||||
expect(screen.getByText(question.formattedStem.text)).toBeInTheDocument();
|
expect(screen.getByText(question.formattedStem.text)).toBeInTheDocument();
|
||||||
const inputElement = screen.getByRole('textbox') as HTMLInputElement;
|
const container = screen.getByLabelText('short-answer-input');
|
||||||
|
const inputElement = within(container).getByRole('textbox') as HTMLInputElement;
|
||||||
expect(inputElement).toBeInTheDocument();
|
expect(inputElement).toBeInTheDocument();
|
||||||
expect(screen.getByText('Répondre')).toBeInTheDocument();
|
expect(screen.getByText('Répondre')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles input change correctly', () => {
|
it('handles input change correctly', () => {
|
||||||
const inputElement = screen.getByRole('textbox') as HTMLInputElement;
|
const container = screen.getByLabelText('short-answer-input');
|
||||||
|
const inputElement = within(container).getByRole('textbox') as HTMLInputElement;
|
||||||
|
|
||||||
fireEvent.change(inputElement, { target: { value: 'User Input' } });
|
fireEvent.change(inputElement, { target: { value: 'User Input' } });
|
||||||
|
|
||||||
expect(inputElement.value).toBe('User Input');
|
expect(inputElement.value).toBe('User Input');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Submit button should be disabled if nothing is entered', () => {
|
it('Submit button should be disable if nothing is entered', () => {
|
||||||
const submitButton = screen.getByText('Répondre');
|
const submitButton = screen.getByText('Répondre');
|
||||||
|
|
||||||
expect(submitButton).toBeDisabled();
|
expect(submitButton).toBeDisabled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not submit answer if nothing is entered', () => {
|
it('not submitted answer if nothing is entered', () => {
|
||||||
const submitButton = screen.getByText('Répondre');
|
const submitButton = screen.getByText('Répondre');
|
||||||
|
|
||||||
fireEvent.click(submitButton);
|
fireEvent.click(submitButton);
|
||||||
|
|
@ -47,51 +49,17 @@ describe('ShortAnswerQuestion Component', () => {
|
||||||
expect(mockHandleSubmitAnswer).not.toHaveBeenCalled();
|
expect(mockHandleSubmitAnswer).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders correctly with the correct answer shown', () => {
|
it('submits answer correctly', () => {
|
||||||
render(<ShortAnswerQuestionDisplay question={question} {...sampleProps} showAnswer={true} passedAnswer="Correct Answer" />);
|
const container = screen.getByLabelText('short-answer-input');
|
||||||
expect(screen.getByText('Réponse(s) accepté(es):')).toBeInTheDocument();
|
const inputElement = within(container).getByRole('textbox') as HTMLInputElement;
|
||||||
expect(screen.getByText('Correct Answer')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('handles input change and checks if the answer is correct', () => {
|
|
||||||
const inputElement = screen.getByRole('textbox') as HTMLInputElement;
|
|
||||||
|
|
||||||
fireEvent.change(inputElement, { target: { value: 'Correct Answer' } });
|
|
||||||
|
|
||||||
expect(inputElement.value).toBe('Correct Answer');
|
|
||||||
|
|
||||||
|
// const inputElement = screen.getByRole('textbox', { name: 'short-answer-input'}) as HTMLInputElement;
|
||||||
const submitButton = screen.getByText('Répondre');
|
const submitButton = screen.getByText('Répondre');
|
||||||
|
|
||||||
|
fireEvent.change(inputElement, { target: { value: 'User Input' } });
|
||||||
|
|
||||||
fireEvent.click(submitButton);
|
fireEvent.click(submitButton);
|
||||||
|
|
||||||
expect(mockHandleSubmitAnswer).toHaveBeenCalledWith('Correct Answer');
|
expect(mockHandleSubmitAnswer).toHaveBeenCalledWith('User Input');
|
||||||
});
|
});
|
||||||
|
});
|
||||||
it('submits the correct answer', () => {
|
|
||||||
const inputElement = screen.getByRole('textbox') as HTMLInputElement;
|
|
||||||
|
|
||||||
fireEvent.change(inputElement, { target: { value: 'Correct Answer' } });
|
|
||||||
|
|
||||||
const submitButton = screen.getByText('Répondre');
|
|
||||||
fireEvent.click(submitButton);
|
|
||||||
|
|
||||||
expect(mockHandleSubmitAnswer).toHaveBeenCalledWith('Correct Answer');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('submits an incorrect answer', () => {
|
|
||||||
const inputElement = screen.getByRole('textbox') as HTMLInputElement;
|
|
||||||
|
|
||||||
fireEvent.change(inputElement, { target: { value: 'Incorrect Answer' } });
|
|
||||||
|
|
||||||
const submitButton = screen.getByText('Répondre');
|
|
||||||
fireEvent.click(submitButton);
|
|
||||||
|
|
||||||
expect(mockHandleSubmitAnswer).toHaveBeenCalledWith('Incorrect Answer');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('displays feedback when the answer is shown', () => {
|
|
||||||
render(<ShortAnswerQuestionDisplay question={question} {...sampleProps} showAnswer={true} passedAnswer="Incorrect Answer" />);
|
|
||||||
expect(screen.getByText('❌ Incorrect!')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('Réponse(s) accepté(es):')).toBeInTheDocument();
|
|
||||||
expect(screen.getByText('Incorrect Answer')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -66,18 +66,6 @@ describe('TeacherModeQuiz', () => {
|
||||||
expect(mockSubmitAnswer).toHaveBeenCalledWith('Option A', 1);
|
expect(mockSubmitAnswer).toHaveBeenCalledWith('Option A', 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test('handles shows feedback for answered question', () => {
|
|
||||||
act(() => {
|
|
||||||
fireEvent.click(screen.getByText('Option B'));
|
|
||||||
});
|
|
||||||
act(() => {
|
|
||||||
fireEvent.click(screen.getByText('Répondre'));
|
|
||||||
});
|
|
||||||
expect(mockSubmitAnswer).toHaveBeenCalledWith('Option B', 1)
|
|
||||||
expect(screen.getByText('❌ Incorrect!')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('handles shows feedback for an already answered question', () => {
|
test('handles shows feedback for an already answered question', () => {
|
||||||
// Answer the first question
|
// Answer the first question
|
||||||
act(() => {
|
act(() => {
|
||||||
|
|
@ -118,7 +106,7 @@ describe('TeacherModeQuiz', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if the feedback dialog is shown again
|
// Check if the feedback dialog is shown again
|
||||||
expect(screen.getByText('❌ Incorrect!')).toBeInTheDocument();
|
expect(screen.getByText('Rétroaction')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('handles disconnect button click', () => {
|
test('handles disconnect button click', () => {
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,6 @@ const MultipleChoiceQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
{!showAnswer && handleOnSubmitAnswer && (
|
{!showAnswer && handleOnSubmitAnswer && (
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
className='submit-button'
|
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
answer !== "" && handleOnSubmitAnswer && handleOnSubmitAnswer(answer)
|
answer !== "" && handleOnSubmitAnswer && handleOnSubmitAnswer(answer)
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,6 @@ const NumericalQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
)}
|
)}
|
||||||
{handleOnSubmitAnswer && (
|
{handleOnSubmitAnswer && (
|
||||||
<Button
|
<Button
|
||||||
className='submit-button'
|
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
answer !== undefined &&
|
answer !== undefined &&
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ const ShortAnswerQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
}, [answer]);
|
}, [answer]);
|
||||||
|
|
||||||
const checkAnswer = () => {
|
const checkAnswer = () => {
|
||||||
const isCorrect = question.choices.some((choice) => String(choice.text).toLowerCase() === String(answer).toLowerCase());
|
const isCorrect = question.choices.some((choice) => choice.text.toLowerCase() === (answer as String).toLowerCase());
|
||||||
setisGoodAnswer(isCorrect);
|
setisGoodAnswer(isCorrect);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -91,7 +91,6 @@ const ShortAnswerQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
</div>
|
</div>
|
||||||
{handleOnSubmitAnswer && (
|
{handleOnSubmitAnswer && (
|
||||||
<Button
|
<Button
|
||||||
className='submit-button'
|
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
answer !== undefined &&
|
answer !== undefined &&
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,6 @@ const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
)}
|
)}
|
||||||
{!showAnswer && handleOnSubmitAnswer && (
|
{!showAnswer && handleOnSubmitAnswer && (
|
||||||
<Button
|
<Button
|
||||||
className='submit-button'
|
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
answer !== undefined && handleOnSubmitAnswer && handleOnSubmitAnswer(answer)
|
answer !== undefined && handleOnSubmitAnswer && handleOnSubmitAnswer(answer)
|
||||||
|
|
|
||||||
|
|
@ -200,10 +200,6 @@
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
|
|
||||||
}
|
}
|
||||||
.submit-button{
|
|
||||||
width: 20%;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ const StudentModeQuiz: React.FC<StudentModeQuizProps> = ({
|
||||||
<div >
|
<div >
|
||||||
<b>Question {questionInfos.question.id}/{questions.length}</b>
|
<b>Question {questionInfos.question.id}/{questions.length}</b>
|
||||||
</div>
|
</div>
|
||||||
<div className="overflow-auto" style={{ width: '50%', alignItems: 'center', justifyContent: 'center', margin: 'auto' }}>
|
<div className="overflow-auto">
|
||||||
<div className="question-component-container">
|
<div className="question-component-container">
|
||||||
<div className="mb-5">
|
<div className="mb-5">
|
||||||
{/* <QuestionNavigation
|
{/* <QuestionNavigation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue