-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: move width & height from style to attribute in <foreignObject> (#1486) * fix: move width & height from style to attribute in <foreignObject> #1485 * chore: commit changeset * chore(release): bump version (#1488) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
28753a8
commit 992e9d5
Showing
15 changed files
with
162 additions
and
6 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,109 @@ | ||
const util = require('util'); | ||
// ref: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom | ||
// ref: https://github.com/jsdom/jsdom/issues/2524 | ||
Object.defineProperty(window, 'TextEncoder', { | ||
writable: true, | ||
value: util.TextEncoder, | ||
}); | ||
Object.defineProperty(window, 'TextDecoder', { | ||
writable: true, | ||
value: util.TextDecoder, | ||
}); | ||
|
||
const fs = require('fs'); | ||
const { JSDOM } = require('jsdom'); | ||
const xmlserializer = require('xmlserializer'); | ||
const { HTML, Canvas } = require('@antv/g'); | ||
const { Renderer } = require('@antv/g-svg'); | ||
const { sleep } = require('../../util'); | ||
|
||
// create a renderer, unregister plugin relative to DOM | ||
const renderer = new Renderer(); | ||
const domInteractionPlugin = renderer.getPlugin('dom-interaction'); | ||
renderer.unregisterPlugin(domInteractionPlugin); | ||
|
||
const dom = new JSDOM(` | ||
<div id="container"> | ||
</div> | ||
`); | ||
|
||
const SIZE = 200; | ||
const canvas = new Canvas({ | ||
container: 'container', | ||
width: SIZE, | ||
height: SIZE, | ||
renderer, | ||
document: dom.window.document, | ||
requestAnimationFrame: dom.window.requestAnimationFrame, | ||
cancelAnimationFrame: dom.window.cancelAnimationFrame, | ||
}); | ||
|
||
const RESULT_IMAGE = '/html.svg'; | ||
const BASELINE_IMAGE_DIR = '/snapshots'; | ||
|
||
describe('Render <HTML> with g-svg', () => { | ||
afterEach(() => { | ||
canvas.removeChildren(); | ||
}); | ||
|
||
afterAll(() => { | ||
canvas.destroy(); | ||
}); | ||
|
||
it('should render HTML on server-side correctly.', async () => { | ||
await canvas.ready; | ||
const html = new HTML({ | ||
id: 'p1', | ||
name: 'p2-name', | ||
className: 'p2-classname', | ||
style: { | ||
x: 50, | ||
y: 50, | ||
width: 60, | ||
height: 30, | ||
innerHTML: 'p2', | ||
}, | ||
}); | ||
canvas.appendChild(html); | ||
|
||
const html2 = new HTML({ | ||
id: 'p1', | ||
name: 'p2-name', | ||
className: 'p2-classname', | ||
style: { | ||
x: 50, | ||
y: 150, | ||
width: 60, | ||
height: 30, | ||
innerHTML: '<div>p2</div>', | ||
fontSize: '20px', | ||
textAlign: 'center', | ||
color: 'red', | ||
}, | ||
}); | ||
canvas.appendChild(html2); | ||
|
||
await sleep(120); | ||
|
||
// fs.writeFileSync( | ||
// __dirname + RESULT_IMAGE, | ||
// xmlserializer.serializeToString( | ||
// dom.window.document.getElementById('container').children[0], | ||
// ), | ||
// ); | ||
|
||
const snapshot = fs.readFileSync( | ||
__dirname + BASELINE_IMAGE_DIR + RESULT_IMAGE, | ||
{ | ||
encoding: 'utf8', | ||
flag: 'r', | ||
}, | ||
); | ||
|
||
expect( | ||
xmlserializer.serializeToString( | ||
dom.window.document.getElementById('container').children[0], | ||
), | ||
).toBe(snapshot); | ||
}); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
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
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
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
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
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
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
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
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
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