mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Added tests
This commit is contained in:
parent
22dc7a5399
commit
7b69071672
6 changed files with 159 additions and 2 deletions
|
|
@ -209,5 +209,33 @@ describe('MultipleChoiceQuestionDisplay', () => {
|
||||||
expect(wrongAnswer1?.textContent).not.toContain('❌');
|
expect(wrongAnswer1?.textContent).not.toContain('❌');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('calculates and displays pick rates correctly when showResults is true', () => {
|
||||||
|
const question = parse(`::MCQ:: What is 2+2? {
|
||||||
|
=Four
|
||||||
|
~Three
|
||||||
|
~Five
|
||||||
|
}`)[0] as MultipleChoiceQuestion;
|
||||||
|
|
||||||
|
const mockStudents = [
|
||||||
|
{ id: '1', name: 'Alice', answers: [{ idQuestion: 1, answer: ['Four'], isCorrect: true }] },
|
||||||
|
{ id: '2', name: 'Bob', answers: [{ idQuestion: 1, answer: ['Three'], isCorrect: false }] },
|
||||||
|
{ id: '3', name: 'Charlie', answers: [{ idQuestion: 1, answer: ['Four'], isCorrect: true }] }
|
||||||
|
];
|
||||||
|
|
||||||
|
render(
|
||||||
|
<MultipleChoiceQuestionDisplay
|
||||||
|
question={{ ...question, id: '1' }}
|
||||||
|
students={mockStudents}
|
||||||
|
showResults={true}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
// Expect pick rate for "Four" to be 2/3
|
||||||
|
expect(screen.getByText('✅2/3 (66.7%)')).toBeInTheDocument();
|
||||||
|
|
||||||
|
// Expect pick rate for "Three" to be 1/3
|
||||||
|
expect(screen.getByText('❌1/3 (33.3%)')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,4 +81,37 @@ describe('NumericalQuestion Component', () => {
|
||||||
expect(mockHandleOnSubmitAnswer).toHaveBeenCalledWith([7]);
|
expect(mockHandleOnSubmitAnswer).toHaveBeenCalledWith([7]);
|
||||||
mockHandleOnSubmitAnswer.mockClear();
|
mockHandleOnSubmitAnswer.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('calculates and displays correct answer rate when showResults is true', () => {
|
||||||
|
const mockStudents = [
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
name: 'Alice',
|
||||||
|
answers: [{ idQuestion: 1, answer: [7], isCorrect: true }]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
name: 'Bob',
|
||||||
|
answers: [{ idQuestion: 1, answer: [3], isCorrect: false }]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '3',
|
||||||
|
name: 'Charlie',
|
||||||
|
answers: [{ idQuestion: 1, answer: [6], isCorrect: true }]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
render(
|
||||||
|
<MemoryRouter>
|
||||||
|
<NumericalQuestionDisplay
|
||||||
|
question={{ ...question, id: '1' }}
|
||||||
|
showResults={true}
|
||||||
|
students={mockStudents}
|
||||||
|
/>
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByText('Taux de réponse correcte: 2/3')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('66.7%')).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ describe('Questions Component', () => {
|
||||||
showAnswer: false
|
showAnswer: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderComponent = (question: Question) => {
|
const renderComponent = (question: Question, showAnswerToggle = false) => {
|
||||||
render(<QuestionDisplay question={question} {...sampleProps} />);
|
render(<QuestionDisplay question={question} showAnswerToggle={showAnswerToggle} {...sampleProps} />);
|
||||||
};
|
};
|
||||||
|
|
||||||
// describe('question type parsing', () => {
|
// describe('question type parsing', () => {
|
||||||
|
|
@ -122,6 +122,11 @@ describe('Questions Component', () => {
|
||||||
|
|
||||||
expect(mockHandleSubmitAnswer).toHaveBeenCalledWith(['User Input']);
|
expect(mockHandleSubmitAnswer).toHaveBeenCalledWith(['User Input']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('shows "Afficher les résultats" toggle when showAnswerToggle is true', () => {
|
||||||
|
renderComponent(sampleTrueFalseQuestion, true);
|
||||||
|
expect(screen.getByText('Afficher les résultats')).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { render, screen, fireEvent, within } from '@testing-library/react';
|
||||||
import '@testing-library/jest-dom';
|
import '@testing-library/jest-dom';
|
||||||
import { parse, ShortAnswerQuestion } from 'gift-pegjs';
|
import { parse, ShortAnswerQuestion } from 'gift-pegjs';
|
||||||
import ShortAnswerQuestionDisplay from 'src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay';
|
import ShortAnswerQuestionDisplay from 'src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay';
|
||||||
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
|
|
||||||
describe('ShortAnswerQuestion Component', () => {
|
describe('ShortAnswerQuestion Component', () => {
|
||||||
const mockHandleSubmitAnswer = jest.fn();
|
const mockHandleSubmitAnswer = jest.fn();
|
||||||
|
|
@ -64,4 +65,54 @@ describe('ShortAnswerQuestion Component', () => {
|
||||||
expect(mockHandleSubmitAnswer).toHaveBeenCalledWith(['User Input']);
|
expect(mockHandleSubmitAnswer).toHaveBeenCalledWith(['User Input']);
|
||||||
mockHandleSubmitAnswer.mockClear();
|
mockHandleSubmitAnswer.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('calculates and displays correct answer rate when showResults is true', () => {
|
||||||
|
const mockStudents = [
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
name: 'Alice',
|
||||||
|
answers: [{ idQuestion: 1, answer: ['Paris'], isCorrect: true }]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
name: 'Bob',
|
||||||
|
answers: [{ idQuestion: 1, answer: ['Lyon'], isCorrect: false }]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '3',
|
||||||
|
name: 'Charlie',
|
||||||
|
answers: [{ idQuestion: 1, answer: ['Paris'], isCorrect: true }]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
const question: ShortAnswerQuestion = {
|
||||||
|
id: '1',
|
||||||
|
type: 'Short',
|
||||||
|
hasEmbeddedAnswers: false,
|
||||||
|
formattedStem: {
|
||||||
|
text: 'What is the capital of France?',
|
||||||
|
format: 'html'
|
||||||
|
},
|
||||||
|
choices: [{ text: 'Paris', isCorrect: true }],
|
||||||
|
formattedGlobalFeedback: {
|
||||||
|
text: '',
|
||||||
|
format: 'html'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
render(
|
||||||
|
<MemoryRouter>
|
||||||
|
<ShortAnswerQuestionDisplay
|
||||||
|
question={question}
|
||||||
|
showResults={true}
|
||||||
|
students={mockStudents}
|
||||||
|
/>
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByText('Taux de réponse correcte: 2/3')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('66.7%')).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -134,4 +134,43 @@ describe('TrueFalseQuestion Component', () => {
|
||||||
expect(wrongAnswer1).toBeInTheDocument();
|
expect(wrongAnswer1).toBeInTheDocument();
|
||||||
expect(wrongAnswer1?.textContent).not.toContain('❌');
|
expect(wrongAnswer1?.textContent).not.toContain('❌');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('calculates and displays pick rates correctly when showResults is true', () => {
|
||||||
|
const mockStudents = [
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
name: 'Alice',
|
||||||
|
answers: [{ idQuestion: 1, answer: [true], isCorrect: true }]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
name: 'Bob',
|
||||||
|
answers: [{ idQuestion: 1, answer: [false], isCorrect: false }]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
render(
|
||||||
|
<MemoryRouter>
|
||||||
|
<TrueFalseQuestionDisplay
|
||||||
|
question={{ ...trueFalseQuestion, id: '1' }}
|
||||||
|
students={mockStudents}
|
||||||
|
showResults={true}
|
||||||
|
/>
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
|
||||||
|
const pickRateDivs = screen.getAllByText((_, element) =>
|
||||||
|
element !== null &&
|
||||||
|
(element as HTMLElement).classList.contains('pick-rate') &&
|
||||||
|
(element as HTMLElement).textContent!.includes('1/2')
|
||||||
|
);
|
||||||
|
expect(pickRateDivs.length).toBe(2);
|
||||||
|
|
||||||
|
const percentDivs = screen.getAllByText((_, element) =>
|
||||||
|
element !== null &&
|
||||||
|
(element as HTMLElement).classList.contains('pick-rate') &&
|
||||||
|
(element as HTMLElement).textContent!.includes('50.0%')
|
||||||
|
);
|
||||||
|
expect(percentDivs.length).toBe(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ const LiveResults: React.FC<LiveResultsProps> = ({ questions, showSelectedQuesti
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="action-bar mb-1">
|
<div className="action-bar mb-1">
|
||||||
|
<div className="text-2xl text-bold">Résultats du quiz</div>
|
||||||
<FormGroup row>
|
<FormGroup row>
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
label={<div className="text-sm">Afficher les noms</div>}
|
label={<div className="text-sm">Afficher les noms</div>}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue