|
7 | 7 | // Reference tests: https://github.com/nextcloud-deps/CDMarkdownKit/tree/master/CDMarkdownKitTests |
8 | 8 |
|
9 | 9 | import { mount } from 'cypress/vue2' |
| 10 | +import Vue from 'vue' |
| 11 | +import VueRouter from 'vue-router' |
10 | 12 | import NcRichText from '../../src/components/NcRichText/NcRichText.vue' |
11 | 13 |
|
12 | 14 | describe('NcRichText', () => { |
@@ -402,34 +404,56 @@ describe('NcRichText', () => { |
402 | 404 | }) |
403 | 405 |
|
404 | 406 | describe('links', () => { |
| 407 | + const TestRouteComponent = { |
| 408 | + template: '<div />', |
| 409 | + } |
| 410 | + |
| 411 | + const mountRichText = (text: string) => { |
| 412 | + Vue.use(VueRouter) |
| 413 | + const routes = [{ path: '/world', component: TestRouteComponent }] |
| 414 | + const router = new VueRouter({ |
| 415 | + mode: 'history', |
| 416 | + routes, |
| 417 | + }) |
| 418 | + |
| 419 | + mount(NcRichText, { |
| 420 | + propsData: { |
| 421 | + text, |
| 422 | + useMarkdown: true, |
| 423 | + }, |
| 424 | + extensions: { |
| 425 | + plugins: [router], |
| 426 | + }, |
| 427 | + router, |
| 428 | + }) |
| 429 | + } |
| 430 | + |
405 | 431 | const testLink = (key: string, { text, href = text, name = text }) => { |
406 | 432 | it(key, () => { |
407 | | - mount(NcRichText, { |
408 | | - propsData: { |
409 | | - text, |
410 | | - useMarkdown: true, |
411 | | - }, |
412 | | - }) |
| 433 | + mountRichText(text) |
413 | 434 | cy.get('a').should('have.text', name) |
414 | 435 | cy.get('a').invoke('attr', 'href').should('eq', href) |
415 | 436 | }) |
416 | 437 | } |
417 | 438 |
|
418 | 439 | testLink('autolink', { text: 'https://autolink.me' }) |
419 | | - testLink('relative link', { text: '[hello](world)', href: 'world', name: 'hello' }) |
| 440 | + testLink('relative link', { text: '[hello](/world)', href: '/world', name: 'hello' }) |
420 | 441 | testLink('absolute link', { text: '[hello](https://nextcloud.com)', href: 'https://nextcloud.com', name: 'hello' }) |
421 | 442 | testLink('tel link', { text: '[hello](tel:+49123456789)', href: 'tel:+49123456789', name: 'hello' }) |
| 443 | + testLink('mailto link', { text: '[hello](mailto:+49123456789)', href: 'mailto:+49123456789', name: 'hello' }) |
422 | 444 |
|
423 | | - it('no link to unknown protocols', () => { |
424 | | - mount(NcRichText, { |
425 | | - propsData: { |
426 | | - text: '[link](other:proto)', |
427 | | - useMarkdown: true, |
428 | | - }, |
| 445 | + const testNoLink = (key: string, { text, name = text }) => { |
| 446 | + it(key, () => { |
| 447 | + mountRichText(text) |
| 448 | + |
| 449 | + cy.get('body').should('contain', name) |
| 450 | + cy.get('a').should('not.exist') |
429 | 451 | }) |
430 | | - cy.get('body').should('contain', name) |
431 | | - cy.get('a').should('not.exist') |
432 | | - }) |
| 452 | + } |
| 453 | + testNoLink('no link to unknown protocols', { text: '[hello](other:proto)', name: 'hello' }) |
| 454 | + testNoLink('no link to unresolved relative link (by router)', { text: '[hello](world)', name: 'hello' }) |
| 455 | + testNoLink('no link to relative parameters', { text: '[hello](?parameters=1)', name: 'hello' }) |
| 456 | + testNoLink('no link to relative anchor', { text: '[hello](#anchor)', name: 'hello' }) |
433 | 457 | }) |
434 | 458 |
|
435 | 459 | describe('multiline code', () => { |
|
0 commit comments