${link}
` - const doc = prepareDoc(content) - const paragraphs = extractLinkParagraphs(doc) - expect(paragraphs).toEqual([ - { href, pos: 0, type: 'text-only', nodeSize: 6 }, - ]) - }) - - it('returns paragraphs with a single preview', () => { - const doc = prepareDoc(preview) - const paragraphs = extractLinkParagraphs(doc) - expect(paragraphs).toEqual([ - { href, pos: 0, type: 'link-preview', nodeSize: 6 }, - ]) - }) - - it('returns paragraphs with a single link and whitespace', () => { - const content = `${link}
` - const doc = prepareDoc(content) - const paragraphs = extractLinkParagraphs(doc) - expect(paragraphs).toEqual([ - { href, pos: 0, type: 'text-only', nodeSize: 7 }, - ]) - }) - - it('returns multiple paragraphs with a single link', () => { - const paragraph = `${link}
` - const content = paragraph + paragraph - const doc = prepareDoc(content) - const paragraphs = extractLinkParagraphs(doc) - expect(paragraphs).toEqual([ - { href, pos: 0, type: 'text-only', nodeSize: 6 }, - { href, pos: 6, type: 'text-only', nodeSize: 6 }, - ]) - }) - - it('returns previews mixed with paragraphs with a single link', () => { - const content = `${link}
${preview}` - const doc = prepareDoc(content) - const paragraphs = extractLinkParagraphs(doc) - - expect(paragraphs).toEqual([ - { href, pos: 0, type: 'text-only', nodeSize: 6 }, - { href, pos: 6, type: 'link-preview', nodeSize: 6 }, - ]) - }) - - it('ignores an empty paragraph', () => { - const content = '' - const doc = prepareDoc(content) - const paragraphs = extractLinkParagraphs(doc) - expect(paragraphs).toEqual([]) - }) - - it('ignores paragraphs with text after the link', () => { - const content = `${link} Hello
` - const doc = prepareDoc(content) - const paragraphs = extractLinkParagraphs(doc) - expect(paragraphs).toEqual([]) - }) - - it('ignores paragraphs with a link to self', () => { - const content = '' - const doc = prepareDoc(content) - const paragraphs = extractLinkParagraphs(doc) - expect(paragraphs).toEqual([]) - }) - - it('ignores paragraphs with text before the link', () => { - const content = `Hello ${link}
` - const doc = prepareDoc(content) - const paragraphs = extractLinkParagraphs(doc) - expect(paragraphs).toEqual([]) - }) - - it('ignores paragraphs with multiple links', () => { - const content = `${link} ${link}
` - const doc = prepareDoc(content) - const paragraphs = extractLinkParagraphs(doc) - expect(paragraphs).toEqual([]) - }) -}) - -const prepareDoc = (content) => { - const editor = createCustomEditor(content, [Link, Preview]) - return editor.state.doc -}