/* * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ describe('markdown formatted links to', () => { beforeEach(() => { cy.visitTestNote() }) it('external domains render as external link', () => { cy.setCodemirrorContent('[external](https://hedgedoc.org/)') cy.getMarkdownBody() .find('a') .should('have.attr', 'href', 'https://hedgedoc.org/') .should('have.attr', 'rel', 'noreferer noopener') .should('have.attr', 'target', '_blank') }) it('note anchor references render as anchor link', () => { cy.setCodemirrorContent('[anchor](#anchor)') cy.getMarkdownBody().find('a').should('have.attr', 'href', 'http://127.0.0.1:3001/n/test#anchor') }) it('internal pages render as internal link', () => { cy.setCodemirrorContent('[internal](other-note)') cy.getMarkdownBody().find('a').should('have.attr', 'href', 'http://127.0.0.1:3001/n/other-note') }) it('data URIs do not render', () => { cy.setCodemirrorContent('[data](data:text/plain,evil)') cy.getMarkdownBody().find('a').should('not.exist') }) it('javascript URIs do not render', () => { cy.setCodemirrorContent('[js](javascript:alert("evil"))') cy.getMarkdownBody().find('a').should('not.exist') }) }) describe('HTML anchor element links to', () => { beforeEach(() => { cy.visitTestNote() }) it('external domains render as external link', () => { cy.setCodemirrorContent('external') cy.getMarkdownBody() .find('a') .should('have.attr', 'href', 'https://hedgedoc.org/') .should('have.attr', 'rel', 'noreferer noopener') .should('have.attr', 'target', '_blank') }) it('note anchor references render as anchor link', () => { cy.setCodemirrorContent('anchor') cy.getMarkdownBody().find('a').should('have.attr', 'href', 'http://127.0.0.1:3001/n/test#anchor') }) it('internal pages render as internal link', () => { cy.setCodemirrorContent('internal') cy.getMarkdownBody().find('a').should('have.attr', 'href', 'http://127.0.0.1:3001/n/other-note') }) it('data URIs do not render', () => { cy.setCodemirrorContent('data') cy.getMarkdownBody().find('a').should('not.have.attr', 'href') }) it('javascript URIs do not render', () => { cy.setCodemirrorContent('js') cy.getMarkdownBody().find('a').should('not.have.attr', 'href') }) })