-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure void elements have closing slash in mermaid svg (#15661)
* force self-closing breaking space tags in generated mermaid svg * expand void element regular expression * use explicit securityLevel * add more diagram examples to browser test * remove MIME string from test mermaid test notebook * roll back existing test change, add diagram gallery test * rework test selectors * add screenshots from ci * fix mermaid snapshot naming * remove gitgraph screenshots because random hashes * more mermaid screenshot work * more isolated, verbose diagram screenshot names * more screenshots * add unit tests for void element cleaning * another unclosed tag * Fix snapshots for large diagrams * Scale the diagram up to avoid having a small blurry blob * Update Playwright Snapshots --------- Co-authored-by: krassowski <5832902+krassowski@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7052a4c
commit e51ff33
Showing
36 changed files
with
751 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
import { expect, galata, test } from '@jupyterlab/galata'; | ||
import * as path from 'path'; | ||
import { Locator } from '@playwright/test'; | ||
|
||
const fileName = 'mermaid_diagrams.ipynb'; | ||
|
||
const EXPECTED_MERMAID_ORDER = [ | ||
'flowchart', | ||
'sequence', | ||
'class', | ||
'state', | ||
'er', | ||
'journey', | ||
'gantt', | ||
'pie', | ||
'quadrant', | ||
'requirement', | ||
'c4', | ||
'mindmap', | ||
'timeline', | ||
'sankey', | ||
'xy' | ||
]; | ||
|
||
/** | ||
* Workaround for playwright not handling screenshots | ||
* for elements larger than viewport, derived from: | ||
* https://github.com/microsoft/playwright/issues/13486#issuecomment-1112012053 | ||
*/ | ||
async function resizePageAndScreenshot(locator: Locator) { | ||
const page = locator.page(); | ||
const box = await locator.boundingBox(); | ||
const originalSize = page.viewportSize(); | ||
if (box.width > originalSize.width || box.height > originalSize.height) { | ||
const scaleFactor = Math.max( | ||
originalSize.width / box.width, | ||
originalSize.height / box.height | ||
); | ||
await page.setViewportSize({ | ||
width: Math.ceil(box.width * scaleFactor), | ||
height: Math.ceil(box.height * scaleFactor) | ||
}); | ||
} | ||
const screenshot = await locator.screenshot(); | ||
await page.setViewportSize(originalSize); | ||
return screenshot; | ||
} | ||
|
||
for (const theme of ['default', 'dark']) { | ||
const dark = theme === 'dark'; | ||
test.describe(`Notebook Mermaid Diagrams ${theme}`, () => { | ||
test.beforeEach(async ({ page, request, tmpPath }) => { | ||
const contents = galata.newContentsHelper(request); | ||
await contents.uploadFile( | ||
path.resolve(__dirname, `./notebooks/${fileName}`), | ||
`${tmpPath}/${fileName}` | ||
); | ||
await page.filebrowser.openDirectory(tmpPath); | ||
const nbPath = `${tmpPath}/${fileName}`; | ||
|
||
if (dark) { | ||
await page.theme.setDarkTheme(); | ||
} | ||
|
||
await page.notebook.openByPath(nbPath); | ||
await page.notebook.activate(fileName); | ||
}); | ||
|
||
for (let i = 0; i < EXPECTED_MERMAID_ORDER.length; i++) { | ||
let diagram = EXPECTED_MERMAID_ORDER[i]; | ||
const iZero = `${i}`.padStart(2, '0'); | ||
|
||
test(`Mermaid Diagram ${i} ${diagram} in ${theme} theme`, async ({ | ||
page | ||
}) => { | ||
const output = page.locator( | ||
`.jp-Cell:nth-child(${i + 1}) .jp-RenderedMermaid` | ||
); | ||
await output.waitFor(); | ||
|
||
expect(await resizePageAndScreenshot(output)).toMatchSnapshot( | ||
`mermaid-diagram-${theme}-${iZero}-${diagram}.png` | ||
); | ||
}); | ||
} | ||
}); | ||
} |
Binary file added
BIN
+5.91 KB
...agrams.test.ts-snapshots/mermaid-diagram-dark-00-flowchart-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13.5 KB
...iagrams.test.ts-snapshots/mermaid-diagram-dark-01-sequence-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+29.8 KB
...d-diagrams.test.ts-snapshots/mermaid-diagram-dark-02-class-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.6 KB
...d-diagrams.test.ts-snapshots/mermaid-diagram-dark-03-state-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28 KB
...maid-diagrams.test.ts-snapshots/mermaid-diagram-dark-04-er-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.6 KB
...diagrams.test.ts-snapshots/mermaid-diagram-dark-05-journey-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+24.2 KB
...d-diagrams.test.ts-snapshots/mermaid-diagram-dark-06-gantt-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+31.2 KB
...aid-diagrams.test.ts-snapshots/mermaid-diagram-dark-07-pie-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13 KB
...iagrams.test.ts-snapshots/mermaid-diagram-dark-08-quadrant-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.3 KB
...rams.test.ts-snapshots/mermaid-diagram-dark-09-requirement-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+49 KB
...maid-diagrams.test.ts-snapshots/mermaid-diagram-dark-10-c4-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+36.6 KB
...diagrams.test.ts-snapshots/mermaid-diagram-dark-11-mindmap-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.9 KB
...iagrams.test.ts-snapshots/mermaid-diagram-dark-12-timeline-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+188 KB
...-diagrams.test.ts-snapshots/mermaid-diagram-dark-13-sankey-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+29.6 KB
...maid-diagrams.test.ts-snapshots/mermaid-diagram-dark-14-xy-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.94 KB
...ams.test.ts-snapshots/mermaid-diagram-default-00-flowchart-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13.5 KB
...rams.test.ts-snapshots/mermaid-diagram-default-01-sequence-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+29.7 KB
...iagrams.test.ts-snapshots/mermaid-diagram-default-02-class-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.8 KB
...iagrams.test.ts-snapshots/mermaid-diagram-default-03-state-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28.4 KB
...d-diagrams.test.ts-snapshots/mermaid-diagram-default-04-er-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17 KB
...grams.test.ts-snapshots/mermaid-diagram-default-05-journey-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+24 KB
...iagrams.test.ts-snapshots/mermaid-diagram-default-06-gantt-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+37.4 KB
...-diagrams.test.ts-snapshots/mermaid-diagram-default-07-pie-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13.2 KB
...rams.test.ts-snapshots/mermaid-diagram-default-08-quadrant-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.7 KB
...s.test.ts-snapshots/mermaid-diagram-default-09-requirement-jupyterlab-linux.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+52.8 KB
...d-diagrams.test.ts-snapshots/mermaid-diagram-default-10-c4-jupyterlab-linux.png
Oops, something went wrong.
Binary file added
BIN
+34.8 KB
...grams.test.ts-snapshots/mermaid-diagram-default-11-mindmap-jupyterlab-linux.png
Oops, something went wrong.
Binary file added
BIN
+36.1 KB
...rams.test.ts-snapshots/mermaid-diagram-default-12-timeline-jupyterlab-linux.png
Oops, something went wrong.
Binary file added
BIN
+191 KB
...agrams.test.ts-snapshots/mermaid-diagram-default-13-sankey-jupyterlab-linux.png
Oops, something went wrong.
Binary file added
BIN
+30.4 KB
...d-diagrams.test.ts-snapshots/mermaid-diagram-default-14-xy-jupyterlab-linux.png
Oops, something went wrong.
Oops, something went wrong.