-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to provide a canvas to be used for the game rendering instead o…
…f creating a new one (#7199) Only show in developer changelog
- Loading branch information
1 parent
d110e83
commit 35fd7e9
Showing
3 changed files
with
96 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
describe('gdjs.RuntimeGameRenderer canvas tests', () => { | ||
let runtimeGame; | ||
let renderer; | ||
let gameContainer; | ||
|
||
beforeEach(() => { | ||
runtimeGame = gdjs.getPixiRuntimeGame(); | ||
renderer = runtimeGame.getRenderer(); | ||
gameContainer = document.createElement('div'); | ||
}); | ||
|
||
it('should correctly create standard canvas and domElementsContainer', () => { | ||
renderer.createStandardCanvas(gameContainer); | ||
|
||
const actualGameCanvas = renderer.getCanvas(); | ||
const actualDomElementsContainer = renderer.getDomElementContainer(); | ||
|
||
expect(actualGameCanvas).to.not.be(null); | ||
expect(actualDomElementsContainer).to.not.be(null); | ||
expect(actualGameCanvas.parentElement).to.be(gameContainer); | ||
expect(actualDomElementsContainer.parentElement).to.be(gameContainer); | ||
}); | ||
|
||
it('should correctly initialize external canvas and create domElementsContainer', () => { | ||
const gameCanvas = document.createElement('canvas'); | ||
gameContainer.appendChild(gameCanvas); | ||
renderer.initializeForCanvas(gameCanvas); | ||
|
||
const actualGameCanvas = renderer.getCanvas(); | ||
const actualDomElementsContainer = renderer.getDomElementContainer(); | ||
|
||
expect(actualGameCanvas).to.not.be(null); | ||
expect(actualDomElementsContainer).to.not.be(null); | ||
expect(actualGameCanvas).to.be(gameCanvas); | ||
expect(actualDomElementsContainer.parentElement).to.be(gameContainer); | ||
}); | ||
|
||
it('should remove canvas and domElementsContainer on dispose', () => { | ||
renderer.createStandardCanvas(gameContainer); | ||
|
||
const actualGameCanvas = renderer.getCanvas(); | ||
const actualDomElementsContainer = renderer.getDomElementContainer(); | ||
|
||
expect(actualGameCanvas).to.not.be(null); | ||
expect(actualDomElementsContainer).to.not.be(null); | ||
expect(actualGameCanvas.parentElement).to.be(gameContainer); | ||
expect(actualDomElementsContainer.parentElement).to.be(gameContainer); | ||
|
||
runtimeGame.dispose(true); | ||
|
||
const actualGameCanvasAfterDispose = renderer.getCanvas(); | ||
const actualDomElementsContainerAfterDispose = renderer.getDomElementContainer(); | ||
|
||
expect(actualGameCanvasAfterDispose).to.be(null); | ||
expect(actualDomElementsContainerAfterDispose).to.be(null); | ||
|
||
expect(gameContainer.childNodes.length).to.be(0); | ||
}); | ||
}); |