-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: create new MD Editor * feat: remove eslint issue * feat: add toolbar * feat: add mock exports * feat: migrate some file to typescript * feat: update package lock * feat: update package lock * fix: solve unit test
- Loading branch information
1 parent
2d8670c
commit 820b0ba
Showing
15 changed files
with
7,805 additions
and
5,072 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
53 changes: 53 additions & 0 deletions
53
src/packages/components/rich-editor/react-md-editor.spec.tsx
This file contains 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,53 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { describe, it, vi, expect } from 'vitest'; | ||
|
||
import { MDEditor } from './react-md-editor'; | ||
|
||
vi.mock('@uiw/react-md-editor', () => { | ||
return { | ||
italic: undefined, | ||
bold: undefined, | ||
unorderedListCommand: undefined, | ||
default: ({ | ||
value, | ||
onChange, | ||
}: { | ||
value: string; | ||
onChange: (value?: string) => void; | ||
}) => ( | ||
<textarea | ||
data-testid="editor" | ||
value={value} | ||
onChange={(e) => onChange(e.target.value)} | ||
/> | ||
), | ||
}; | ||
}); | ||
|
||
describe('MDEditor component', () => { | ||
it('should render the editor with the initial text', () => { | ||
const mockHandleChange = vi.fn(); | ||
const initialText = 'Initial text'; | ||
|
||
render(<MDEditor text={initialText} handleChange={mockHandleChange} />); | ||
|
||
const editor = screen.getByTestId('editor') as HTMLInputElement; | ||
expect(editor).toBeInTheDocument(); | ||
expect(editor.value).toBe(initialText); | ||
}); | ||
|
||
it('should call handleChange when the text is updated', async () => { | ||
const mockHandleChange = vi.fn(); | ||
const initialText = ''; | ||
const newText = 'Updated text'; | ||
|
||
render(<MDEditor text={initialText} handleChange={mockHandleChange} />); | ||
|
||
const editor = screen.getByTestId('editor'); | ||
await userEvent.clear(editor); | ||
await userEvent.type(editor, newText); | ||
|
||
expect(mockHandleChange).toHaveBeenCalledTimes(12); | ||
}); | ||
}); |
This file contains 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,19 @@ | ||
import Editor, { | ||
bold, | ||
italic, | ||
unorderedListCommand, | ||
} from '@uiw/react-md-editor'; | ||
|
||
export const MDEditor = ({ | ||
text, | ||
handleChange, | ||
}: Readonly<{ text: string; handleChange: (value?: string) => void }>) => { | ||
return ( | ||
<Editor | ||
value={text} | ||
onChange={handleChange} | ||
commands={[italic, bold, unorderedListCommand]} | ||
preview="edit" | ||
/> | ||
); | ||
}; |
File renamed without changes.
7 changes: 1 addition & 6 deletions
7
...correspondences/association/home.spec.jsx → ...correspondences/association/home.spec.tsx
This file contains 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 |
---|---|---|
@@ -1,16 +1,11 @@ | ||
import { locales } from '../../../tests-utils/default-values'; | ||
import { renderWithAppContext } from '../../../tests-utils/render'; | ||
import * as associationUtils from '../../utils/correspondence/association'; | ||
import Home from './home'; | ||
|
||
describe('association-home', () => { | ||
it('renders without crashing', () => { | ||
renderWithAppContext( | ||
<Home | ||
association={associationUtils.empty()} | ||
secondLang={false} | ||
langs={locales} | ||
/>, | ||
<Home association={associationUtils.empty()} secondLang={false} />, | ||
); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
This file contains 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 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 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 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