Accept final member positions in ownership transactions
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user