Skip to content

Commit 381ab1b

Browse files
committed
fix(autolink): add unit tests for nested and deep-nested MD links
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent c55f9da commit 381ab1b

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/unit/components/NcRichText/NcRichText.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,37 @@ describe('Foo', () => {
192192
expect(wrapper.find('em').text()).toEqual('to')
193193
})
194194

195+
it('does not autolink markdown link text that is already inside a link', async () => {
196+
const wrapper = mount(NcRichText, {
197+
props: {
198+
text: '[https://example-nested.org](https://example.com)',
199+
autolink: true,
200+
useMarkdown: true,
201+
},
202+
})
203+
204+
const links = wrapper.findAll('a')
205+
expect(links).toHaveLength(1)
206+
expect(links[0].attributes('href')).toEqual('https://example.com')
207+
expect(links[0].text()).toEqual('https://example-nested.org')
208+
})
209+
210+
it('does not autolink deeply nested markdown link text that is already inside a link', async () => {
211+
const wrapper = mount(NcRichText, {
212+
props: {
213+
text: '[**https://example-nested.org**](https://example.com)',
214+
autolink: true,
215+
useMarkdown: true,
216+
},
217+
})
218+
219+
const links = wrapper.findAll('a')
220+
expect(links).toHaveLength(1)
221+
expect(links[0].attributes('href')).toEqual('https://example.com')
222+
expect(links[0].text()).toEqual('https://example-nested.org')
223+
expect(wrapper.find('strong').text()).toEqual('https://example-nested.org')
224+
})
225+
195226
it('formats markdown is disabled', async () => {
196227
const wrapper = mount(NcRichText, {
197228
props: {

0 commit comments

Comments
 (0)