From a5ed6980701b96bd03e22965f127bd08669afcf0 Mon Sep 17 00:00:00 2001 From: reffat Date: Tue, 28 Jan 2025 21:15:45 +0300 Subject: [PATCH] add test --- src/utils/nodes.test.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/utils/nodes.test.ts diff --git a/src/utils/nodes.test.ts b/src/utils/nodes.test.ts new file mode 100644 index 00000000..e29e3c31 --- /dev/null +++ b/src/utils/nodes.test.ts @@ -0,0 +1,37 @@ +import {Schema} from 'prosemirror-model'; + +import {isNodeEmpty} from './nodes'; + +const schema = new Schema({ + nodes: { + doc: {content: 'block+'}, + yfm_cut_content: {content: 'block+'}, + paragraph: {content: 'inline*', group: 'block'}, + text: {group: 'inline'}, + code_block: {content: 'inline*', group: 'block'}, + }, +}); + +describe('isNodeEmpty', () => { + it('yfm_cut_content with an empty paragraph', () => { + const emptyParagraph = schema.nodes.paragraph.create(); + const yfmCutContent = schema.nodes.yfm_cut_content.create(null, emptyParagraph); + + expect(isNodeEmpty(yfmCutContent)).toBe(true); + }); + + it('yfm_cut_content with a paragraph containing text', () => { + const textNode = schema.text('Hello, world!'); + const paragraphWithText = schema.nodes.paragraph.create(null, textNode); + const yfmCutContent = schema.nodes.yfm_cut_content.create(null, paragraphWithText); + + expect(isNodeEmpty(yfmCutContent)).toBe(false); + }); + + it('fm_cut_content with a non-paragraph block', () => { + const codeBlock = schema.nodes.code_block.create(); + const yfmCutContent = schema.nodes.yfm_cut_content.create(null, codeBlock); + + expect(isNodeEmpty(yfmCutContent)).toBe(false); + }); +});