Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions e2e/case/sprite-filled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @title SpriteFilled
* @category Sprite
*/
import {
AssetType,
Camera,
Sprite,
SpriteDrawMode,
SpriteFilledMode,
SpriteRenderer,
Texture2D,
WebGLEngine
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

// One baseline covering every fill mode (rows) across fill amounts 0/0.25/0.5/0.75/1 (columns).
// The amount steps hit the topology boundaries (45° quad↔triangle, 90° quadrant edges).
WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
engine.canvas.resizeByClientSize();
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();

const cameraEntity = rootEntity.createChild("Camera");
cameraEntity.transform.setPosition(0, 0, 50);
const camera = cameraEntity.addComponent(Camera);
camera.isOrthographic = true;
camera.orthographicSize = 9;

engine.resourceManager
.load<Texture2D>({
url: "https://gw.alipayobjects.com/mdn/rms_7c464e/afts/img/A*rgNGR4Vb7lQAAAAAAAAAAAAAARQnAQ",
type: AssetType.Texture
})
.then((texture) => {
const sprite = new Sprite(engine, texture);
const modes = [
SpriteFilledMode.Horizontal,
SpriteFilledMode.Vertical,
SpriteFilledMode.Radial90,
SpriteFilledMode.Radial180,
SpriteFilledMode.Radial360
];
const amounts = [0, 0.25, 0.5, 0.75, 1];

modes.forEach((mode, row) => {
amounts.forEach((amount, col) => {
const entity = rootEntity.createChild(`filled-${row}-${col}`);
entity.transform.setPosition((col - 2) * 3, (2 - row) * 3, 0);
const renderer = entity.addComponent(SpriteRenderer);
renderer.sprite = sprite;
renderer.width = 2.4;
renderer.height = 2.4;
renderer.drawMode = SpriteDrawMode.Filled;
renderer.filledMode = mode;
renderer.filledAmount = amount;
});
});

updateForE2E(engine);
initScreenshot(engine, camera);
});
});
Comment on lines +30 to +63

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use a repo-hosted texture fixture and handle load failures explicitly.

Line 32 fetches from an external CDN, which makes this baseline test vulnerable to network/service/asset drift. Also, the load chain has no rejection handler, so failures are harder to diagnose in CI.

Suggested hardening
-  engine.resourceManager
-    .load<Texture2D>({
-      url: "https://gw.alipayobjects.com/mdn/rms_7c464e/afts/img/A*rgNGR4Vb7lQAAAAAAAAAAAAAARQnAQ",
-      type: AssetType.Texture
-    })
-    .then((texture) => {
+  const textureUrl = "e2e/assets/sprite-filled.png"; // checked-in deterministic fixture
+  engine.resourceManager
+    .load<Texture2D>({
+      url: textureUrl,
+      type: AssetType.Texture
+    })
+    .then((texture) => {
       const sprite = new Sprite(engine, texture);
       // ...
       updateForE2E(engine);
       initScreenshot(engine, camera);
-    });
+    })
+    .catch((err) => {
+      throw new Error(`sprite-filled e2e setup failed: ${String(err)}`);
+    });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
engine.resourceManager
.load<Texture2D>({
url: "https://gw.alipayobjects.com/mdn/rms_7c464e/afts/img/A*rgNGR4Vb7lQAAAAAAAAAAAAAARQnAQ",
type: AssetType.Texture
})
.then((texture) => {
const sprite = new Sprite(engine, texture);
const modes = [
SpriteFilledMode.Horizontal,
SpriteFilledMode.Vertical,
SpriteFilledMode.Radial90,
SpriteFilledMode.Radial180,
SpriteFilledMode.Radial360
];
const amounts = [0, 0.25, 0.5, 0.75, 1];
modes.forEach((mode, row) => {
amounts.forEach((amount, col) => {
const entity = rootEntity.createChild(`filled-${row}-${col}`);
entity.transform.setPosition((col - 2) * 3, (2 - row) * 3, 0);
const renderer = entity.addComponent(SpriteRenderer);
renderer.sprite = sprite;
renderer.width = 2.4;
renderer.height = 2.4;
renderer.drawMode = SpriteDrawMode.Filled;
renderer.filledMode = mode;
renderer.filledAmount = amount;
});
});
updateForE2E(engine);
initScreenshot(engine, camera);
});
});
const textureUrl = "e2e/assets/sprite-filled.png"; // checked-in deterministic fixture
engine.resourceManager
.load<Texture2D>({
url: textureUrl,
type: AssetType.Texture
})
.then((texture) => {
const sprite = new Sprite(engine, texture);
const modes = [
SpriteFilledMode.Horizontal,
SpriteFilledMode.Vertical,
SpriteFilledMode.Radial90,
SpriteFilledMode.Radial180,
SpriteFilledMode.Radial360
];
const amounts = [0, 0.25, 0.5, 0.75, 1];
modes.forEach((mode, row) => {
amounts.forEach((amount, col) => {
const entity = rootEntity.createChild(`filled-${row}-${col}`);
entity.transform.setPosition((col - 2) * 3, (2 - row) * 3, 0);
const renderer = entity.addComponent(SpriteRenderer);
renderer.sprite = sprite;
renderer.width = 2.4;
renderer.height = 2.4;
renderer.drawMode = SpriteDrawMode.Filled;
renderer.filledMode = mode;
renderer.filledAmount = amount;
});
});
updateForE2E(engine);
initScreenshot(engine, camera);
})
.catch((err) => {
throw new Error(`sprite-filled e2e setup failed: ${String(err)}`);
});
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@e2e/case/sprite-filled.ts` around lines 30 - 63, Replace the external CDN URL
in the resourceManager.load() call with a path to a repo-hosted texture fixture
to ensure test stability. Additionally, add a .catch() rejection handler to the
promise chain (after the existing .then() block) to explicitly handle and log
load failures, so that asset loading errors are properly diagnosed in CI.

9 changes: 9 additions & 0 deletions e2e/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,15 @@ export const E2E_CONFIG = {
diffPercentage: 0.044
}
},
Sprite: {
filled: {
category: "Sprite",
caseFileName: "sprite-filled",
threshold: 0.1,
diffPercentage: 0.3
}
},

UI: {
batchOrder: {
category: "UI",
Expand Down
3 changes: 3 additions & 0 deletions e2e/fixtures/originImage/Sprite_sprite-filled.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading