diff options
Diffstat (limited to 'spec/frontend/content_editor/extensions/horizontal_rule_spec.js')
-rw-r--r-- | spec/frontend/content_editor/extensions/horizontal_rule_spec.js | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/spec/frontend/content_editor/extensions/horizontal_rule_spec.js b/spec/frontend/content_editor/extensions/horizontal_rule_spec.js index a1bc7f0e8ed..322c04a42e1 100644 --- a/spec/frontend/content_editor/extensions/horizontal_rule_spec.js +++ b/spec/frontend/content_editor/extensions/horizontal_rule_spec.js @@ -1,20 +1,39 @@ -import { hrInputRuleRegExp } from '~/content_editor/extensions/horizontal_rule'; +import HorizontalRule from '~/content_editor/extensions/horizontal_rule'; +import { createTestEditor, createDocBuilder, triggerNodeInputRule } from '../test_utils'; describe('content_editor/extensions/horizontal_rule', () => { - describe.each` - input | matches - ${'---'} | ${true} - ${'--'} | ${false} - ${'---x'} | ${false} - ${' ---x'} | ${false} - ${' --- '} | ${false} - ${'x---x'} | ${false} - ${'x---'} | ${false} - `('hrInputRuleRegExp', ({ input, matches }) => { - it(`${matches ? 'matches' : 'does not match'}: "${input}"`, () => { - const match = new RegExp(hrInputRuleRegExp).test(input); + let tiptapEditor; + let doc; + let p; + let horizontalRule; - expect(match).toBe(matches); - }); + beforeEach(() => { + tiptapEditor = createTestEditor({ extensions: [HorizontalRule] }); + + ({ + builders: { doc, p, horizontalRule }, + } = createDocBuilder({ + tiptapEditor, + names: { + horizontalRule: { nodeType: HorizontalRule.name }, + }, + })); + }); + + it.each` + input | insertedNodes + ${'---'} | ${() => [p(), horizontalRule()]} + ${'--'} | ${() => [p()]} + ${'---x'} | ${() => [p()]} + ${' ---x'} | ${() => [p()]} + ${' --- '} | ${() => [p()]} + ${'x---x'} | ${() => [p()]} + ${'x---'} | ${() => [p()]} + `('with input=$input, then should insert a $insertedNode', ({ input, insertedNodes }) => { + const expectedDoc = doc(...insertedNodes()); + + triggerNodeInputRule({ tiptapEditor, inputRuleText: input }); + + expect(tiptapEditor.getJSON()).toEqual(expectedDoc.toJSON()); }); }); |