Files
magpie/internal/gui/panelside_test.go
T
yetone 7033f50722 gui: the panel opens the main window from its edge nearest the tray
isaac_bai on Discord, after v0.1.2857 named the header's icon "Open the
main window": with Windows' taskbar at the bottom, the panel stands above
the tray and its header is the panel's whole height from the icon; the
button left of Quit was where his pointer already was. yogurt36 had asked
for one opener, not two, so the panel still has exactly one, now on the
edge nearest the tray:

- Hung below its icon (the Mac's menu bar, a taskbar or bar at the top)
  it is the header's icon, as before.
- Standing above it (Windows' bottom taskbar, a bottom panel on Linux) it
  is "Open the main window" left of Quit in the foot (#openMain), and the
  header has no icon. The string is the one the icon's name already
  uses, in all five languages.

Which side: once togglePanelNow has placed and shown the panel,
tellPanelSide reads the panel's bounds and its screen's and sends
magpiePanelOpenAt("foot") when the panel is nearer the screen's bottom,
"head" otherwise (panelOpenAt, panelside.go; the Mac is always "head").
Under Wayland a window can't read where the compositor put it, so there,
and until the app says, layout.js sets body[data-open-at] by the system:
"foot" on Windows, "head" elsewhere. CSS shows one of the two from it.

Tests:
- TestPanelOpensTheWindowFromTheEdgeNearestTheTray: Windows bottom/top
  taskbar, a tall panel, a second screen above the first, Linux X11
  bottom/top, Wayland, a screen not read, the Mac, unknown places; only
  "head" or "foot" reach the page.
- TestPanelToldItsSideWhenShown: both show paths in togglePanelNow call
  tellPanelSide after placing; app.js has magpiePanelOpenAt.
- panel-open-once.test.cjs, Chromium and WebKit x en/zh/zh-TW/ja/de:
  on a Mac platform exactly one opener, the header's, named per
  language, opening /api/window/main, foot ["profBtn","quit"]; told
  "foot" it moves. On Win32 exactly one opener, the foot's, left of Quit
  (["profBtn","openMain","quit"]), the foot's buttons fitting apart with
  their words whole at 360px, opening /api/window/main; told "head" it
  moves back; an unknown side changes nothing.

Run on mote via mote-run:
- At this head (rebased on 8468afecb): go test ./internal/gui -run
  'TestPanel|TestTrayDouble|Budget|I18n|Asset': ok; node --test
  panel-open-once, i18n-keys, window-no-footer, panel-profiles,
  quit-ask-setting, gui-de, gui-ja, gui-zh-tw: 165 of 165 pass.
- At the same change rebased on f168dd278 (main's 8 commits since are
  Library, Routing, browser and Codex-subagent work, none in the
  panel's header or foot): the 127 GUI files that load
  mode=panel or touch the foot, Quit, i18n or a budget, both engines,
  6 at a time: 2112 of 2136 pass. The 24 reds are in 7 other files; run
  again 2 at a time, 16 stay red at this change and 17 at origin/main
  1e1068c86, the same tests: usage-fold, tray-cell-click and
  codex-auto-reset webkit de (#4790), remote-magpie (#4398), and one
  provider-mask case (filed #5109); account-mask (#3951) and
  quota-curve (#4768) went green on the second run.
- At this head: wsl-run go vet -tags gtk3 ./internal/gui: ok
- win-run go vet ./internal/gui: ok; win-run go test -run
  'TestPanelOpens|TestPanelToldItsSide|TestTrayDouble' ./internal/gui: ok
- gofmt -l internal/gui: empty

Broken by hand (in a copy): panelOpenAt always "head" plus the page's
default and magpiePanelOpenAt doing nothing: the Go test red on 5 cases,
panel-open-once 20 of 20 red. Only the CSS rule that hides the header's
icon at the foot dropped: panel-open-once red (two openers shown).

Not tried: a real Windows tray with the taskbar at the bottom or the top,
or a Linux X11 bottom panel; the bounds Wails reports there are read from
its source (positionWindow, the screen's Bounds), not seen. The whole GUI
suite (1175 files) was not run: mote was at load ~55-100 from other
sessions' suites.
2026-11-04 00:22:54 +08:00

71 lines
2.9 KiB
Go

package gui
import (
"os"
"regexp"
"strings"
"testing"
)
// The panel opens the main window from its edge nearest the tray: the
// foot above a bottom taskbar, the header below a top one (isaac_bai).
func TestPanelOpensTheWindowFromTheEdgeNearestTheTray(t *testing.T) {
screen := panelRect{0, 0, 1920, 1080}
for _, c := range []struct {
name string
goos string
panel panelRect
screen panelRect
known bool
want string
}{
{"Windows, taskbar at the bottom", "windows", panelRect{1540, 520, 360, 520}, screen, true, "foot"},
{"Windows, taskbar at the top", "windows", panelRect{1540, 48, 360, 520}, screen, true, "head"},
{"Windows, a tall panel nearer the bottom", "windows", panelRect{1540, 100, 360, 932}, screen, true, "foot"},
{"Windows, second screen above the first, taskbar at its bottom", "windows", panelRect{1540, -560, 360, 520}, panelRect{0, -1080, 1920, 1080}, true, "foot"},
{"Windows, place unknown", "windows", panelRect{}, panelRect{}, false, "foot"},
{"Linux X11, bottom panel", "linux", panelRect{1500, 520, 360, 520}, screen, true, "foot"},
{"Linux X11, top bar", "linux", panelRect{1500, 32, 360, 520}, screen, true, "head"},
{"Linux Wayland, place unknown", "linux", panelRect{0, 0, 360, 520}, screen, false, "head"},
{"Linux, screen not read", "linux", panelRect{1500, 520, 360, 520}, panelRect{}, true, "head"},
{"Mac menu bar", "darwin", panelRect{1500, 30, 360, 520}, screen, true, "head"},
{"Mac, place unknown", "darwin", panelRect{}, panelRect{}, false, "head"},
} {
if got := panelOpenAt(c.goos, c.panel, c.screen, c.known); got != c.want {
t.Errorf("%s: %q, want %q", c.name, got, c.want)
}
}
if js := panelOpenAtJS("foot"); !strings.Contains(js, `magpiePanelOpenAt("foot")`) {
t.Errorf("foot: %s", js)
}
if js := panelOpenAtJS(`x");alert(1);("`); !strings.Contains(js, `magpiePanelOpenAt("head")`) {
t.Errorf("only head or foot reach the page: %s", js)
}
}
// Each way the tray shows the panel tells it its side once it is placed,
// and the page has the function that hears it.
func TestPanelToldItsSideWhenShown(t *testing.T) {
src, err := os.ReadFile("app.go")
if err != nil {
t.Fatal(err)
}
body := regexp.MustCompile(`(?s)func \(h \*host\) togglePanelNow\(\) \{.*?\n\}\n`).Find(src)
if body == nil {
t.Fatal("togglePanelNow not found")
}
if !regexp.MustCompile(`(?s)PositionWindow\(h\.panel, 6\)\s*showWebview\(h\.panel\)\.Focus\(\)\s*h\.tellPanelSide\(\)\s*return`).Match(body) {
t.Error("the Mac's panel isn't told its side after it is placed")
}
if !regexp.MustCompile(`(?s)h\.tray\.ToggleWindow\(\)\s*if h\.panel\.IsVisible\(\) \{\s*h\.tellPanelSide\(\)`).Match(body) {
t.Error("the panel shown by ToggleWindow isn't told its side")
}
page, err := os.ReadFile("assets/app.js")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(page), "window.magpiePanelOpenAt = (side)") {
t.Error("app.js has no magpiePanelOpenAt")
}
}