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
8 changes: 4 additions & 4 deletions src/components/introduce/StudyReviewForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
56 changes: 24 additions & 32 deletions src/components/introduce/StudyReviewForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,46 @@ 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();
});
});
});

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();
});
Expand Down
12 changes: 9 additions & 3 deletions src/containers/introduce/StudyReviewContainer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('스터디 후기를 작성해주세요!');
});
});
});

Expand Down