Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add validity for study review #163

Merged
merged 19 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
22e1690
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Jan 3, 2021
ab89ea1
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Jan 15, 2021
5f42974
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Jan 22, 2021
dc82bdd
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Jan 23, 2021
4ca9277
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Jan 29, 2021
b7c0ac9
Merge branch 'sumbit-action-to-study-review-form' into main
saseungmin Jan 30, 2021
5a7dca9
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Jan 31, 2021
5831537
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Jan 31, 2021
b976791
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Feb 6, 2021
305cf4d
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Feb 6, 2021
cd26a6b
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Feb 6, 2021
6a17bde
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Feb 12, 2021
bae1f46
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Feb 15, 2021
8a68bb9
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Mar 30, 2021
799825e
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Apr 6, 2021
1631e3f
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Apr 7, 2021
739bb60
Merge branch 'apply-css-review-list' into main
saseungmin Apr 7, 2021
a1aa3ad
[Feature] Add validity for study review
saseungmin Apr 8, 2021
88dcd59
Merge branch 'main' of https://github.com/CodeSoom/project-react-2-sa…
saseungmin Apr 8, 2021
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
18 changes: 11 additions & 7 deletions src/components/introduce/ReviewForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ const StudyReviewFormButton = styled(Button)`
margin: 1px 0 0.8rem 0.5rem;
`;

const isValidateUserInfo = (user, participants) => !!participants
.find(({ id, confirm }) => id === user && confirm && confirm === true);
const isValidateAboutUser = (user, group) => {
const { participants, reviews } = group;

return !participants.some(({ id, confirm }) => id === user && confirm && confirm === true)
|| reviews.some(({ id }) => id && id === user);
};

const ReviewForm = ({
participants, user, fields, onChangeReview, onSubmit,
group, user, fields, onChangeReview, onSubmit,
}) => {
const { rating, content } = fields;

if (!isValidateUserInfo(user, participants)) {
return null;
}

const handleChangeRating = (newRating, name) => {
onChangeReview({
name,
Expand All @@ -81,6 +81,10 @@ const ReviewForm = ({
});
};

if (isValidateAboutUser(user, group)) {
return null;
}

return (
<StudyReviewFormWrapper>
<StudyReviewFormHeader>
Expand Down
90 changes: 58 additions & 32 deletions src/components/introduce/ReviewForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,73 +15,99 @@ describe('ReviewForm', () => {
const reviewForm = { rating: 3, content: '' };

const renderReviewForm = ({
participants, user, fields = reviewForm,
group, user, fields = reviewForm,
}) => render((
<ReviewForm
user={user}
participants={participants}
group={group}
fields={fields}
onSubmit={handleSubmit}
onChangeReview={handleChange}
/>
));

const userStatusSetting = ({ user, participants }) => ({
participants,
const userStatusSetting = ({ user, group }) => ({
group,
user,
});

context('with user', () => {
describe('When the user is approved applicant and applyEndDate is Deadline', () => {
context('When you have already written a review', () => {
const settings = {
participants: [{ id: 'user1', confirm: true }],
group: {
participants: [{ id: 'user1', confirm: true }],
reviews: [{ id: 'user1', content: 'review' }],
},
user: 'user1',
};

it('renders study review form', () => {
it('Should be nothing renders', () => {
const { container } = renderReviewForm(userStatusSetting(settings));
expect(container).toHaveTextContent('스터디 후기를 작성해주세요!');
expect(container).toBeEmptyDOMElement();
});
it('call event change review form', () => {
const { getByPlaceholderText } = renderReviewForm(userStatusSetting(settings));

const textarea = getByPlaceholderText('후기를 입력해주세요!');
});

fireEvent.change(textarea, {
target: {
name: 'content',
value: 'test',
context("When you didn't write a review", () => {
describe('When the user is approved applicant and applyEndDate is Deadline', () => {
const settings = {
group: {
participants: [{ id: 'user1', confirm: true }],
reviews: [],
},
user: 'user1',
};

it('renders study review form', () => {
const { container } = renderReviewForm(userStatusSetting(settings));
expect(container).toHaveTextContent('스터디 후기를 작성해주세요!');
});
it('call event change review form', () => {
const { getByPlaceholderText } = renderReviewForm(userStatusSetting(settings));

expect(handleChange).toBeCalled();
});
const textarea = getByPlaceholderText('후기를 입력해주세요!');

it('call event click for review form', () => {
const { getByText } = renderReviewForm(userStatusSetting(settings));
fireEvent.change(textarea, {
target: {
name: 'content',
value: 'test',
},
});

fireEvent.click(getByText('후기 등록하기'));
expect(handleChange).toBeCalled();
});

expect(handleSubmit).toBeCalled();
});
});
it('call event click for review form', () => {
const { getByText } = renderReviewForm(userStatusSetting(settings));

describe('When the user is not approved applicant', () => {
it('nothing renders study review form', () => {
const { container } = renderReviewForm(userStatusSetting({
participants: [],
user: 'user2',
}));
fireEvent.click(getByText('후기 등록하기'));

expect(container).toBeEmptyDOMElement();
expect(handleSubmit).toBeCalled();
});
});

describe('When the user is not approved applicant', () => {
it('nothing renders study review form', () => {
const { container } = renderReviewForm(userStatusSetting({
group: {
participants: [],
reviews: [],
},
user: 'user2',
}));

expect(container).toBeEmptyDOMElement();
});
});
});
});

context('without user', () => {
it('nothing renders study review form', () => {
const { container } = renderReviewForm(userStatusSetting({
participants: [],
group: {
participants: [],
reviews: [],
},
user: null,
}));

Expand Down
2 changes: 1 addition & 1 deletion src/components/introduce/ReviewList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ReviewList = ({ reviews }) => {
if (_.isEmpty(reviews)) {
return (
<EmptyReviewWrapper>
등록된 리뷰가 존재하지 않습니다!
등록된 후기가 존재하지 않습니다!
</EmptyReviewWrapper>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/introduce/ReviewList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('ReviewList', () => {
it('Render nothing review message', () => {
const { container } = renderReviewList([]);

expect(container).toHaveTextContent('등록된 리뷰가 존재하지 않습니다!');
expect(container).toHaveTextContent('등록된 후기가 존재하지 않습니다!');
});
});
});
2 changes: 1 addition & 1 deletion src/containers/introduce/ReviewContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const ReviewFormContainer = () => {
<SubTitle title="후기" />
<ReviewForm
user={user}
participants={group.participants}
group={group}
fields={studyReviewFields}
onChangeReview={onChangeReviewFields}
onSubmit={onSubmitReview}
Expand Down
18 changes: 3 additions & 15 deletions src/containers/introduce/ReviewContainer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ describe('ReviewContainer', () => {
confirm: true,
},
],
reviews: [],
applyEndDate: yesterday,
}));
given('user', () => ('user1'));

const { container } = renderReviewContainer();

expect(container).toHaveTextContent('등록된 리뷰가 존재하지 않습니다!');
expect(container).toHaveTextContent('등록된 후기가 존재하지 않습니다!');
});

context('with login and group', () => {
Expand Down Expand Up @@ -103,12 +104,7 @@ describe('ReviewContainer', () => {
},
],
applyEndDate: yesterday,
reviews: [{
id: 'user1',
rating: 3,
content: 'test review',
createdDate: new Date(),
}],
reviews: [],
}));

describe('When you are an approved applicant', () => {
Expand Down Expand Up @@ -146,14 +142,6 @@ describe('ReviewContainer', () => {
expect(dispatch).toBeCalledTimes(1);
});
});

describe('Renders Review List', () => {
it('Information about the study review is render', () => {
const { container } = renderReviewContainer();

expect(container).toHaveTextContent('test review');
});
});
});
});

Expand Down
37 changes: 7 additions & 30 deletions src/reducers/groupSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,36 +139,12 @@ const { actions, reducer } = createSlice({
},

setGroupReview(state, { payload: review }) {
const { group } = state;

if (group.reviews) {
return {
...state,
group: {
...group,
reviews: [
{
...review,
createDate: new Date().toString(),
},
...group.reviews,
],
},
};
}

return {
...state,
group: {
...group,
reviews: [
{
...review,
createDate: new Date().toString(),
},
],
},
};
return produce(state, (draft) => {
draft.group.reviews.push({
...review,
createDate: new Date().toString(),
});
});
},
},
});
Expand Down Expand Up @@ -217,6 +193,7 @@ export const writeStudyGroup = () => async (dispatch, getState) => {
const groupId = await postStudyGroup(
produce(groupReducer.writeField, (draft) => {
draft.moderatorId = user;
draft.reviews = [];
draft.participants.push({
id: user,
});
Expand Down
37 changes: 10 additions & 27 deletions src/reducers/groupSlice.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,36 +277,19 @@ describe('reducer', () => {
rating: 3,
};

context('When the group reviews field is exists', () => {
const initialState = {
group: {
reviews: [],
},
};

it('Set in the group review field', () => {
const state = reducer(initialState, setGroupReview(review));

const { group: { reviews } } = state;

expect(reviews[0].id).toBe('test');
expect(reviews[0].rating).toBe(3);
});
});

context("When the group reviews field isn't exists", () => {
const initialState = {
group: {},
};
const initialState = {
group: {
reviews: [],
},
};

it('Set in the group review field', () => {
const state = reducer(initialState, setGroupReview(review));
it('Set in the group review field', () => {
const state = reducer(initialState, setGroupReview(review));

const { group: { reviews } } = state;
const { group: { reviews } } = state;

expect(reviews[0].id).toBe('test');
expect(reviews[0].rating).toBe(3);
});
expect(reviews[0].id).toBe('test');
expect(reviews[0].rating).toBe(3);
});
});
});
Expand Down