-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6cc8d0
commit 8791167
Showing
17 changed files
with
426 additions
and
22 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
packages/picasso-rich-text-editor/src/LexicalEditor/types.ts
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,3 +1,35 @@ | ||
export type SettingName = 'link' | 'emoji' | ||
|
||
export type ChangeHandler = (html: string) => void | ||
|
||
export type { TextLengthChangeHandler } from '../LexicalTextLengthPlugin' | ||
|
||
export type EditorPlugin = SettingName | ||
|
||
export type CustomEmoji = { | ||
id: string | ||
name: string | ||
keywords: string[] | ||
skins: [ | ||
{ | ||
src: string | ||
} | ||
] | ||
} | ||
|
||
export type CustomEmojiGroup = { | ||
id: string | ||
name: string | ||
emojis: CustomEmoji[] | ||
} | ||
|
||
export type Emoji = { | ||
id: string | ||
name: string | ||
native?: string | ||
unified?: string | ||
keywords: string[] | ||
shortcodes: string | ||
emoticons?: string[] | ||
src?: string | ||
} |
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
77 changes: 77 additions & 0 deletions
77
packages/picasso-rich-text-editor/src/LexicalEmojiPlugin/LexicalEmojiPlugin.test.ts
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,77 @@ | ||
import { renderHook } from '@testing-library/react-hooks' | ||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' | ||
import { $createTextNode, $insertNodes, COMMAND_PRIORITY_EDITOR } from 'lexical' | ||
|
||
import LexicalEmojiPlugin, { | ||
INSERT_CUSTOM_EMOJI_COMMAND, | ||
INSERT_EMOJI_COMMAND, | ||
} from './index' | ||
import { $createCustomEmojiNode } from './nodes/CustomEmojiNode' | ||
|
||
jest.mock('@lexical/react/LexicalComposerContext', () => ({ | ||
useLexicalComposerContext: jest.fn(() => [{}]), | ||
})) | ||
|
||
jest.mock('@lexical/utils', () => ({ | ||
mergeRegister: jest.fn(), | ||
})) | ||
|
||
jest.mock('lexical', () => ({ | ||
$createTextNode: jest.fn(), | ||
$insertNodes: jest.fn(), | ||
COMMAND_PRIORITY_EDITOR: jest.fn(), | ||
createCommand: jest.fn(), | ||
})) | ||
|
||
jest.mock('./nodes/CustomEmojiNode', () => ({ | ||
$createCustomEmojiNode: jest.fn(), | ||
})) | ||
|
||
describe('LexicalEmojiPlugin', () => { | ||
const mockEditor = { | ||
registerCommand: jest.fn(), | ||
} | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
;(useLexicalComposerContext as jest.Mock).mockReturnValue([mockEditor]) | ||
}) | ||
|
||
it('registers commands on mount', () => { | ||
renderHook(() => LexicalEmojiPlugin()) | ||
|
||
expect(mockEditor.registerCommand).toHaveBeenCalledTimes(2) | ||
expect(mockEditor.registerCommand).toHaveBeenCalledWith( | ||
INSERT_EMOJI_COMMAND, | ||
expect.any(Function), | ||
COMMAND_PRIORITY_EDITOR | ||
) | ||
expect(mockEditor.registerCommand).toHaveBeenCalledWith( | ||
INSERT_CUSTOM_EMOJI_COMMAND, | ||
expect.any(Function), | ||
COMMAND_PRIORITY_EDITOR | ||
) | ||
}) | ||
|
||
it('inserts a text node when the native emoji command is called', () => { | ||
renderHook(() => LexicalEmojiPlugin()) | ||
const nativeEmojiCommand = mockEditor.registerCommand.mock.calls[0][1] | ||
|
||
nativeEmojiCommand('😃') | ||
|
||
expect($createTextNode).toHaveBeenCalledWith('😃') | ||
expect($insertNodes).toHaveBeenCalledWith([$createTextNode()]) | ||
}) | ||
|
||
it('inserts a custom emoji node when the custom emoji command is called', () => { | ||
const payload = { id: 'custom emoji', src: 'https://example.com/emoji.png' } | ||
|
||
renderHook(() => LexicalEmojiPlugin()) | ||
const customEmojiCommand = mockEditor.registerCommand.mock.calls[1][1] | ||
|
||
customEmojiCommand(payload) | ||
|
||
expect($createCustomEmojiNode).toHaveBeenCalledWith(payload) | ||
expect($insertNodes).toHaveBeenCalledWith([$createCustomEmojiNode(payload)]) | ||
}) | ||
}) |
Oops, something went wrong.