-
Notifications
You must be signed in to change notification settings - Fork 3
[Feature] Applying the editor #30
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 @@ | ||
| module.exports = 'test-file-stub'; |
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 @@ | ||
| module.exports = {}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,45 @@ | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import styled from '@emotion/styled'; | ||
|
|
||
| import { EditorState, convertToRaw } from 'draft-js'; | ||
| import draftToHtml from 'draftjs-to-html'; | ||
| import { Editor } from 'react-draft-wysiwyg'; | ||
|
|
||
| import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css'; | ||
|
|
||
| const WriteEditorWrapper = styled.div``; | ||
|
|
||
| const WriteEditor = ({ onChange }) => { | ||
| const [editorState, setEditorState] = useState(EditorState.createEmpty()); | ||
|
|
||
| const handleChangeEditor = (state) => { | ||
| setEditorState(state); | ||
| onChange({ | ||
|
Comment on lines
+17
to
+18
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| name: 'contents', | ||
| value: draftToHtml(convertToRaw(state.getCurrentContent())), | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <WriteEditorWrapper> | ||
| <Editor | ||
| editorState={editorState} | ||
| onEditorStateChange={handleChangeEditor} | ||
| ariaLabel="contents" | ||
| placeholder="내용을 작성해주세요." | ||
| localization={{ | ||
| locale: 'ko', | ||
| }} | ||
| toolbar={{ | ||
| list: { inDropdown: true }, | ||
| textAlign: { inDropdown: true }, | ||
| link: { inDropdown: true }, | ||
| history: { inDropdown: true }, | ||
| }} | ||
| /> | ||
| </WriteEditorWrapper> | ||
| ); | ||
| }; | ||
|
|
||
| export default WriteEditor; | ||
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,20 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { render } from '@testing-library/react'; | ||
|
|
||
| import WriteEditor from './WriteEditor'; | ||
|
|
||
| describe('WriteEditor', () => { | ||
| const handleChange = jest.fn(); | ||
| const renderWriteButtons = () => render(( | ||
| <WriteEditor | ||
| onChange={handleChange} | ||
| /> | ||
| )); | ||
|
|
||
| it('render Write Editor', () => { | ||
| const { container } = renderWriteButtons(); | ||
|
|
||
| expect(container).toHaveTextContent('내용을 작성해주세요.'); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
그래서 jest 문서에 정적파일처리하는 내용이 있길래 문서와 같이 시도해봤지만, 해결되지 않았습니다.
node_modules안에서 불러와서 그런가 생각해서 빼낸 후 다시 시도해보았지만, 역시 같은 이유로 테스트가 통과하지 못하였습니다.test가 관여하지 않는index.jsx에import를 시켜놓은 상태입니다.Uh oh!
There was an error while loading. Please reload this page.
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.
자바스크립트는 css 파일이나 image 파일들을 import할 수 없습니다. 그래서 webpack은 css-loader나 file-loader등을 사용해서 자바스크립트가 해당 리소스를 불러올 수 있도록 해줘야 합니다. 하지만 테스트 코드에서는 webpack으로 빌드한게 아니기 때문에 올바르게 동작하지 않습니다. 따라서 실제 코드에서는 동작하지만 테스트 코드에서는 필요없는 리소스들은 mocking해야 합니다.
jest.config.js에 다음과 같이 코드를 추가해서 리소스 파일을 불러올 때 마다 내가 지정한 가짜 코드를 불러오도록 할 수 있습니다.
<rootDir>/__mocks__/fileMock.jsSee also
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.
윤석님이 답해주신 해답을 어제도 문서를 보며 적용해보았지만 해결되지 않았습니다.
오늘 다시 해본 결과 잘 됩니다! 감사합니다. 🙏
아마 해결되지 않았던 이유는 test를 껐다가 재실행을 안해서 적용이 안되서 그런거 같습니다.
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.
다행이네요 👍