Ocelot-Social/webapp/components/Editor/defaultExtensions.spec.js
Marco Bomfim f921244661 fix(editor): Fix hashtags not working after embeded content
Up to this point, once you've inserted a given URL to the editor, and it renders a new embeded content, if you hit Return, and try using a tag, or mention, it would not work since the paragraph was never closed, causing a sintatic error that rendered the mentions unable to be used unless you explicitly hit return again, to escape the given text block you were in. See the PR/Issue for further info.
2019-11-06 16:24:48 -03:00

90 lines
2.5 KiB
JavaScript

import defaultExtensions from './defaultExtensions.js'
import { Editor } from 'tiptap'
let content
let createEditor
describe('defaultExtensions', () => {
describe('editor', () => {
createEditor = () => {
const componentStub = {
placeholder: 'placeholder',
$t: jest.fn(),
$apollo: {
mutate: jest.fn(),
},
}
return new Editor({
content,
extensions: [...defaultExtensions(componentStub)],
})
}
})
it('renders', () => {
content = ''
expect(createEditor().getHTML()).toEqual('<p></p>')
})
describe('`content` contains a mentioning', () => {
beforeEach(() => {
content =
'<p>This is a post content mentioning <a class="mention" data-mention-id="alicias-id" href="/profile/f0628376-e692-4167-bdb4-d521de5a014f" target="_blank">@alicia-luettgen</a>.</p>'
})
it('renders mentioning as link', () => {
const editor = createEditor()
const expected =
'<p>This is a post content mentioning <a href="/profile/f0628376-e692-4167-bdb4-d521de5a014f" rel="noopener noreferrer nofollow" target="_blank">@alicia-luettgen</a>.</p>'
expect(editor.getHTML()).toEqual(expected)
})
})
describe('`content` contains a hashtag', () => {
beforeEach(() => {
content =
'<p>This is a post content with a hashtag <a class="hashtag" href="/search/hashtag/metoo" target="_blank">#metoo</a>.</p>'
})
it('renders hashtag as link', () => {
const editor = createEditor()
const expected =
'<p>This is a post content with a hashtag <a href="/search/hashtag/metoo" rel="noopener noreferrer nofollow" target="_blank">#metoo</a>.</p>'
expect(editor.getHTML()).toEqual(expected)
})
})
describe('`content` contains embed code', () => {
beforeEach(() => {
content =
'<p>Baby loves cat: </p><a href="https://www.youtube.com/watch?v=qkdXAtO40Fo" class="embed" target="_blank"></a>'
})
it('recognizes embed code', () => {
const editor = createEditor()
const expected = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
text: 'Baby loves cat:',
type: 'text'
}
]
},
{
type: 'embed',
attrs: {
dataEmbedUrl: 'https://www.youtube.com/watch?v=qkdXAtO40Fo'
}
}
]
}
expect(editor.getJSON()).toEqual(expected)
})
})
})