diff --git a/cypress/integration/diagrams.spec.ts b/cypress/integration/diagrams.spec.ts new file mode 100644 index 000000000..186810da3 --- /dev/null +++ b/cypress/integration/diagrams.spec.ts @@ -0,0 +1,74 @@ +/* + * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +describe('Diagram codeblock ', () => { + beforeEach(() => { + cy.visitTestEditor() + }) + + it('renders markmap', () => { + cy.codemirrorFill('```markmap\n- pro\n- contra\n```') + cy.getMarkdownBody() + .find('[data-cy=markmap]') + .children() + .should('be.visible') + }) + + it('renders vega-lite', () => { + cy.codemirrorFill('```vega-lite\n{"$schema":"https://vega.github.io/schema/vega-lite/v4.json","data":{"values":[{"a":"","b":28}]},"mark":"bar","encoding":{"x":{"field":"a"},"y":{"field":"b"}}}\n```') + cy.getMarkdownBody() + .find('.vega-embed') + .children() + .should('be.visible') + }) + + it('renders graphviz', () => { + cy.codemirrorFill('```graphviz\ngraph {\na -- b\n}\n```') + cy.getMarkdownBody() + .find('[data-cy=graphviz]') + .children() + .should('be.visible') + }) + + it('renders mermaid', () => { + cy.codemirrorFill('```mermaid\ngraph TD;\n A-->B;\n```') + cy.getMarkdownBody() + .find('.mermaid') + .children() + .should('be.visible') + }) + + it('renders flowcharts', () => { + cy.codemirrorFill('```flow\nst=>start: Start\ne=>end: End\nst->e\n```') + cy.getMarkdownBody() + .find('[data-cy=flowchart]') + .children() + .should('be.visible') + }) + + it('renders abc scores', () => { + cy.codemirrorFill('```abc\nM:4/4\nK:G\n|:GABc dedB:|\n```') + cy.getMarkdownBody() + .find('.abcjs-score') + .children() + .should('be.visible') + }) + + it('renders csv as table', () => { + cy.codemirrorFill('```csv delimiter=; header\na;b;c;d\n1;2;3;4\n```') + cy.getMarkdownBody() + .find('.csv-html-table') + .should('be.visible') + }) + + it('renders plantuml', () => { + cy.codemirrorFill('```plantuml\nclass Example\n```') + cy.getMarkdownBody() + .find('img') + // PlantUML uses base64 encoded version of zip-deflated PlantUML code in the request URL. + .should('have.attr', 'src', 'http://mock-plantuml.local/svg/SoWkIImgAStDuKhEIImkLd2jICmjo4dbSaZDIm6A0W00') + }) +}) diff --git a/cypress/integration/linkEmbedder.spec.ts b/cypress/integration/linkEmbedder.spec.ts new file mode 100644 index 000000000..6b988bd2e --- /dev/null +++ b/cypress/integration/linkEmbedder.spec.ts @@ -0,0 +1,69 @@ +/* + * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +describe('Link gets replaced with embedding: ', () => { + beforeEach(() => { + cy.visitTestEditor() + }) + + // TODO Add general testing of one-click-embedding component. The tests below just test a specific use of the component. + + it('GitHub Gist', () => { + cy.codemirrorFill('https://gist.github.com/schacon/1') + cy.getMarkdownBody() + .find('.one-click-embedding.gist-frame') + .click() + cy.getMarkdownBody() + .find('iframe[data-cy=gh-gist]') + .should('be.visible') + }) + + it('YouTube', () => { + cy.codemirrorFill('https://www.youtube.com/watch?v=YE7VzlLtp-4') + cy.getMarkdownBody() + .find('.one-click-embedding-preview') + .should('have.attr', 'src', 'https://i.ytimg.com/vi/YE7VzlLtp-4/maxresdefault.jpg') + .parent() + .click() + cy.getMarkdownBody() + .find('iframe') + .should('have.attr', 'src', 'https://www.youtube-nocookie.com/embed/YE7VzlLtp-4?autoplay=1') + }) + + it('Vimeo', () => { + cy.intercept({ + method: 'GET', + url: 'https://vimeo.com/api/v2/video/23237102.json' + }, { + statusCode: 200, + headers: { + 'content-type': 'application/json' + }, + body: '[{"thumbnail_large": "https://i.vimeocdn.com/video/503631401_640.jpg"}]' + }) + cy.codemirrorFill('https://vimeo.com/23237102') + cy.getMarkdownBody() + .find('.one-click-embedding-preview') + .should('have.attr', 'src', 'https://i.vimeocdn.com/video/503631401_640.jpg') + .parent() + .click() + cy.getMarkdownBody() + .find('iframe') + .should('have.attr', 'src', 'https://player.vimeo.com/video/23237102?autoplay=1') + }) + + it('Asciinema', () => { + cy.codemirrorFill('https://asciinema.org/a/117928') + cy.getMarkdownBody() + .find('.one-click-embedding-preview') + .should('have.attr', 'src', 'https://asciinema.org/a/117928.png') + .parent() + .click() + cy.getMarkdownBody() + .find('iframe') + .should('have.attr', 'src', 'https://asciinema.org/a/117928/embed?autoplay=1') + }) +}) diff --git a/cypress/integration/shortcodes.spec.ts b/cypress/integration/shortcodes.spec.ts index 8a9e31a5e..719c3ab9b 100644 --- a/cypress/integration/shortcodes.spec.ts +++ b/cypress/integration/shortcodes.spec.ts @@ -4,12 +4,12 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -describe('Short code', () => { +describe('Short code gets replaced or rendered: ', () => { beforeEach(() => { cy.visitTestEditor() }) - describe('for pdfs', () => { + describe('pdf', () => { it('renders a plain link', () => { cy.codemirrorFill(`{%pdf https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf %}`) cy.getMarkdownBody() @@ -17,4 +17,30 @@ describe('Short code', () => { .should('have.attr', 'href', 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf') }) }) + + describe('slideshare', () => { + it('renders a plain link', () => { + cy.codemirrorFill(`{%slideshare example/123456789 %}`) + cy.getMarkdownBody() + .find('a') + .should('have.attr', 'href', 'https://www.slideshare.net/example/123456789') + }) + }) + + describe('speakerdeck', () => { + it('renders a plain link', () => { + cy.codemirrorFill(`{%speakerdeck example/123456789 %}`) + cy.getMarkdownBody() + .find('a') + .should('have.attr', 'href', 'https://speakerdeck.com/example/123456789') + }) + }) + + describe('youtube', () => { + it('renders one-click-embedding', () => { + cy.codemirrorFill(`{%youtube YE7VzlLtp-4 %}`) + cy.getMarkdownBody() + .find('.one-click-embedding.embed-responsive-item') + }) + }) }) diff --git a/cypress/support/config.ts b/cypress/support/config.ts index aaa89d9d1..bac8e4f95 100644 --- a/cypress/support/config.ts +++ b/cypress/support/config.ts @@ -45,6 +45,7 @@ beforeEach(() => { termsOfUse: 'https://example.com/termsOfUse', imprint: 'https://example.com/imprint' }, + plantumlServer: 'http://mock-plantuml.local', version: { version: 'mock', sourceCodeUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', diff --git a/src/components/markdown-renderer/replace-components/flow/flowchart/flowchart.tsx b/src/components/markdown-renderer/replace-components/flow/flowchart/flowchart.tsx index d24b68f6e..949f97c73 100644 --- a/src/components/markdown-renderer/replace-components/flow/flowchart/flowchart.tsx +++ b/src/components/markdown-renderer/replace-components/flow/flowchart/flowchart.tsx @@ -57,6 +57,6 @@ export const FlowChart: React.FC = ({ code }) => { ) } else { - return
+ return
} } diff --git a/src/components/markdown-renderer/replace-components/gist/gist-frame.tsx b/src/components/markdown-renderer/replace-components/gist/gist-frame.tsx index 74fab494d..8a9ff6259 100644 --- a/src/components/markdown-renderer/replace-components/gist/gist-frame.tsx +++ b/src/components/markdown-renderer/replace-components/gist/gist-frame.tsx @@ -66,6 +66,7 @@ export const GistFrame: React.FC = ({ id }) => { return (