fix(09): WR-07 keep relation column order from the YAML itself, not a fixed indentation

This commit is contained in:
Jakub Zych
2026-10-01 21:10:09 +02:00
parent 889250c8fb
commit b026aec162
3 changed files with 80 additions and 22 deletions

View File

@@ -115,6 +115,77 @@ func TestRelationDefaultSort(t *testing.T) {
}
}
// TestRelationColumnOrderIsIndependentOfIndentation pins WR-07: column order
// is the file's order in each panel, whatever the indentation, and the view and
// manage panels do not share one order.
func TestRelationColumnOrderIsIndependentOfIndentation(t *testing.T) {
const twoSpace = `editors:
label: demo.editors
view:
list:
columns:
username:
label: demo.username
email:
label: demo.email
toolbarButtons: link|unlink
manage:
list:
columns:
username:
label: demo.username
email:
label: demo.email
`
for name, yamlText := range map[string]string{"two-space": twoSpace, "four-space": validRelationYAML} {
t.Run(name, func(t *testing.T) {
ctl := relationTestController{}
fsys := relationTestFS(yamlText)
form, err := CompileForm("acme.demo", ctl, fsys)
if err != nil {
t.Fatal(err)
}
relations, err := compileRelations("acme.demo", ctl, fsys, form)
if err != nil {
t.Fatal(err)
}
schema := relations["editors"].Schema
for panel, cols := range map[string][]RelationColumn{"view": schema.View.List.Columns, "manage": schema.Manage.List.Columns} {
if len(cols) != 2 || cols[0].Key != "username" || cols[1].Key != "email" {
t.Fatalf("%s columns = %+v, want username then email (file order, not alphabetical)", panel, cols)
}
}
})
}
const reversed = `editors:
view:
list:
columns:
username: {label: demo.username}
email: {label: demo.email}
manage:
list:
columns:
email: {label: demo.email}
username: {label: demo.username}
`
ctl := relationTestController{}
fsys := relationTestFS(reversed)
form, err := CompileForm("acme.demo", ctl, fsys)
if err != nil {
t.Fatal(err)
}
relations, err := compileRelations("acme.demo", ctl, fsys, form)
if err != nil {
t.Fatal(err)
}
schema := relations["editors"].Schema
if v, m := schema.View.List.Columns, schema.Manage.List.Columns; v[0].Key != "username" || m[0].Key != "email" {
t.Fatalf("view=%+v manage=%+v, want each panel in its own file order", v, m)
}
}
func TestRelationCandidateExclusions(t *testing.T) {
contract := relationTestController{}.AdminRelationContracts()[0]
ids, err := contract.ExcludedRelatedIDs(&relationTestOwner{OwnerID: 41})