mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Compare commits
3 commits
68e90bdbdc
...
03faf97702
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03faf97702 | ||
|
|
e2c4bb0722 | ||
|
|
182402e621 |
2 changed files with 171 additions and 53 deletions
|
|
@ -294,5 +294,75 @@ describe('ManageRoom', () => {
|
||||||
expect(screen.queryByText('Student 1')).not.toBeInTheDocument();
|
expect(screen.queryByText('Student 1')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('handles user joined and leaves but name still seeable', async () => {
|
||||||
|
await act(async () => {
|
||||||
|
render(
|
||||||
|
<MemoryRouter>
|
||||||
|
<ManageRoom />
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const createSuccessCallback = (mockSocket.on as jest.Mock).mock.calls.find(call => call[0] === 'create-success')[1];
|
||||||
|
createSuccessCallback('Test Room');
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const userJoinedCallback = (mockSocket.on as jest.Mock).mock.calls.find(call => call[0] === 'user-joined')[1];
|
||||||
|
userJoinedCallback(mockStudents[0]);
|
||||||
|
});
|
||||||
|
await act(async () => {
|
||||||
|
const userJoinedCallback = (mockSocket.on as jest.Mock).mock.calls.find(call => call[0] === 'user-joined')[1];
|
||||||
|
userJoinedCallback(mockStudents[1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Student 1')).toBeInTheDocument();
|
||||||
|
|
||||||
|
});
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Student 2')).toBeInTheDocument();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
const launchButton = screen.getByText('Lancer');
|
||||||
|
fireEvent.click(launchButton);
|
||||||
|
|
||||||
|
const rythmeButton = screen.getByText('Rythme du professeur');
|
||||||
|
fireEvent.click(rythmeButton);
|
||||||
|
|
||||||
|
const secondLaunchButton = screen.getAllByText('Lancer');
|
||||||
|
fireEvent.click(secondLaunchButton[1]);
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('2/60')).toBeInTheDocument();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const userDisconnectedCallback = (mockSocket.on as jest.Mock).mock.calls.find(call => call[0] === 'user-disconnected')[1];
|
||||||
|
userDisconnectedCallback(mockStudents[1].id);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Résultats du quiz')).toBeInTheDocument();
|
||||||
|
|
||||||
|
});
|
||||||
|
const toggleUsernamesSwitch = screen.getByLabelText('Afficher les noms');
|
||||||
|
|
||||||
|
// Toggle the display of usernames back
|
||||||
|
fireEvent.click(toggleUsernamesSwitch);
|
||||||
|
|
||||||
|
expect(screen.getByText('Student 1')).toBeInTheDocument();
|
||||||
|
|
||||||
|
expect(screen.getByText('Student 2')).toBeInTheDocument();
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('1/60')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ import { checkIfIsCorrect } from './useRooms';
|
||||||
const ManageRoom: React.FC = () => {
|
const ManageRoom: React.FC = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [socket, setSocket] = useState<Socket | null>(null);
|
const [socket, setSocket] = useState<Socket | null>(null);
|
||||||
const [students, setStudents] = useState<StudentType[]>([]);
|
const [connectedStudents, setConnectedStudents] = useState<StudentType[]>([]);
|
||||||
|
const [totalStudents, setTotalStudents] = useState<StudentType[]>([]);
|
||||||
const { quizId = '', roomName = '' } = useParams<{ quizId: string, roomName: string }>();
|
const { quizId = '', roomName = '' } = useParams<{ quizId: string, roomName: string }>();
|
||||||
const [quizQuestions, setQuizQuestions] = useState<QuestionType[] | undefined>();
|
const [quizQuestions, setQuizQuestions] = useState<QuestionType[] | undefined>();
|
||||||
const [quiz, setQuiz] = useState<QuizType | null>(null);
|
const [quiz, setQuiz] = useState<QuizType | null>(null);
|
||||||
|
|
@ -40,7 +41,8 @@ const ManageRoom: React.FC = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (newlyConnectedUser) {
|
if (newlyConnectedUser) {
|
||||||
console.log(`Handling newly connected user: ${newlyConnectedUser.name}`);
|
console.log(`Handling newly connected user: ${newlyConnectedUser.name}`);
|
||||||
setStudents((prevStudents) => [...prevStudents, newlyConnectedUser]);
|
setConnectedStudents((prevStudents) => [...prevStudents, newlyConnectedUser]);
|
||||||
|
setTotalStudents((prevStudents) => [...prevStudents, newlyConnectedUser]);
|
||||||
|
|
||||||
// only send nextQuestion if the quiz has started
|
// only send nextQuestion if the quiz has started
|
||||||
if (!quizStarted) {
|
if (!quizStarted) {
|
||||||
|
|
@ -128,7 +130,9 @@ const ManageRoom: React.FC = () => {
|
||||||
setSocket(null);
|
setSocket(null);
|
||||||
setQuizQuestions(undefined);
|
setQuizQuestions(undefined);
|
||||||
setCurrentQuestion(undefined);
|
setCurrentQuestion(undefined);
|
||||||
setStudents(new Array<StudentType>());
|
setConnectedStudents(new Array<StudentType>());
|
||||||
|
setTotalStudents(new Array<StudentType>());
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -172,7 +176,7 @@ const ManageRoom: React.FC = () => {
|
||||||
|
|
||||||
socket.on('user-disconnected', (userId: string) => {
|
socket.on('user-disconnected', (userId: string) => {
|
||||||
console.log(`Student left: id = ${userId}`);
|
console.log(`Student left: id = ${userId}`);
|
||||||
setStudents((prevUsers) => prevUsers.filter((user) => user.id !== userId));
|
setConnectedStudents((prevUsers) => prevUsers.filter((user) => user.id !== userId));
|
||||||
});
|
});
|
||||||
|
|
||||||
setSocket(socket);
|
setSocket(socket);
|
||||||
|
|
@ -193,7 +197,7 @@ const ManageRoom: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the students state using the functional form of setStudents
|
// Update the students state using the functional form of setStudents
|
||||||
setStudents((prevStudents) => {
|
setConnectedStudents((prevStudents) => {
|
||||||
console.log('Current students:');
|
console.log('Current students:');
|
||||||
prevStudents.forEach((student) => {
|
prevStudents.forEach((student) => {
|
||||||
console.log(student.name);
|
console.log(student.name);
|
||||||
|
|
@ -240,6 +244,48 @@ const ManageRoom: React.FC = () => {
|
||||||
}
|
}
|
||||||
return updatedStudents;
|
return updatedStudents;
|
||||||
});
|
});
|
||||||
|
setTotalStudents((prevStudents) => {
|
||||||
|
let foundStudent = false;
|
||||||
|
const updatedStudents = prevStudents.map((student) => {
|
||||||
|
console.log(`Comparing ${student.id} to ${idUser}`);
|
||||||
|
if (student.id === idUser) {
|
||||||
|
foundStudent = true;
|
||||||
|
const existingAnswer = student.answers.find(
|
||||||
|
(ans) => ans.idQuestion === idQuestion
|
||||||
|
);
|
||||||
|
let updatedAnswers: Answer[] = [];
|
||||||
|
if (existingAnswer) {
|
||||||
|
updatedAnswers = student.answers.map((ans) => {
|
||||||
|
console.log(`Comparing ${ans.idQuestion} to ${idQuestion}`);
|
||||||
|
return ans.idQuestion === idQuestion
|
||||||
|
? {
|
||||||
|
...ans,
|
||||||
|
answer,
|
||||||
|
isCorrect: checkIfIsCorrect(
|
||||||
|
answer,
|
||||||
|
idQuestion,
|
||||||
|
quizQuestions!
|
||||||
|
)
|
||||||
|
}
|
||||||
|
: ans;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const newAnswer = {
|
||||||
|
idQuestion,
|
||||||
|
answer,
|
||||||
|
isCorrect: checkIfIsCorrect(answer, idQuestion, quizQuestions!)
|
||||||
|
};
|
||||||
|
updatedAnswers = [...student.answers, newAnswer];
|
||||||
|
}
|
||||||
|
return { ...student, answers: updatedAnswers };
|
||||||
|
}
|
||||||
|
return student;
|
||||||
|
});
|
||||||
|
if (!foundStudent) {
|
||||||
|
console.log(`Student ${username} not found in the list.`);
|
||||||
|
}
|
||||||
|
return updatedStudents;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
setSocket(socket);
|
setSocket(socket);
|
||||||
}
|
}
|
||||||
|
|
@ -253,10 +299,12 @@ const ManageRoom: React.FC = () => {
|
||||||
if (nextQuestionIndex === undefined || nextQuestionIndex > quizQuestions.length - 1) return;
|
if (nextQuestionIndex === undefined || nextQuestionIndex > quizQuestions.length - 1) return;
|
||||||
|
|
||||||
setCurrentQuestion(quizQuestions[nextQuestionIndex]);
|
setCurrentQuestion(quizQuestions[nextQuestionIndex]);
|
||||||
webSocketService.nextQuestion({roomName: formattedRoomName,
|
webSocketService.nextQuestion({
|
||||||
|
roomName: formattedRoomName,
|
||||||
questions: quizQuestions,
|
questions: quizQuestions,
|
||||||
questionIndex: nextQuestionIndex,
|
questionIndex: nextQuestionIndex,
|
||||||
isLaunch: false});
|
isLaunch: false
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const previousQuestion = () => {
|
const previousQuestion = () => {
|
||||||
|
|
@ -388,7 +436,7 @@ const ManageRoom: React.FC = () => {
|
||||||
style={{ display: "flex", justifyContent: "flex-end" }}
|
style={{ display: "flex", justifyContent: "flex-end" }}
|
||||||
>
|
>
|
||||||
<GroupIcon style={{ marginRight: '5px' }} />
|
<GroupIcon style={{ marginRight: '5px' }} />
|
||||||
{students.length}/60
|
{connectedStudents.length}/60
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -434,7 +482,7 @@ const ManageRoom: React.FC = () => {
|
||||||
socket={socket}
|
socket={socket}
|
||||||
questions={quizQuestions}
|
questions={quizQuestions}
|
||||||
showSelectedQuestion={showSelectedQuestion}
|
showSelectedQuestion={showSelectedQuestion}
|
||||||
students={students}
|
students={totalStudents}
|
||||||
></LiveResultsComponent>
|
></LiveResultsComponent>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -470,7 +518,7 @@ const ManageRoom: React.FC = () => {
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<StudentWaitPage
|
<StudentWaitPage
|
||||||
students={students}
|
students={connectedStudents}
|
||||||
launchQuiz={launchQuiz}
|
launchQuiz={launchQuiz}
|
||||||
setQuizMode={setQuizMode}
|
setQuizMode={setQuizMode}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue