52 lines
1.9 KiB
Go
52 lines
1.9 KiB
Go
// 成员拖放纯文档回归,复用子图 fixture 验证来源坐标只转换一次。
|
|
package platform
|
|
|
|
import (
|
|
"encoding/json"
|
|
"math"
|
|
"testing"
|
|
)
|
|
|
|
// TestMemberDropPositions 先更新来源局部位置,再执行跨子图移动,断言目标坐标为 (140,250)。
|
|
// 另覆盖缺失成员、不匹配 ID 集合、非有限/越界坐标及缺字段或 null 的严格解码。
|
|
func TestMemberDropPositions(t *testing.T) {
|
|
raw := memberFixture(t)
|
|
source := "11111111-1111-4111-8111-111111111111"
|
|
target := "22222222-2222-4222-8222-222222222222"
|
|
original := string(raw[source])
|
|
positions := map[string]memberDropPosition{"a": {X: 40, Y: 50}}
|
|
positioned, err := positionMemberDrop(raw[source], positions)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
raw[source] = positioned
|
|
moved, err := moveMembersDocuments("parent", source, target, []string{"a"}, raw)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pos := canvasNodesByID(moved[target])["a"]["position"].(map[string]any)
|
|
if pos["x"] != float64(140) || pos["y"] != float64(250) {
|
|
t.Fatalf("final drop position %v", pos)
|
|
}
|
|
if original == string(positioned) {
|
|
t.Fatal("position not applied")
|
|
}
|
|
if _, err := positionMemberDrop(positioned, map[string]memberDropPosition{"missing": {}}); err == nil {
|
|
t.Fatal("missing member accepted")
|
|
}
|
|
if !validMemberDropPositions([]string{"a"}, nil) || !validMemberDropPositions([]string{"a"}, positions) {
|
|
t.Fatal("valid positions rejected")
|
|
}
|
|
for _, bad := range []map[string]memberDropPosition{{}, {"other": {}}, {"a": {X: 1e6 + 1}}, {"a": {Y: math.NaN()}}, {"a": {X: math.Inf(1)}}} {
|
|
if validMemberDropPositions([]string{"a"}, bad) {
|
|
t.Fatalf("bad positions accepted %v", bad)
|
|
}
|
|
}
|
|
for _, bad := range []string{`{"x":1}`, `{"x":null,"y":1}`, `{"x":1,"y":2,"z":3}`} {
|
|
var p memberDropPosition
|
|
if json.Unmarshal([]byte(bad), &p) == nil {
|
|
t.Fatal("malformed position accepted")
|
|
}
|
|
}
|
|
}
|