-
Notifications
You must be signed in to change notification settings - Fork 3
[Feature] onChange All Write Fields in Write Page #25
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| const writeForm = { | ||
| title: '스터디를 소개합니다.1', | ||
| contents: '우리는 이것저것 합니다.1', | ||
| moderatorId: 'user1', | ||
| applyEndDate: '2020-11-26', | ||
| participants: [], | ||
| personnel: 10, | ||
| tags: [ | ||
| 'JavaScript', | ||
| 'Algorithm', | ||
| ], | ||
| }; | ||
|
|
||
| export default writeForm; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import React from 'react'; | ||
|
|
||
| import styled from '@emotion/styled'; | ||
|
|
||
| const WriteFormWrapper = styled.div``; | ||
|
|
||
| const WriteForm = ({ onChange, fields }) => { | ||
| const { | ||
| title, applyEndDate, personnel, contents, | ||
| } = fields; | ||
|
|
||
| const handleChange = (e) => { | ||
| const { name, value } = e.target; | ||
|
|
||
| onChange({ name, value }); | ||
| }; | ||
|
|
||
| return ( | ||
| <WriteFormWrapper> | ||
| <div> | ||
| <input | ||
| type="text" | ||
| name="title" | ||
| value={title} | ||
| onChange={handleChange} | ||
| placeholder="제목을 입력하세요" | ||
| /> | ||
| </div> | ||
| <div> | ||
| <label htmlFor="application-deadline">모집 마감 날짜</label> | ||
| <input | ||
| type="date" | ||
| name="applyEndDate" | ||
| value={applyEndDate} | ||
| onChange={handleChange} | ||
| id="application-deadline" | ||
| /> | ||
| </div> | ||
| <div> | ||
| <label htmlFor="participants-number">참여 인원 수</label> | ||
| <input | ||
| type="number" | ||
| name="personnel" | ||
| value={personnel} | ||
| onChange={handleChange} | ||
| id="participants-number" | ||
| /> | ||
| </div> | ||
| <div> | ||
| {/* TODO: 추후 draft.js를 사용하여 변경 예정 */} | ||
| <textarea | ||
| rows="10" | ||
| cols="100" | ||
| name="contents" | ||
| value={contents} | ||
| onChange={handleChange} | ||
| placeholder="내용" | ||
| /> | ||
| </div> | ||
| </WriteFormWrapper> | ||
| ); | ||
| }; | ||
|
|
||
| export default WriteForm; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { fireEvent, render } from '@testing-library/react'; | ||
|
|
||
| import WriteForm from './WriteForm'; | ||
|
|
||
| import WRITE_FORM from '../../../fixtures/write-form'; | ||
|
|
||
| describe('WriteForm', () => { | ||
| const handleChange = jest.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| handleChange.mockClear(); | ||
| }); | ||
|
|
||
| const renderWriteForm = (fields) => render(( | ||
| <WriteForm | ||
| fields={fields} | ||
| onChange={handleChange} | ||
| /> | ||
| )); | ||
|
|
||
| it('renders input write form text', () => { | ||
| const { getByLabelText, getByPlaceholderText } = renderWriteForm(WRITE_FORM); | ||
|
|
||
| const { | ||
| title, applyEndDate, personnel, contents, | ||
| } = WRITE_FORM; | ||
|
|
||
| expect(getByPlaceholderText('제목을 입력하세요')).toHaveValue(title); | ||
| expect(getByLabelText('모집 마감 날짜')).toHaveValue(applyEndDate); | ||
| expect(getByLabelText('참여 인원 수')).toHaveValue(personnel); | ||
| expect(getByPlaceholderText('내용')).toHaveTextContent(contents); | ||
| }); | ||
|
|
||
| describe('listens change event', () => { | ||
| it('write fields value change', () => { | ||
| const { getByPlaceholderText } = renderWriteForm(WRITE_FORM); | ||
|
|
||
| const { title } = WRITE_FORM; | ||
|
|
||
| const inputTitle = getByPlaceholderText('제목을 입력하세요'); | ||
| expect(inputTitle).toHaveValue(title); | ||
|
|
||
| fireEvent.change(inputTitle, { | ||
| target: { | ||
| value: '안녕하세요!', | ||
| name: 'title', | ||
| }, | ||
| }); | ||
|
|
||
| expect(handleChange).toBeCalled(); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { useDispatch, useSelector } from 'react-redux'; | ||
|
|
||
| import { get } from '../../util/utils'; | ||
| import WriteForm from '../../components/write/WriteForm'; | ||
|
|
||
| import { changeWriteField } from '../../reducers/slice'; | ||
|
|
||
| const WriteFormContainer = () => { | ||
| const dispatch = useDispatch(); | ||
|
|
||
| const writeField = useSelector(get('writeField')); | ||
|
|
||
| const onChangeWriteField = ({ name, value }) => { | ||
| dispatch( | ||
| changeWriteField({ | ||
| name, | ||
| value, | ||
| }), | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <WriteForm | ||
| fields={writeField} | ||
| onChange={onChangeWriteField} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default WriteFormContainer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { useDispatch, useSelector } from 'react-redux'; | ||
|
|
||
| import { fireEvent, render } from '@testing-library/react'; | ||
|
|
||
| import WriteFormContainer from './WriteFormContainer'; | ||
|
|
||
| describe('WriteFormContainer', () => { | ||
| const dispatch = jest.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| dispatch.mockClear(); | ||
|
|
||
| useDispatch.mockImplementation(() => dispatch); | ||
|
|
||
| useSelector.mockImplementation((state) => state({ | ||
| writeField: { | ||
| title: '', | ||
| contents: '', | ||
| moderatorId: '', | ||
| applyEndDate: '', | ||
| participants: [], | ||
| personnel: 0, | ||
| }, | ||
| })); | ||
| }); | ||
|
|
||
| const renderWriteFormContainer = () => render(( | ||
| <WriteFormContainer /> | ||
| )); | ||
|
|
||
| describe('render Write Form Container contents text', () => { | ||
| it('renders write input text', () => { | ||
| const { getByPlaceholderText, getByLabelText } = renderWriteFormContainer(); | ||
|
|
||
| expect(getByPlaceholderText('제목을 입력하세요')).not.toBeNull(); | ||
| expect(getByPlaceholderText('내용')).not.toBeNull(); | ||
| expect(getByLabelText('모집 마감 날짜')).not.toBeNull(); | ||
| expect(getByLabelText('참여 인원 수')).not.toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('dispatch actions call', () => { | ||
| const { value, name } = { | ||
| name: 'title', | ||
| value: '안녕하세요!', | ||
| }; | ||
| it('listens actions change event', () => { | ||
| const { getByPlaceholderText } = renderWriteFormContainer(); | ||
|
|
||
| const inputTitle = getByPlaceholderText('제목을 입력하세요'); | ||
|
|
||
| expect(inputTitle).toHaveValue(''); | ||
|
|
||
| fireEvent.change(inputTitle, { | ||
| target: { value, name }, | ||
| }); | ||
|
|
||
| expect(dispatch).toBeCalledWith({ | ||
| payload: { | ||
| name, | ||
| value, | ||
| }, | ||
| type: 'application/changeWriteField', | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.