diff --git a/src/frontend/components/ViewersList/InstructorViewersList/index.spec.tsx b/src/frontend/components/ViewersList/InstructorViewersList/index.spec.tsx deleted file mode 100644 index b349fe7249..0000000000 --- a/src/frontend/components/ViewersList/InstructorViewersList/index.spec.tsx +++ /dev/null @@ -1,176 +0,0 @@ -import { act, render, screen } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; -import React from 'react'; - -import { useParticipantsStore } from 'data/stores/useParticipantsStore'; -import { - participantMockFactory, - videoMockFactory, -} from 'utils/tests/factories'; -import { wrapInIntlProvider } from 'utils/tests/intl'; -import { converse } from 'utils/window'; -import { InstructorViewersList } from '.'; - -jest.mock('utils/window', () => ({ - converse: { - acceptParticipantToJoin: jest.fn(), - askParticipantToJoin: jest.fn(), - kickParticipant: jest.fn(), - rejectParticipantToJoin: jest.fn(), - }, -})); - -const mockedParticipantOnDemands1 = participantMockFactory(); -const mockedParticipantOnDemands2 = participantMockFactory(); - -const mockedParticipantOnStage1 = participantMockFactory(); -const mockedParticipantOnStage2 = participantMockFactory(); - -const mockedParticipantOnStage1Full = { - ...mockedParticipantOnStage1, - isInstructor: false, - isOnStage: true, -}; - -const mockedParticipantOnStage2Full = { - ...mockedParticipantOnStage2, - isInstructor: false, - isOnStage: true, -}; - -const participant1 = { - id: 'example.jid.student1@prosody.org', - isInstructor: true, - isOnStage: false, - name: 'Student 1', -}; - -const participant2 = { - id: 'example.jid.student2@prosody.org', - isInstructor: false, - isOnStage: false, - name: 'Student 2', -}; - -const participant3 = { - id: 'example.jid.student3@prosody.org', - isInstructor: false, - isOnStage: false, - name: 'Student 3', -}; - -describe('', () => { - beforeEach(() => jest.resetAllMocks()); - - it('displays severals participants, not on stage and not asking, and then remove some of them', () => { - const video = videoMockFactory(); - - render(wrapInIntlProvider()); - - expect(screen.queryByText('Demands')).toEqual(null); - expect(screen.queryByText('On stage')).toEqual(null); - expect(screen.queryByText('Other participants')).toEqual(null); - - act(() => useParticipantsStore.getState().addParticipant(participant1)); - act(() => useParticipantsStore.getState().addParticipant(participant2)); - act(() => useParticipantsStore.getState().addParticipant(participant3)); - - screen.getByText('Student 1'); - screen.getByText('Student 2'); - screen.getByText('Student 3'); - - act(() => useParticipantsStore.getState().removeParticipant('Student 2')); - - expect(screen.queryByText('Student 2')).not.toBeInTheDocument(); - }); - - it('displays severals participants, some on stage, and some asking, and some not on stage and not asking', () => { - const video = videoMockFactory({ - participants_asking_to_join: [ - mockedParticipantOnDemands1, - mockedParticipantOnDemands2, - ], - participants_in_discussion: [ - mockedParticipantOnStage1, - mockedParticipantOnStage2, - ], - }); - - useParticipantsStore.setState({ - participants: [ - participant1, - participant2, - mockedParticipantOnStage1Full, - mockedParticipantOnStage2Full, - ], - }); - - render(wrapInIntlProvider()); - - screen.getByText('Demands'); - screen.getByText('On stage'); - screen.getByText('Other participants'); - - screen.getByText('Student 1'); - screen.getByText('Student 2'); - screen.getByText(mockedParticipantOnDemands1.name); - screen.getByText(mockedParticipantOnDemands2.name); - screen.getByText(mockedParticipantOnStage1Full.name); - screen.getByText(mockedParticipantOnStage2Full.name); - }); - - it('displays a demanding participant and accepts it', () => { - const video = videoMockFactory({ - participants_asking_to_join: [mockedParticipantOnDemands1], - }); - - render(wrapInIntlProvider()); - - screen.getByText('Demands'); - expect(screen.queryByText('On stage')).toEqual(null); - expect(screen.queryByText('Other participants')).toEqual(null); - screen.getByText(mockedParticipantOnDemands1.name); - - const acceptButton = screen.getByRole('button', { name: 'Accept' }); - act(() => userEvent.click(acceptButton)); - expect(converse.acceptParticipantToJoin).toHaveBeenCalledTimes(1); - }); - - it('displays a demanding participant and rejects it', () => { - const video = videoMockFactory({ - participants_asking_to_join: [mockedParticipantOnDemands1], - }); - - render(wrapInIntlProvider()); - - screen.getByText('Demands'); - expect(screen.queryByText('On stage')).toEqual(null); - expect(screen.queryByText('Other participants')).toEqual(null); - screen.getByText(mockedParticipantOnDemands1.name); - - const rejectButton = screen.getAllByRole('button')[0]; - act(() => userEvent.click(rejectButton)); - expect(converse.rejectParticipantToJoin).toHaveBeenCalledTimes(1); - }); - - it('displays an on-stage participant and kicks it', () => { - const video = videoMockFactory({ - participants_in_discussion: [mockedParticipantOnStage1], - }); - - useParticipantsStore.setState({ - participants: [mockedParticipantOnStage1Full], - }); - - render(wrapInIntlProvider()); - - expect(screen.queryByText('Demands')).toEqual(null); - screen.getByText('On stage'); - expect(screen.queryByText('Other participants')).toEqual(null); - screen.getByText(mockedParticipantOnStage1Full.name); - - const terminateButton = screen.getByRole('button', { name: 'Terminate' }); - act(() => userEvent.click(terminateButton)); - expect(converse.kickParticipant).toHaveBeenCalledTimes(1); - }); -}); diff --git a/src/frontend/components/ViewersList/InstructorViewersList/index.tsx b/src/frontend/components/ViewersList/InstructorViewersList/index.tsx deleted file mode 100644 index 48ea609e7d..0000000000 --- a/src/frontend/components/ViewersList/InstructorViewersList/index.tsx +++ /dev/null @@ -1,170 +0,0 @@ -import React from 'react'; -import { Box, Button, List } from 'grommet'; -import { AddCircle } from 'grommet-icons'; -import { defineMessages, useIntl } from 'react-intl'; - -import { - useParticipantsStore, - ParticipantType, -} from 'data/stores/useParticipantsStore'; -import { Video } from 'types/tracks'; -import { ViewersListHeader } from 'components/ViewersList/components/ViewersListHeader'; -import { ViewersListItem } from 'components/ViewersList/components/ViewersListItem'; -import { converse } from 'utils/window'; -import { ViewersListItemContainer } from 'components/ViewersList/components/ViewersListItemContainer'; -import { ViewersListTextButton } from 'components/ViewersList/components/ViewersListTextButton'; - -const messages = defineMessages({ - demands: { - defaultMessage: 'Demands', - description: - 'Participants asking for going on stage are displayed under this label.', - id: 'components.ViewersList.demands', - }, - onStage: { - defaultMessage: 'On stage', - description: 'On-stage participants are displayed under this label.', - id: 'components.ViewersList.onStage', - }, - otherViewers: { - defaultMessage: 'Other participants', - description: 'Connected participants are displayed under this label.', - id: 'components.ViewersList.otherViewers', - }, - acceptButton: { - defaultMessage: 'Accept', - description: - 'The text displayed in the button in charge of accepting on-stage request, in the viewers list.', - id: 'components.ViewersList.acceptButton', - }, - endOnStageButton: { - defaultMessage: 'Terminate', - description: - 'The text displayed in the button in charge of making students on stage exiting the stage, in the viewers list.', - id: 'components.ViewersList.endOnStageButton', - }, -}); - -interface InstructorViewersListProps { - video: Video; -} - -export const InstructorViewersList = ({ - video, -}: InstructorViewersListProps) => { - const participants = useParticipantsStore((state) => state.participants); - const participantsOnStage = participants.filter( - (participant) => - video.participants_in_discussion.some( - (p) => p.name === participant.name, - ) || participant.isInstructor, - ); - - const participantsNotOnStageAndNotAsking = participants.filter( - (participant) => - !participantsOnStage.includes(participant) && - !video.participants_asking_to_join.some( - (p) => p.name === participant.name, - ), - ); - const intl = useIntl(); - - return ( - - {video.participants_asking_to_join.length !== 0 && ( - - - - participantA.name.localeCompare(participantB.name), - )} - pad="none" - > - {(item: ParticipantType, index: number) => ( - - - -