debian-mirror-gitlab/spec/frontend/content_editor/extensions/frontmatter_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
2 KiB
JavaScript
Raw Normal View History

2021-12-11 22:18:48 +05:30
import Frontmatter from '~/content_editor/extensions/frontmatter';
2022-03-02 08:16:31 +05:30
import CodeBlockHighlight from '~/content_editor/extensions/code_block_highlight';
2021-12-11 22:18:48 +05:30
import { createTestEditor, createDocBuilder, triggerNodeInputRule } from '../test_utils';
describe('content_editor/extensions/frontmatter', () => {
let tiptapEditor;
let doc;
2022-03-02 08:16:31 +05:30
let frontmatter;
let codeBlock;
2021-12-11 22:18:48 +05:30
beforeEach(() => {
2022-03-02 08:16:31 +05:30
tiptapEditor = createTestEditor({ extensions: [Frontmatter, CodeBlockHighlight] });
2021-12-11 22:18:48 +05:30
({
2022-03-02 08:16:31 +05:30
builders: { doc, codeBlock, frontmatter },
2021-12-11 22:18:48 +05:30
} = createDocBuilder({
tiptapEditor,
names: {
frontmatter: { nodeType: Frontmatter.name },
2022-03-02 08:16:31 +05:30
codeBlock: { nodeType: CodeBlockHighlight.name },
2021-12-11 22:18:48 +05:30
},
}));
});
2022-07-16 23:28:13 +05:30
it('inherits from code block highlight extension', () => {
expect(Frontmatter.parent).toBe(CodeBlockHighlight);
});
2021-12-11 22:18:48 +05:30
it('does not insert a frontmatter block when executing code block input rule', () => {
2022-06-21 17:19:12 +05:30
const expectedDoc = doc(codeBlock({ language: 'plaintext' }, ''));
2021-12-11 22:18:48 +05:30
const inputRuleText = '``` ';
triggerNodeInputRule({ tiptapEditor, inputRuleText });
expect(tiptapEditor.getJSON()).toEqual(expectedDoc.toJSON());
});
2022-03-02 08:16:31 +05:30
2022-07-16 23:28:13 +05:30
it('sets isFrontmatter attribute to true by default', () => {
expect(Frontmatter.config.addAttributes()).toEqual(
expect.objectContaining({
isFrontmatter: { default: true },
}),
);
});
2022-03-02 08:16:31 +05:30
it.each`
command | result | resultDesc
${'toggleCodeBlock'} | ${() => doc(codeBlock(''))} | ${'code block element'}
${'setCodeBlock'} | ${() => doc(codeBlock(''))} | ${'code block element'}
${'setFrontmatter'} | ${() => doc(frontmatter(''))} | ${'frontmatter element'}
${'toggleFrontmatter'} | ${() => doc(frontmatter(''))} | ${'frontmatter element'}
`('executing $command should generate a document with a $resultDesc', ({ command, result }) => {
const expectedDoc = result();
tiptapEditor.commands[command]();
expect(tiptapEditor.getJSON()).toEqual(expectedDoc.toJSON());
});
2021-12-11 22:18:48 +05:30
});