fix(POSTV1-editor): 修复多选拖动与底图调整
Dada P0-A isolated Windows CI / validate-and-package (push) Waiting to run

This commit is contained in:
suyx
2026-08-06 10:53:38 +08:00
parent 51d613f459
commit 83fe57f319
8 changed files with 310 additions and 14 deletions
+32
View File
@@ -1,8 +1,11 @@
import { describe, expect, it } from "vitest";
import {
adjustBackgroundPixels,
backgroundDrawPlan,
CanvasEditHistory,
createEditorCanvasState,
cssFilterForBackground,
defaultBackgroundAdjustments,
deserializeFabricCanvas,
switchBackground,
@@ -24,6 +27,35 @@ const element = {
};
describe("TDD-WP4-BG-001/002 canvas boundary", () => {
it("builds valid filters and distinct contain/crop draw plans", () => {
const adjustments = { ...defaultBackgroundAdjustments(), brightness: 25, contrast: 15, saturation: -20 };
expect(cssFilterForBackground(adjustments)).toBe("brightness(125%) contrast(115%) saturate(80%)");
expect(cssFilterForBackground(defaultBackgroundAdjustments())).toBe("none");
expect(backgroundDrawPlan({ height: 200, width: 400 }, { height: 100, width: 100 }, { ...adjustments, fit: "fit" })).toEqual({
destination: { height: 50, width: 100, x: 0, y: 25 },
source: { height: 200, width: 400, x: 0, y: 0 },
});
expect(backgroundDrawPlan({ height: 200, width: 400 }, { height: 100, width: 100 }, { ...adjustments, fit: "crop" })).toEqual({
destination: { height: 100, width: 100, x: 0, y: 0 },
source: { height: 200, width: 200, x: 100, y: 0 },
});
});
it("changes pixels for temperature and sharpness without changing alpha", () => {
const flat = new Uint8ClampedArray([100, 100, 100, 255]);
expect([...adjustBackgroundPixels(flat, 1, 1, { sharpness: 0, temperature: 100 })]).toEqual([135, 108, 65, 255]);
const edged = new Uint8ClampedArray([
100, 100, 100, 255, 100, 100, 100, 255, 100, 100, 100, 255,
100, 100, 100, 255, 180, 180, 180, 255, 100, 100, 100, 255,
100, 100, 100, 255, 100, 100, 100, 255, 100, 100, 100, 255,
]);
const sharpened = adjustBackgroundPixels(edged, 3, 3, { sharpness: 100, temperature: 0 });
expect(sharpened[16]).toBe(255);
expect(sharpened[19]).toBe(255);
});
it("switches background without moving overlays, resets processing, and re-extracts palette", () => {
const initial = createEditorCanvasState({ assetId: "00000000-0000-4000-8000-000000000010", ratio: "3:4" });
const withOverlay = { ...initial, background: { ...initial.background, adjustments: { ...initial.background.adjustments, brightness: 42, filter: "mono" } }, elements: [element] };