Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('schema', () => {
const { schema } = createBaseTestManager([{ extension: new CodeBlockExtension(), priority: 1 }]);
const attrs = { language: 'typescript' };
const content = 'unchanged without decorations';
const { codeBlock, doc } = pmBuild(schema, {
codeBlock: { nodeType: 'codeBlock', ...attrs },
});
it('creates the correct dom node', () => {
expect(toHTML({ node: codeBlock(content), schema })).toBe(
`<pre class="language-${attrs.language}"><code data-code-block-language="${attrs.language}">${content}</code></pre>`,
);
});
it('parses the dom structure and finds itself', () => {
const node = fromHTML({
schema,
content: `<pre><code data-code-block-language="${attrs.language}" class="language-${attrs.language}">${content}</code></pre>`,
});
const expected = doc(codeBlock(content));
expect(node).toEqualProsemirrorNode(expected);
it('parses extra attributes', () => {
const { a, doc, p } = pmBuild(schema, {
a: { markType: 'link', href, custom, title },
});
const node = fromHTML({
content: `<p><a data-custom="${custom}" title="${title}" href="${href}">link</a></p>`,
schema,
});
const expected = doc(p(a('link')));
expect(node).toEqualProsemirrorNode(expected);
});
});
it('it produces valid html', () => {
({ schema } = createBaseTestManager([{ extension: new ParagraphExtension(), priority: 1 }]));
({ doc, p } = pmBuild(schema, {
p: { nodeType: 'paragraph', indent: 1, align: 'right', lineSpacing: '100%', id: 'never' },
}));
const html = toHTML({
node: p('hello'),
schema,
});
expect(html).toBe(`<p id="never" data-indent="1" style="text-align: right;line-height: 100%;">hello</p>`);
});
});
describe('schema', () => {
const { schema } = createBaseTestManager([{ extension: new MentionExtension(), priority: 1 }]);
const attrs = { id: 'test', label: '@test', name: 'testing' };
const { mention, p, doc } = pmBuild(schema, {
mention: { markType: 'mention', ...attrs },
});
it('creates the correct dom node', () => {
expect(toHTML({ node: p(mention(attrs.label)), schema })).toMatchInlineSnapshot(`
<p>
<a data-mention-name="testing" data-mention-id="test" class="mention mention-testing">
@test
</a>
</p>
`);
});
{
extension: new CustomExtension({
extraAttrs: [
'title',
['run', 'failure', 'data-run'],
{
default: 'yo',
getAttrs: domNode => (domNode as Element).getAttribute('simple'),
name: 'crazy',
},
],
}),
priority: 1,
},
]);
const { doc, custom, other } = pmBuild(schema, {
custom: { nodeType: 'custom', run, title, crazy: 'yo' },
other: { nodeType: 'custom', run, title, crazy: 'believe me' },
});
it('creates attrs with the correct shape', () => {
expect(schema.nodes.custom.spec.attrs).toEqual({
title: { default: '' },
run: { default: 'failure' },
crazy: { default: 'yo' },
});
});
it('parses the dom for extra attributes', () => {
const node = fromHTML({
content: `<p data-run="${run}" title="${title}">hello</p>`,
schema,
describe('schema', () => {
const { schema } = createBaseTestManager([{ extension: new HeadingExtension(), priority: 1 }]);
const { h1, h2, h3, doc } = pmBuild(schema, {
h1: { nodeType: 'heading' },
h2: { nodeType: 'heading', level: 2 },
h3: { nodeType: 'heading', level: 3 },
});
it('defaults to level 1', () => {
expect(toHTML({ node: h1('Heading'), schema })).toBe('<h1>Heading</h1>');
});
it('changes level based on attributes', () => {
expect(toHTML({ node: h2('Heading'), schema })).toBe('<h2>Heading</h2>');
expect(toHTML({ node: h3('Heading'), schema })).toBe('<h3>Heading</h3>');
});
it('it can parse content', () => {
const node = fromHTML({ content: '<h2>Hello</h2>', schema });
describe('schema', () => {
let { schema } = createBaseTestManager([{ extension: new ParagraphExtension(), priority: 1 }]);
let { doc, p } = pmBuild(schema, {});
it('it can parse content', () => {
({ schema } = createBaseTestManager([{ extension: new ParagraphExtension(), priority: 1 }]));
({ doc, p } = pmBuild(schema, {
p: { nodeType: 'paragraph', indent: 1, align: 'right', lineSpacing: '100%', id: 'never' },
}));
const node = fromHTML({
content: `<p id="never" style="text-align: right; line-height: 100%;" data-indent="1">hello</p>`,
schema,
});
const expected = doc(p('hello'));
expect(node).toEqualProsemirrorNode(expected);
});
it('it produces valid html', () => {
({ schema } = createBaseTestManager([{ extension: new ParagraphExtension(), priority: 1 }]));
beforeEach(() => {
({ schema } = createBaseTestManager([{ extension: new LinkExtension(), priority: 1 }]));
({ a, doc, p } = pmBuild(schema, {
a: { markType: 'link', href },
}));
});