Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/introduce/ModeratorViewButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useState } from 'react';
import StyledApplyStatusButton from '../../styles/StyledApplyStatusButton';
import ParticipantListModal from './modals/ParticipantListModal';

const ModeratorViewButton = ({ group, user }) => {
const ModeratorViewButton = ({ group, user, onUpdateConfirm }) => {
const [ListModal, setListModal] = useState(false);

const { moderatorId, participants } = group;
Expand Down Expand Up @@ -32,6 +32,7 @@ const ModeratorViewButton = ({ group, user }) => {
<ParticipantListModal
visible={ListModal}
onClose={handelClose}
onUpdate={onUpdateConfirm}
participants={participants.filter((_, index) => index !== 0)}
/>
</>
Expand Down
14 changes: 10 additions & 4 deletions src/components/introduce/modals/ParticipantList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const ParticipantListWrapper = styled.div`
grid-template-columns: 260px 186px 148px;
justify-items: center;
align-items: center;
margin-bottom: 0.5rem;
margin-bottom: 0.7rem;
min-height: 0;
min-width: 0;
`;

const ParticipantList = ({ participant }) => {
const ParticipantList = ({ participant, onUpdate }) => {
const [viewApplyModal, setViewApplyModal] = useState(false);

const { id, confirm } = participant;
Expand All @@ -42,11 +42,17 @@ const ParticipantList = ({ participant }) => {
</div>
<div>
{confirm === true ? (
<ParticipantListButton cancel>
<ParticipantListButton
cancel
onClick={onUpdate}
>
취소하기
</ParticipantListButton>
) : (
<ParticipantListButton confirm>
<ParticipantListButton
confirm
onClick={onUpdate}
>
승인하기
</ParticipantListButton>
)}
Expand Down
27 changes: 27 additions & 0 deletions src/components/introduce/modals/ParticipantList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import { fireEvent, render } from '@testing-library/react';
import ParticipantList from './ParticipantList';

describe('ParticipantList', () => {
const handleUpdate = jest.fn();

beforeEach(() => {
handleUpdate.mockClear();
});

const renderParticipantList = (participant) => render((
<ParticipantList
participant={participant}
onUpdate={handleUpdate}
/>
));

Expand All @@ -23,6 +30,16 @@ describe('ParticipantList', () => {
expect(container).toHaveTextContent(props.id);
expect(container).toHaveTextContent('취소하기');
});

it('click cancel button', () => {
const { getByText } = renderParticipantList(props);

const button = getByText('취소하기');

fireEvent.click(button);

expect(handleUpdate).toBeCalled();
});
});

context('without confirm', () => {
Expand All @@ -37,6 +54,16 @@ describe('ParticipantList', () => {
expect(container).toHaveTextContent(props.id);
expect(container).toHaveTextContent('승인하기');
});

it('click confirm button', () => {
const { getByText } = renderParticipantList(props);

const button = getByText('승인하기');

fireEvent.click(button);

expect(handleUpdate).toBeCalled();
});
});

describe('click "View application" button', () => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/introduce/modals/ParticipantListModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ const StyledButton = styled(Button)`
}
`;

const ParticipantListModal = ({ visible, onClose, participants }) => {
const ParticipantListModal = ({
visible, onClose, participants, onUpdate,
}) => {
if (!visible) {
return null;
}
Expand All @@ -107,6 +109,7 @@ const ParticipantListModal = ({ visible, onClose, participants }) => {
<ParticipantList
key={participant.id}
participant={participant}
onUpdate={() => onUpdate(participant.id)}
/>
))}
</ParticipantListWrapper>
Expand Down
71 changes: 56 additions & 15 deletions src/components/introduce/modals/ParticipantListModal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,81 @@ import ParticipantListModal from './ParticipantListModal';

describe('ParticipantListModal', () => {
const handleClose = jest.fn();
const handleUpdate = jest.fn();

beforeEach(() => {
jest.clearAllMocks();
});

const renderParticipantListModal = ({ visible, participants }) => render((
<ParticipantListModal
visible={visible}
participants={participants}
onClose={handleClose}
onUpdate={handleUpdate}
/>
));

context('with visible', () => {
const modal = {
visible: true,
participants: [{
const visible = true;

describe('Contents on the screen', () => {
const participants = [{
confirm: false,
id: 'test',
}],
};
}];

it('renders Modal text', () => {
const { container } = renderParticipantListModal(modal);
it('renders Modal text', () => {
const { container } = renderParticipantListModal({ visible, participants });

expect(container).toHaveTextContent('스터디 신청자 목록 🙋‍♂️');
expect(container).toHaveTextContent('신청서 보기');
expect(container).toHaveTextContent('test');
});

it('click button call close', () => {
const { getByText } = renderParticipantListModal({ visible, participants });

const button = getByText('닫기');

fireEvent.click(button);

expect(container).toHaveTextContent('스터디 신청자 목록 🙋‍♂️');
expect(container).toHaveTextContent('신청서 보기');
expect(container).toHaveTextContent('test');
expect(handleClose).toBeCalled();
});
});

it('click button call close', () => {
const { getByText } = renderParticipantListModal(modal);
context('When confirm is true', () => {
const participants = [{
confirm: true,
id: 'test',
}];

it('event is called with user ID after clicking cancel button', () => {
const { getByText } = renderParticipantListModal({ visible, participants });

const button = getByText('취소하기');

fireEvent.click(button);

expect(handleUpdate).toBeCalledWith('test');
});
});

context('When confirm is false', () => {
const participants = [{
confirm: false,
id: 'test',
}];

it('renders confirm button', () => {
const { getByText } = renderParticipantListModal({ visible, participants });

const button = getByText('닫기');
const button = getByText('승인하기');

fireEvent.click(button);
fireEvent.click(button);

expect(handleClose).toBeCalled();
expect(handleUpdate).toBeCalledWith('test');
});
});
});

Expand Down
11 changes: 10 additions & 1 deletion src/containers/introduce/IntroduceHeaderContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { useDispatch, useSelector } from 'react-redux';

import { getAuth, getGroup } from '../../util/utils';
import {
changeApplyFields, clearApplyFields, deleteParticipant, updateParticipant,
changeApplyFields,
clearApplyFields,
deleteParticipant,
updateConfirmParticipant,
updateParticipant,
} from '../../reducers/groupSlice';

import IntroduceHeader from '../../components/introduce/IntroduceHeader';
Expand Down Expand Up @@ -42,6 +46,10 @@ const IntroduceHeaderContainer = () => {
dispatch(clearApplyFields());
}, [dispatch]);

const onUpdateConfirmParticipant = useCallback((id) => {
dispatch(updateConfirmParticipant(id));
}, [dispatch]);

if (!group) {
return (
<GroupContentLoader />
Expand All @@ -61,6 +69,7 @@ const IntroduceHeaderContainer = () => {
onChangeApplyFields={onChangeApplyFields}
/>
<ModeratorViewButton
onUpdateConfirm={onUpdateConfirmParticipant}
user={user}
group={group}
/>
Expand Down
Loading