mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Refactor some redundant code in Text Input tests (#3768)
Don't show in changelog
This commit is contained in:
@@ -58,7 +58,7 @@ describe('gdjs.TextInputRuntimeObject (using a PixiJS RuntimeGame with DOM eleme
|
||||
});
|
||||
};
|
||||
|
||||
it('creates the DOM element', async () => {
|
||||
const setupObjectAndGetDomElementContainer = async () => {
|
||||
const runtimeGame = await gdjs.getPixiRuntimeGameWithAssets();
|
||||
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
|
||||
loadScene(runtimeScene);
|
||||
@@ -70,10 +70,6 @@ describe('gdjs.TextInputRuntimeObject (using a PixiJS RuntimeGame with DOM eleme
|
||||
const object = makeTextInputRuntimeObject(runtimeScene);
|
||||
runtimeScene.addObject(object);
|
||||
|
||||
// Check the default size.
|
||||
expect(object.getWidth()).to.be(300);
|
||||
expect(object.getHeight()).to.be(30);
|
||||
|
||||
// Check that the DOM element was created
|
||||
const gameDomElementContainer = runtimeGame
|
||||
.getRenderer()
|
||||
@@ -83,6 +79,20 @@ describe('gdjs.TextInputRuntimeObject (using a PixiJS RuntimeGame with DOM eleme
|
||||
'Expected getDomElementContainer to return a valid container.'
|
||||
);
|
||||
|
||||
return { runtimeScene, gameDomElementContainer, object };
|
||||
};
|
||||
|
||||
it('creates the DOM element', async () => {
|
||||
const {
|
||||
runtimeScene,
|
||||
gameDomElementContainer,
|
||||
object,
|
||||
} = await setupObjectAndGetDomElementContainer();
|
||||
|
||||
// Check the default size.
|
||||
expect(object.getWidth()).to.be(300);
|
||||
expect(object.getHeight()).to.be(30);
|
||||
|
||||
expect(gameDomElementContainer.hasChildNodes()).to.be(true);
|
||||
|
||||
const inputElement = gameDomElementContainer.querySelector('input');
|
||||
@@ -98,25 +108,11 @@ describe('gdjs.TextInputRuntimeObject (using a PixiJS RuntimeGame with DOM eleme
|
||||
});
|
||||
|
||||
it('destroys the DOM element when the scene is paused/resumed/stopped', async () => {
|
||||
const runtimeGame = await gdjs.getPixiRuntimeGameWithAssets();
|
||||
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
|
||||
loadScene(runtimeScene);
|
||||
|
||||
// Make sure the renderer is created (to test the real DOM element creation/update)
|
||||
const gameContainer = document.createElement('div');
|
||||
runtimeGame.getRenderer().createStandardCanvas(gameContainer);
|
||||
|
||||
const object = makeTextInputRuntimeObject(runtimeScene);
|
||||
runtimeScene.addObject(object);
|
||||
|
||||
// Check that the DOM element was created
|
||||
const gameDomElementContainer = runtimeGame
|
||||
.getRenderer()
|
||||
.getDomElementContainer();
|
||||
if (!gameDomElementContainer)
|
||||
throw new Error(
|
||||
'Expected getDomElementContainer to return a valid container.'
|
||||
);
|
||||
const {
|
||||
runtimeScene,
|
||||
gameDomElementContainer,
|
||||
object,
|
||||
} = await setupObjectAndGetDomElementContainer();
|
||||
|
||||
expect(gameDomElementContainer.querySelector('input')).not.to.be(null);
|
||||
|
||||
@@ -129,28 +125,17 @@ describe('gdjs.TextInputRuntimeObject (using a PixiJS RuntimeGame with DOM eleme
|
||||
|
||||
runtimeScene.unloadScene();
|
||||
expect(gameDomElementContainer.querySelector('input')).to.be(null);
|
||||
|
||||
// Clean up - not mandatory but to avoid overloading the testing browser.
|
||||
runtimeScene.unloadScene();
|
||||
});
|
||||
|
||||
it('changes the DOM element when the object type is updated', async () => {
|
||||
const runtimeGame = await gdjs.getPixiRuntimeGameWithAssets();
|
||||
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
|
||||
loadScene(runtimeScene);
|
||||
|
||||
// Make sure the renderer is created (to test the real DOM element creation/update)
|
||||
const gameContainer = document.createElement('div');
|
||||
runtimeGame.getRenderer().createStandardCanvas(gameContainer);
|
||||
|
||||
const object = makeTextInputRuntimeObject(runtimeScene);
|
||||
runtimeScene.addObject(object);
|
||||
|
||||
// Check that the DOM element was created
|
||||
const gameDomElementContainer = runtimeGame
|
||||
.getRenderer()
|
||||
.getDomElementContainer();
|
||||
if (!gameDomElementContainer)
|
||||
throw new Error(
|
||||
'Expected getDomElementContainer to return a valid container.'
|
||||
);
|
||||
const {
|
||||
runtimeScene,
|
||||
gameDomElementContainer,
|
||||
object,
|
||||
} = await setupObjectAndGetDomElementContainer();
|
||||
|
||||
expect(gameDomElementContainer.querySelector('input')).not.to.be(null);
|
||||
|
||||
@@ -171,25 +156,11 @@ describe('gdjs.TextInputRuntimeObject (using a PixiJS RuntimeGame with DOM eleme
|
||||
});
|
||||
|
||||
it('hides the DOM element when the object or layer is hidden', async () => {
|
||||
const runtimeGame = await gdjs.getPixiRuntimeGameWithAssets();
|
||||
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
|
||||
loadScene(runtimeScene);
|
||||
|
||||
// Make sure the renderer is created (to test the real DOM element creation/update)
|
||||
const gameContainer = document.createElement('div');
|
||||
runtimeGame.getRenderer().createStandardCanvas(gameContainer);
|
||||
|
||||
const object = makeTextInputRuntimeObject(runtimeScene);
|
||||
runtimeScene.addObject(object);
|
||||
|
||||
// Check that the DOM element was created
|
||||
const gameDomElementContainer = runtimeGame
|
||||
.getRenderer()
|
||||
.getDomElementContainer();
|
||||
if (!gameDomElementContainer)
|
||||
throw new Error(
|
||||
'Expected getDomElementContainer to return a valid container.'
|
||||
);
|
||||
const {
|
||||
runtimeScene,
|
||||
gameDomElementContainer,
|
||||
object,
|
||||
} = await setupObjectAndGetDomElementContainer();
|
||||
|
||||
const inputElement = gameDomElementContainer.querySelector('input');
|
||||
if (!inputElement) throw new Error('Expected input element to be found');
|
||||
@@ -224,25 +195,11 @@ describe('gdjs.TextInputRuntimeObject (using a PixiJS RuntimeGame with DOM eleme
|
||||
});
|
||||
|
||||
it('hides the DOM element when the object is far from the camera', async () => {
|
||||
const runtimeGame = await gdjs.getPixiRuntimeGameWithAssets();
|
||||
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
|
||||
loadScene(runtimeScene);
|
||||
|
||||
// Make sure the renderer is created (to test the real DOM element creation/update)
|
||||
const gameContainer = document.createElement('div');
|
||||
runtimeGame.getRenderer().createStandardCanvas(gameContainer);
|
||||
|
||||
const object = makeTextInputRuntimeObject(runtimeScene);
|
||||
runtimeScene.addObject(object);
|
||||
|
||||
// Check that the DOM element was created
|
||||
const gameDomElementContainer = runtimeGame
|
||||
.getRenderer()
|
||||
.getDomElementContainer();
|
||||
if (!gameDomElementContainer)
|
||||
throw new Error(
|
||||
'Expected getDomElementContainer to return a valid container.'
|
||||
);
|
||||
const {
|
||||
runtimeScene,
|
||||
gameDomElementContainer,
|
||||
object,
|
||||
} = await setupObjectAndGetDomElementContainer();
|
||||
|
||||
const inputElement = gameDomElementContainer.querySelector('input');
|
||||
if (!inputElement) throw new Error('Expected input element to be found');
|
||||
|
@@ -528,7 +528,7 @@ const PropertiesEditor = ({
|
||||
|
||||
if (!!additionalText) {
|
||||
return (
|
||||
<Line alignItems="baseline">
|
||||
<Line alignItems="baseline" key={`section-title-${field.name}`}>
|
||||
<Text displayInlineAsSpan>{field.name}</Text>
|
||||
<Spacer />
|
||||
<Text
|
||||
@@ -540,7 +540,7 @@ const PropertiesEditor = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<Line>
|
||||
<Line key={`section-title-${field.name}`}>
|
||||
<Text displayInlineAsSpan>{field.name}</Text>
|
||||
</Line>
|
||||
);
|
||||
|
Reference in New Issue
Block a user