b15fd30c4f
CI / changes (pull_request) Successful in 1s
CI / unit (pull_request) Successful in 8s
CI / integration (pull_request) Successful in 12s
CI / ui (pull_request) Successful in 27s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m6s
- #4 bag label: '{n} in the bag' / 'Bag is empty' (was 'Bag {n}') - #6 allow a single trailing dot in display names (backend + UI regex + tests) - #1 double-tap zooms toward the tapped cell, not the top-left - #8 shuffle fires a short multi-pulse haptic - #11 highlighted/flashing tiles darken their bottom edge too (shadow joins the flash) - #13 toast slides up from the bottom and fades out - #7 hide the logout button (kept wired behind `hidden`) - #16 admin game seats: left-align numeric columns, clarify the 'Hints used' header
87 lines
2.7 KiB
Go
87 lines
2.7 KiB
Go
package account
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestValidateDisplayName(t *testing.T) {
|
|
cases := map[string]struct {
|
|
in string
|
|
want string
|
|
ok bool
|
|
}{
|
|
"plain": {"Kaya", "Kaya", true},
|
|
"cyrillic": {"Кая", "Кая", true},
|
|
"dot underscore mix": {"Name_P. Last", "Name_P. Last", true},
|
|
"single dot": {"Mr.Smith", "Mr.Smith", true},
|
|
"dot then space": {"Mr. Smith", "Mr. Smith", true},
|
|
"trim surrounding": {" Kaya ", "Kaya", true},
|
|
"adjacent specials": {"Name P._Last", "", false},
|
|
"two spaces": {"Name Last", "", false},
|
|
"leading special": {"_Name", "", false},
|
|
"trailing underscore": {"Name_", "", false},
|
|
"trailing dot ok": {"Anna B.", "Anna B.", true},
|
|
"double trailing dot": {"Name..", "", false},
|
|
"digit rejected": {"Name2", "", false},
|
|
"blank": {" ", "", false},
|
|
"too long": {strings.Repeat("a", 33), "", false},
|
|
}
|
|
for name, tc := range cases {
|
|
t.Run(name, func(t *testing.T) {
|
|
got, err := ValidateDisplayName(tc.in)
|
|
if tc.ok != (err == nil) || (tc.ok && got != tc.want) {
|
|
t.Fatalf("ValidateDisplayName(%q) = (%q, err=%v), want (%q, ok=%v)", tc.in, got, err, tc.want, tc.ok)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestValidateAwayWindow(t *testing.T) {
|
|
hm := func(h, m int) time.Time { return time.Date(0, 1, 1, h, m, 0, 0, time.UTC) }
|
|
cases := map[string]struct {
|
|
start, end time.Time
|
|
ok bool
|
|
}{
|
|
"8h overnight": {hm(22, 0), hm(6, 0), true},
|
|
"12h exact": {hm(0, 0), hm(12, 0), true},
|
|
"13h daytime": {hm(8, 0), hm(21, 0), false},
|
|
"zero window": {hm(7, 0), hm(7, 0), true},
|
|
"13h wrap": {hm(20, 0), hm(9, 0), false},
|
|
}
|
|
for name, tc := range cases {
|
|
t.Run(name, func(t *testing.T) {
|
|
if err := validateAwayWindow(tc.start, tc.end); tc.ok != (err == nil) {
|
|
t.Fatalf("validateAwayWindow = %v, want ok=%v", err, tc.ok)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestResolveAndValidZone(t *testing.T) {
|
|
offsetOf := func(name string) int {
|
|
_, off := time.Date(2024, 1, 1, 12, 0, 0, 0, ResolveZone(name)).Zone()
|
|
return off
|
|
}
|
|
if got := offsetOf("+03:00"); got != 3*3600 {
|
|
t.Errorf("+03:00 offset = %d, want 10800", got)
|
|
}
|
|
if got := offsetOf("-05:30"); got != -(5*3600 + 30*60) {
|
|
t.Errorf("-05:30 offset = %d", got)
|
|
}
|
|
if ResolveZone("nonsense-zone") != time.UTC {
|
|
t.Error("unknown zone should resolve to UTC")
|
|
}
|
|
for _, ok := range []string{"+05:45", "-12:00", "+14:00", "Europe/Moscow", "UTC"} {
|
|
if !validZone(ok) {
|
|
t.Errorf("validZone(%q) = false, want true", ok)
|
|
}
|
|
}
|
|
for _, bad := range []string{"+15:00", "03:00", "+3:00", "nope", "+05:99"} {
|
|
if validZone(bad) {
|
|
t.Errorf("validZone(%q) = true, want false", bad)
|
|
}
|
|
}
|
|
}
|