acbb2d8254
Owner-review follow-up on the Stage 8 branch: - Friend code is copyable (📋 + toast). The lobby notification badge is fixed — it had inherited the hamburger-bar style — into a proper round count dot. - Safari: min-width:0 on flex text inputs (friend code, profile, chat) so they shrink instead of pushing the adjacent button off-screen. - Profile editing is validated on both the UI and the backend: display-name format (letters joined by single space/./_ separators, no leading/trailing/adjacent separators, <=32 runes), a UTC-offset timezone picker (account.ResolveZone parses ±HH:MM or a legacy IANA name), a 10-minute away grid capped at 12h (wrap-aware), and email format; Save is disabled and invalid fields red-bordered until valid. Language stays in Settings. - In a game, an "add to friends" menu item flips to a disabled "request sent"; chat send/nudge became ⬆️/🛎️ icon buttons. - A finished game drops its last-word highlight, hides Check word / Drop game, disables zoom, and draws an inert (greyed) footer instead of hiding it. Tests: account validators (name/away/zone), UI profileValidation, e2e for the finished-game footer/menu and the copy control. Docs (PLAN, ARCHITECTURE, FUNCTIONAL +ru, UI_DESIGN) updated for the display-name rule, UTC-offset timezone and the 12h away window.
85 lines
2.5 KiB
Go
85 lines
2.5 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 special": {"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)
|
|
}
|
|
}
|
|
}
|