From 79ede597001c65576159243d9aea7208bc30a8a9 Mon Sep 17 00:00:00 2001 From: saseungmin Date: Sat, 16 Jan 2021 20:31:24 +0900 Subject: [PATCH] [Fix] Validation of study review form - The study review form appears when the application deadline is reached --- src/components/introduce/StudyReviewForm.jsx | 8 +-- .../introduce/StudyReviewForm.test.jsx | 56 ++++++++----------- .../introduce/StudyReviewContainer.test.jsx | 12 +++- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/components/introduce/StudyReviewForm.jsx b/src/components/introduce/StudyReviewForm.jsx index 5feaf7b..39cb278 100644 --- a/src/components/introduce/StudyReviewForm.jsx +++ b/src/components/introduce/StudyReviewForm.jsx @@ -41,11 +41,12 @@ const StudyReviewFormButton = styled(Button)` margin: 1px 0 0.8rem 0.5rem; `; -const isValidateUserInfo = (user) => (moderator) => !user || (moderator === user); +const isValidateUserInfo = (user) => (participants) => !!participants + .find(({ id, confirm }) => id === user && confirm && confirm === true); const StudyReviewForm = ({ group, user, time }) => { const { - participants, personnel, applyEndDate, moderatorId, + participants, personnel, applyEndDate, } = group; const applyEndTime = changeDateToTime(applyEndDate); @@ -54,8 +55,7 @@ const StudyReviewForm = ({ group, user, time }) => { time, applyEndTime, participants, personnel, }; - // TODO: 수정하자. - if (isValidateUserInfo(user)(moderatorId) || !isCheckedTimeStatus(valid)) { + if (!isValidateUserInfo(user)(participants) || !isCheckedTimeStatus(valid)) { return null; } diff --git a/src/components/introduce/StudyReviewForm.test.jsx b/src/components/introduce/StudyReviewForm.test.jsx index edaa5c3..d68672c 100644 --- a/src/components/introduce/StudyReviewForm.test.jsx +++ b/src/components/introduce/StudyReviewForm.test.jsx @@ -16,36 +16,34 @@ describe('StudyReviewForm', () => { /> )); - context('with user', () => { - describe('User is not moderator and applyEndDate is Deadline', () => { - const info = { - group: { - ...STUDY_GROUP, - applyEndDate: yesterday, - }, - time: Date.now(), - user: 'user1', - }; + const userStatusSetting = ({ user, participants }) => ({ + group: { + ...STUDY_GROUP, + participants, + applyEndDate: yesterday, + }, + time: Date.now(), + user, + }); + context('with user', () => { + describe('When the user is approved applicant and applyEndDate is Deadline', () => { it('renders study review form', () => { - const { container } = renderStudyReviewForm(info); + const { container } = renderStudyReviewForm(userStatusSetting({ + participants: [{ id: 'user1', confirm: true }], + user: 'user1', + })); expect(container).toHaveTextContent('스터디 후기를 작성해주세요!'); }); }); - describe('User is moderator', () => { - const info = { - group: { - ...STUDY_GROUP, - applyEndDate: yesterday, - }, - time: Date.now(), - user: 'user2', - }; - + describe('When the user is not approved applicant', () => { it('nothing renders study review form', () => { - const { container } = renderStudyReviewForm(info); + const { container } = renderStudyReviewForm(userStatusSetting({ + participants: [], + user: 'user2', + })); expect(container).toBeEmptyDOMElement(); }); @@ -53,17 +51,11 @@ describe('StudyReviewForm', () => { }); context('without user', () => { - const info = { - group: { - ...STUDY_GROUP, - applyEndDate: yesterday, - }, - time: Date.now(), - user: null, - }; - it('nothing renders study review form', () => { - const { container } = renderStudyReviewForm(info); + const { container } = renderStudyReviewForm(userStatusSetting({ + participants: [], + user: null, + })); expect(container).toBeEmptyDOMElement(); }); diff --git a/src/containers/introduce/StudyReviewContainer.test.jsx b/src/containers/introduce/StudyReviewContainer.test.jsx index ac6cd50..a828b20 100644 --- a/src/containers/introduce/StudyReviewContainer.test.jsx +++ b/src/containers/introduce/StudyReviewContainer.test.jsx @@ -28,14 +28,20 @@ describe('StudyReviewContainer', () => { context('with login and group', () => { given('group', () => ({ ...STUDY_GROUP, + participants: [{ + id: 'user1', + confirm: true, + }], applyEndDate: yesterday, })); given('user', () => ('user1')); - it('renders study review form', () => { - const { container } = renderStudyReviewContainer(); + describe('When you are an approved applicant', () => { + it('renders study review form', () => { + const { container } = renderStudyReviewContainer(); - expect(container).toHaveTextContent('스터디 후기를 작성해주세요!'); + expect(container).toHaveTextContent('스터디 후기를 작성해주세요!'); + }); }); });