-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lexical: Added testing for some added shortcuts
Also: - Added svg loading support (dummy stub) for jest. - Updated headless test case due to node changes. - Split out editor change detected to where appropriate. - Added functions to help with testing, like mocking our context.
- Loading branch information
1 parent
8486775
commit e50cd33
Showing
10 changed files
with
239 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// This is a basic transformer stub to help jest handle SVG files. | ||
// Essentially blanks them since we don't really need to involve them | ||
// in our tests (yet). | ||
module.exports = { | ||
process() { | ||
return { | ||
code: 'module.exports = \'\';', | ||
}; | ||
}, | ||
getCacheKey() { | ||
// The output is always the same. | ||
return 'svgTransform'; | ||
}, | ||
}; |
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
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
40 changes: 40 additions & 0 deletions
40
resources/js/wysiwyg/lexical/rich-text/__tests__/unit/LexicalDetailsNode.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,40 @@ | ||
import {dispatchKeydownEventForNode, initializeUnitTest} from "lexical/__tests__/utils"; | ||
import {$createDetailsNode, DetailsNode} from "@lexical/rich-text/LexicalDetailsNode"; | ||
import {$createParagraphNode, $getRoot, LexicalNode, ParagraphNode} from "lexical"; | ||
|
||
const editorConfig = Object.freeze({ | ||
namespace: '', | ||
theme: { | ||
}, | ||
}); | ||
|
||
describe('LexicalDetailsNode tests', () => { | ||
initializeUnitTest((testEnv) => { | ||
|
||
test('createDOM()', () => { | ||
const {editor} = testEnv; | ||
let html!: string; | ||
|
||
editor.updateAndCommit(() => { | ||
const details = $createDetailsNode(); | ||
html = details.createDOM(editorConfig, editor).outerHTML; | ||
}); | ||
|
||
expect(html).toBe(`<details><summary contenteditable="false"></summary></details>`); | ||
}); | ||
|
||
test('exportDOM()', () => { | ||
const {editor} = testEnv; | ||
let html!: string; | ||
|
||
editor.updateAndCommit(() => { | ||
const details = $createDetailsNode(); | ||
html = (details.exportDOM(editor).element as HTMLElement).outerHTML; | ||
}); | ||
|
||
expect(html).toBe(`<details><summary></summary></details>`); | ||
}); | ||
|
||
|
||
}); | ||
}) |
95 changes: 95 additions & 0 deletions
95
resources/js/wysiwyg/services/__tests__/keyboard-handling.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,95 @@ | ||
import { | ||
createTestContext, | ||
dispatchKeydownEventForNode, | ||
dispatchKeydownEventForSelectedNode, | ||
initializeUnitTest | ||
} from "lexical/__tests__/utils"; | ||
import { | ||
$createParagraphNode, $createTextNode, | ||
$getRoot, LexicalNode, | ||
ParagraphNode, | ||
} from "lexical"; | ||
import {$createDetailsNode, DetailsNode} from "@lexical/rich-text/LexicalDetailsNode"; | ||
import {registerKeyboardHandling} from "../keyboard-handling"; | ||
import {registerRichText} from "@lexical/rich-text"; | ||
|
||
describe('Keyboard-handling service tests', () => { | ||
initializeUnitTest((testEnv) => { | ||
|
||
test('Details: down key on last lines creates new sibling node', () => { | ||
const {editor} = testEnv; | ||
|
||
registerRichText(editor); | ||
registerKeyboardHandling(createTestContext(testEnv)); | ||
|
||
let lastRootChild!: LexicalNode|null; | ||
let detailsPara!: ParagraphNode; | ||
|
||
editor.updateAndCommit(() => { | ||
const root = $getRoot() | ||
const details = $createDetailsNode(); | ||
detailsPara = $createParagraphNode(); | ||
details.append(detailsPara); | ||
$getRoot().append(details); | ||
detailsPara.select(); | ||
|
||
lastRootChild = root.getLastChild(); | ||
}); | ||
|
||
expect(lastRootChild).toBeInstanceOf(DetailsNode); | ||
|
||
dispatchKeydownEventForNode(detailsPara, editor, 'ArrowDown'); | ||
editor.commitUpdates(); | ||
|
||
editor.getEditorState().read(() => { | ||
lastRootChild = $getRoot().getLastChild(); | ||
}); | ||
|
||
expect(lastRootChild).toBeInstanceOf(ParagraphNode); | ||
}); | ||
|
||
test('Details: enter on last empy block creates new sibling node', () => { | ||
const {editor} = testEnv; | ||
|
||
registerRichText(editor); | ||
registerKeyboardHandling(createTestContext(testEnv)); | ||
|
||
let lastRootChild!: LexicalNode|null; | ||
let detailsPara!: ParagraphNode; | ||
|
||
editor.updateAndCommit(() => { | ||
const root = $getRoot() | ||
const details = $createDetailsNode(); | ||
const text = $createTextNode('Hello!'); | ||
detailsPara = $createParagraphNode(); | ||
detailsPara.append(text); | ||
details.append(detailsPara); | ||
$getRoot().append(details); | ||
text.selectEnd(); | ||
|
||
lastRootChild = root.getLastChild(); | ||
}); | ||
|
||
expect(lastRootChild).toBeInstanceOf(DetailsNode); | ||
|
||
dispatchKeydownEventForNode(detailsPara, editor, 'Enter'); | ||
editor.commitUpdates(); | ||
|
||
dispatchKeydownEventForSelectedNode(editor, 'Enter'); | ||
editor.commitUpdates(); | ||
|
||
let detailsChildren!: LexicalNode[]; | ||
let lastDetailsText!: string; | ||
|
||
editor.getEditorState().read(() => { | ||
detailsChildren = (lastRootChild as DetailsNode).getChildren(); | ||
lastRootChild = $getRoot().getLastChild(); | ||
lastDetailsText = detailsChildren[0].getTextContent(); | ||
}); | ||
|
||
expect(lastRootChild).toBeInstanceOf(ParagraphNode); | ||
expect(detailsChildren).toHaveLength(1); | ||
expect(lastDetailsText).toBe('Hello!'); | ||
}); | ||
}); | ||
}); |
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