Files
RenewCMS/test/localization_ordering_domain_test.go
T

51 lines
1.4 KiB
Go

package test
import (
"RenewCMS/internal/domain/localization"
"reflect"
"testing"
)
func TestLocalizationCompareTags(t *testing.T) {
examples := []struct {
name string
left string
right string
want int
}{
{"same tag", "fr", "fr", 0},
{"same default tag", "en", "en", 0},
{"default first", "en", "de", -1},
{"default last argument", "de", "en", 1},
{"alphabetical before", "de", "fr", -1},
{"alphabetical after", "fr", "de", 1},
}
for _, example := range examples {
t.Run(example.name, func(t *testing.T) {
if got := localization.CompareTags("en", example.left, example.right); got != example.want {
t.Errorf("CompareTags(%q, %q) = %d, want %d", example.left, example.right, got, example.want)
}
})
}
}
func TestLocalizationBuildViewOrdersDefaultThenEnabledThenTag(t *testing.T) {
rows := []localization.Row{
{Tag: "pt", Enabled: false, Confirmed: true},
{Tag: "fr", Enabled: true, Confirmed: true},
{Tag: "es", Enabled: false, Confirmed: true},
{Tag: "en", IsDefault: true, Enabled: true, Confirmed: true},
{Tag: "de", Enabled: true, Confirmed: true},
}
view := localization.BuildView(rows, map[string]localization.VersionCount{}, nil)
order := []string{}
for _, language := range view.Languages {
order = append(order, language.Lang)
}
if want := []string{"en", "de", "fr", "es", "pt"}; !reflect.DeepEqual(order, want) {
t.Errorf("order = %v, want %v", order, want)
}
}