Files
magpie/internal/gui/trayidle_test.go
T
yetone eb779ce92a gui: the tray icon's tooltip is in magpie's language (yi_time)
yi_time in #feedback: magpie set to Chinese on Windows, and the tray
icon's hover tooltip said "Today: 121K tokens (2.9K in · 180 out ·
118K cached)" and "3 requests" in English. The tray menu already
followed magpie's language (trayLang, #301); the tooltip's words were
hard-coded English in trayusage.go.

Now every tooltip is in trayLang(settings.Lang, systemLang), on
Windows, macOS and Linux alike. That covers trayIdleTip, magpie's
totals (trayTotalCard), and each subscription card (trayCardText: its
use or what is left, the pace, when it resets, until's d/h/m, "as of
…"). The words are in trayWords beside the menu's, for zh, zh-TW, ja
and de; English stays the key and the fallback. A window's name and an
error are still the card's own. A change of language in Settings now
also refreshes the tooltip (onTrayUsage); before, only the menu was
relabelled. The test-only trayUsageText and trayUsageView stay in
English, so the existing tests keep their strings.

Test: TestTrayTooltipFollowsMagpiesLanguage.
- yi_time's own numbers in zh: "magpie\n今天:121K token(输入 2.9K ·
  输出 180 · 缓存 118K)\n3 个请求".
- The same numbers in en are unchanged.
- Covers the total card and a card's used, left, reset and as-of.
- For zh, zh-TW, ja and de, no English word in the idle, totals, card
  (with pace) or combined tooltips.

Run at this head (rebased on 5573f7923):
- mote: gofmt -l clean; CGO_ENABLED=0 GOOS=linux go vet -tags nogui
  and GOOS=windows go vet of ./internal/gui ok.
- mote: go test ./internal/gui. Everything passes except
  TestMainWindowCorners/macOS_26_SDK, which is #3949 (red on mote's
  macOS 27, not touched here).
- Windows (xiaomi-gpu, win-run): go test -run Tray ./internal/gui ok.

Broken by hand: with the tooltip words taken out of trayWords, the
test goes red. Its zh output is then exactly the old English tooltip.

Not tried:
- The real tray on Windows, hovering the icon.
- The watch loop's choice of language has no test of its own. Passing
  "en" there would not go red.
2026-11-03 10:14:23 +08:00

34 lines
1.3 KiB
Go

package gui
import (
"testing"
"github.com/yetone/magpie/internal/usage"
)
// ylorn on Discord: with no cards in the menu bar the tooltip said only
// "magpie". It says magpie over today's total: every token, split into
// input, output and cache (NextCommit on Discord), then the cost in
// Settings' currency ("+" when some calls had no price, none when none had
// one) and the requests.
func TestTrayIdleTip(t *testing.T) {
for _, c := range []struct {
t usage.Totals
want string
}{
{usage.Totals{Calls: 152, Input: 912_000, Output: 318_400, CacheRead: 4_900_000, CacheWrite: 200_000, Cost: 3.4, Unpriced: 2},
"magpie\nToday: 6.3M tokens (912K in · 318K out · 5.1M cached)\n≈$3.40+ · 152 requests"},
{usage.Totals{Calls: 1, Input: 950, Output: 50},
"magpie\nToday: 1.0K tokens (950 in · 50 out)\n1 request"},
{usage.Totals{}, "magpie\nToday: no requests yet"},
} {
if got := trayIdleTip("en", c.t, "usd", 0); got != c.want {
t.Errorf("trayIdleTip(%+v) =\n%q, want\n%q", c.t, got, c.want)
}
}
// waybar reads the title as Pango markup: still safe after sniTip
if got := sniTip(trayIdleTip("en", usage.Totals{Calls: 3, Input: 10, Cost: 2}, "usd", 0)); got != "magpie\nToday: 10 tokens (10 in · 0 out)\n≈$2.00 · 3 requests" {
t.Errorf("sniTip: %q", got)
}
}