From 13d5e99ab90ab872c8cc072a0246348f0d24fa9a Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Mon, 3 Aug 2026 23:56:14 +0200 Subject: mobile: return the day's rank and its localised label --- mobile/mobile_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 mobile/mobile_test.go (limited to 'mobile/mobile_test.go') diff --git a/mobile/mobile_test.go b/mobile/mobile_test.go new file mode 100644 index 0000000..c7df63c --- /dev/null +++ b/mobile/mobile_test.go @@ -0,0 +1,42 @@ +package mobile + +import ( + "encoding/json" + "testing" +) + +func decodeDay(t *testing.T, s string) map[string]any { + t.Helper() + var m map[string]any + if err := json.Unmarshal([]byte(s), &m); err != nil { + t.Fatalf("Day returned invalid JSON: %v\n%s", err, s) + } + return m +} + +func TestDayCarriesLocalisedRank(t *testing.T) { + pl := decodeDay(t, Day("2026-08-01", "of", "vul", "pl")) + if pl["rank"] != "memorial" { + t.Errorf("pl rank = %v, want memorial", pl["rank"]) + } + if pl["rank_label"] != "wspomnienie obowiązkowe" { + t.Errorf("pl rank_label = %v", pl["rank_label"]) + } + en := decodeDay(t, Day("2026-08-01", "of", "vul", "en")) + if en["rank_label"] != "memorial" { + t.Errorf("en rank_label = %v", en["rank_label"]) + } +} + +// The app shows the colour as a swatch and never as a word, so the raw key must +// be present and no localised label may be. This test exists so the app cannot +// quietly start depending on a colour word. +func TestDayHasColourKeyButNoColourLabel(t *testing.T) { + m := decodeDay(t, Day("2026-08-01", "of", "vul", "pl")) + if m["colour"] != "white" { + t.Errorf("colour = %v, want white", m["colour"]) + } + if _, present := m["colour_label"]; present { + t.Error("colour_label must not be returned: the app draws a swatch") + } +} -- cgit v1.3