Files
summercms/modules/cabana/locale_order_test.go
Jakub Zych bd8626e5fc fix(cabana): send the default content locale first in enabledLocales
- enabledContentLocales moves TranslationWriter.DefaultLocale to index 0
  and keeps the other enabled codes in the writer's order
- every ML control opens on enabledLocales[0], so the form now shows the
  host-column values (content, excerpt, title, slug) instead of an empty
  non-default locale
- a DefaultLocale error is logged and keeps the writer's order
- README and forms docs: default locale first
2026-10-09 20:58:12 +02:00

28 lines
838 B
Go

package cabana
import (
"context"
"slices"
"testing"
"git.golem15.com/golem15/summercms/modules/backpack"
)
// TestEnabledLocalesDefaultFirstSmoke pins D-03: the form schema lists the
// default locale first, so every ML control opens on the locale whose values
// live in the host columns, whatever order the writer keeps.
func TestEnabledLocalesDefaultFirstSmoke(t *testing.T) {
db, _ := openDryRunDB(t)
app := backpack.New(nil)
if err := app.Publish(db); err != nil {
t.Fatal(err)
}
if err := app.Publish[TranslationWriter](&recordingWriter{defaultLocale: "pl", enabled: []string{"en", "pl"}}); err != nil {
t.Fatal(err)
}
svc := &service{app: app}
if got := svc.enabledContentLocales(context.Background()); !slices.Equal(got, []string{"pl", "en"}) {
t.Fatalf("enabledContentLocales = %v, want [pl en]", got)
}
}