Files
magpie/internal/gui/mainwindow_test.go
T
yetone d3191a51c8 gui: with Hide accounts on, an account's eye shows that one account in this window (yogurt36)
yogurt36 on Discord, for a screen share: with Hide accounts on, one
account should be readable while the others stay masked. Now an
account's name on the provider editor's row (accountNameButton and the
one-account line) and on its Usage card (quotaWho) has a quiet eye, in
sight on hover or keyboard focus, with an aria-label. A click shows
that account, its address and the name the user gave it together
(kin), everywhere the window draws it, tooltips included: the shown
set is skipped in hits(), which every mask goes through. It lives in
memory only. The tray panel keeps hiding it, and closing the window
hides it again: the page stays loaded while the window is hidden, so
hideMain runs mainClosedJS (hideAccounts.closed) first. With Hide
accounts off there is no eye. Strings in zh, zh-TW, ja and de.

Run (macOS, playwright 1.62.0, rebased on 630fd1d69; at push 0f6615ffc, site only, came under it):
- account-eye.test.cjs: 20/20 in chromium and webkit, en zh zh-TW ja
  de, 900px and 360px (no select, no stripe, no sideways scroll, a
  click scrolls nothing, Tab (Alt+Tab in WebKit) reaches the eye).
- Red on the old code (feature stashed): both tests fail.
- Broken by hand, each red, then restored: the shown check in hits();
  closed() without shown.clear(); kin() returning only the address.
- TestClosingHidesShownAccounts (new): red without shown.clear() and
  without the ExecJS(mainClosedJS) call in hideMain.
- go test -run 'TestCoreScriptBudget|TestBuiltinClientsLoaded|
  TestClosingHidesShownAccounts' ./internal/gui: ok. app.js
  1,306,355 bytes, under 1,321,319; budgets not raised.
- i18n-keys.test.cjs: 4/4.
- gofmt -l clean; go vet (mac), GOOS=linux go vet -tags nogui,
  GOOS=windows go vet ./internal/gui; go build, GOOS=linux go build
  -tags nogui, GOOS=windows go build: ok.

After the last rebase one chromium en/zh run of account-eye showed 1
fail of 4 with 179MiB free on the disk; its log wasn't kept, so the
test is unnamed. Every run since, with its log kept, passed: 4/4 and
then 20/20 in both engines.

Not run: the whole GUI suite and the full go test ./internal/gui
(another session's suite held the machine and the disk was full; one
link hit ENOSPC and passed on retry). They run after the push.
Not tried: the real Wails window's close (hideMain) by hand.
2026-10-26 18:18:24 +08:00

116 lines
4.0 KiB
Go

//go:build !nogui
package gui
import (
"os"
"strings"
"testing"
"github.com/wailsapp/wails/v3/pkg/application"
"github.com/yetone/magpie/internal/settings"
)
// StringKe on Discord: magpie restarted for an update while another app was
// full screen, and from then on its window opened only on that app's Space.
// The window moves to the Space the user is on when shown, and can still go
// full screen; it doesn't join every Space.
func TestMainWindowFollowsActiveSpace(t *testing.T) {
m := mainMacWindow()
b := m.CollectionBehavior
if b&application.MacWindowCollectionBehaviorMoveToActiveSpace == 0 {
t.Errorf("main window collection behaviour %d does not move to the active Space", b)
}
if b&application.MacWindowCollectionBehaviorFullScreenPrimary == 0 {
t.Errorf("main window collection behaviour %d can no longer go full screen", b)
}
if b&(application.MacWindowCollectionBehaviorCanJoinAllSpaces|application.MacWindowCollectionBehaviorFullScreenAuxiliary) != 0 {
t.Errorf("main window collection behaviour %d joins all Spaces or full-screen ones", b)
}
if m.TitleBar != application.MacTitleBarHiddenInset {
t.Errorf("main window title bar changed: %+v", m.TitleBar)
}
}
// StringKe on Discord: a full-screen window closed left a black Space
// behind. On the Mac it leaves full screen before it is hidden.
func TestCloseStepLeavesFullscreen(t *testing.T) {
cases := []struct {
goos string
fullscreen bool
want closeAction
}{
{"darwin", true, closeLeaveFullscreen},
{"darwin", false, closeHide},
{"windows", true, closeHide},
{"linux", true, closeHide},
{"linux", false, closeHide},
}
for _, c := range cases {
if got := closeStep(c.goos, c.fullscreen); got != c.want {
t.Errorf("closeStep(%s, fullscreen=%v) = %v, want %v", c.goos, c.fullscreen, got, c.want)
}
}
}
// lainbo on v0.1.819 (#763): with the Dock set to hidden, a full-screen window
// had no close, minimise or full-screen buttons, and only Esc took it out of
// full screen. A full-screen window keeps magpie in the Dock, whatever the setting.
func TestFullscreenKeepsDock(t *testing.T) {
hidden, window, shown := settings.Settings{}, settings.Settings{DockWindow: true}, settings.Settings{Dock: true}
cases := []struct {
s settings.Settings
shown, fullscreen bool
want bool
}{
{hidden, true, true, true},
{hidden, true, false, false},
{hidden, false, false, false},
{window, true, true, true},
{window, true, false, true},
{window, false, false, false},
{shown, false, false, true},
}
for _, c := range cases {
if got := inDock(c.s, c.shown, c.fullscreen); got != c.want {
t.Errorf("inDock(%+v, shown=%v, fullscreen=%v) = %v, want %v", c.s, c.shown, c.fullscreen, got, c.want)
}
}
}
// yogurt36 on Discord: an account shown by its eye while Hide accounts is on
// is shown for the window's session only. Closing the window only hides it,
// so hideMain tells the page; the call it makes is one app.js answers, and
// what answers it forgets every account shown.
func TestClosingHidesShownAccounts(t *testing.T) {
if mainClosedJS != "window.hideAccounts?.closed?.()" {
t.Fatalf("hideMain runs %q", mainClosedJS)
}
src, err := os.ReadFile("mainwindow.go")
if err != nil {
t.Fatal(err)
}
_, hide, _ := strings.Cut(string(src), "func (h *host) hideMain() {")
hide, _, _ = strings.Cut(hide, "\n}\n")
if i, j := strings.Index(hide, "h.main.ExecJS(mainClosedJS)"), strings.Index(hide, "h.main.Hide()"); i < 0 || j < i {
t.Fatalf("hideMain doesn't tell the page before it hides the window:%s", hide)
}
js, err := os.ReadFile("assets/app.js")
if err != nil {
t.Fatal(err)
}
_, fn, ok := strings.Cut(string(js), "window.hideAccounts = {")
if !ok {
t.Fatal("app.js has no window.hideAccounts")
}
_, fn, ok = strings.Cut(fn, "\n closed: () => {")
if !ok {
t.Fatal("window.hideAccounts has no closed")
}
fn, _, _ = strings.Cut(fn, "\n")
if !strings.Contains(fn, "shown.clear()") {
t.Fatalf("closed forgets no shown account: %q", fn)
}
}