oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1//go:build webkit
2
3package thintest
4
5import (
6 "encoding/json"
7 "math"
8 "os"
9 "os/exec"
10 "testing"
11)
12
13type keyboardSpot struct {
14 VVTop, VVBottom, ScrollY float64
15 ComposerTop, ComposerBottom *float64
16 LastTop, LastBottom *float64
17}
18
19// TestWebKitKeyboard: Paul, staging f2eac36, Safari on an iPhone: the
20// composer jumped to the top of the screen when the keyboard opened. In
21// WebKit at 390x844 with the keyboard simulated as Safari does it (the
22// visual viewport shrinks to 450 and pans down; the layout viewport
23// stays), the chat's composer sits on the keyboard (its bottom on the
24// visual viewport's), well below the status bar, the newest message just
25// above it, and back at the bottom when the keyboard closes. The empty
26// conversation and the task thread's composer too. Needs
27// EQUIPO_PLAYWRIGHT_CORE (a playwright-core directory with its WebKit).
28func TestWebKitKeyboard(t *testing.T) {
29 core := os.Getenv("EQUIPO_PLAYWRIGHT_CORE")
30 if core == "" {
31 t.Skip("EQUIPO_PLAYWRIGHT_CORE is not set")
32 }
33 g := newGallery(t)
34 owner, member := g.a.inst.Cookie(), g.a.memberCookie()
35 type pageCfg struct {
36 Name string `json:"name"`
37 Path string `json:"path"`
38 Selector string `json:"selector"`
39 Scheme string `json:"scheme"`
40 Cookie map[string]string `json:"cookie"`
41 ScrollToComposer bool `json:"scrollToComposer"`
42 }
43 ck := func(name, value string) map[string]string { return map[string]string{"name": name, "value": value} }
44 pages := []pageCfg{
45 {Name: "chat", Path: "/conversation", Selector: "#chat-composer", Cookie: ck(owner.Name, owner.Value)},
46 {Name: "chat-dark", Path: "/conversation", Selector: "#chat-composer", Scheme: "dark", Cookie: ck(owner.Name, owner.Value)},
47 {Name: "empty", Path: "/conversation", Selector: "#chat-composer", Cookie: ck(member.Name, member.Value)},
48 {Name: "task", Path: "/tasks/" + g.unchecked, Selector: "#chat-composer", Cookie: ck(owner.Name, owner.Value), ScrollToComposer: true},
49 }
50 when := os.Getenv("EQUIPO_KEYBOARD_WHEN")
51 if when == "" {
52 when = "after"
53 }
54 raw, _ := json.Marshal(map[string]any{"base": g.a.inst.URL, "pages": pages, "art": os.Getenv("EQUIPO_BROWSER_ARTIFACTS"), "when": when})
55 cmd := exec.Command("node", "testdata/keyboard.mjs")
56 cmd.Env = append(os.Environ(), "EQUIPO_KEYBOARD="+string(raw))
57 cmd.Stderr = os.Stderr
58 got, err := cmd.Output()
59 if err != nil {
60 t.Fatalf("webkit: %v", err)
61 }
62 var res map[string]map[string]keyboardSpot
63 if err := json.Unmarshal(got, &res); err != nil {
64 t.Fatalf("webkit output %q: %v", got, err)
65 }
66 near := func(a, b float64) bool { return math.Abs(a-b) <= 2 }
67 for _, name := range []string{"chat", "chat-dark", "empty"} {
68 for _, state := range []string{"closed", "open", "reclosed"} {
69 s := res[name][state]
70 if s.ComposerBottom == nil {
71 t.Fatalf("%s %s: no composer", name, state)
72 }
73 if !near(*s.ComposerBottom, s.VVBottom) {
74 t.Fatalf("%s %s: composer bottom %.1f, visual viewport bottom %.1f (%+v)", name, state, *s.ComposerBottom, s.VVBottom, s)
75 }
76 // Below the status bar: well into the visible area, never at its top.
77 if *s.ComposerTop < s.VVTop+200 {
78 t.Fatalf("%s %s: composer top %.1f at the top of the visible area from %.1f", name, state, *s.ComposerTop, s.VVTop)
79 }
80 if name != "empty" && s.LastBottom != nil && (*s.LastBottom > *s.ComposerTop+1 || *s.LastBottom < *s.ComposerTop-160 || *s.LastBottom < s.VVTop) {
81 t.Fatalf("%s %s: newest message %.1f..%.1f not just above the composer at %.1f", name, state, *s.LastTop, *s.LastBottom, *s.ComposerTop)
82 }
83 }
84 }
85 // The task thread's composer is in the page's flow: with Safari's pan it
86 // stays where the focused field is, inside the visible area.
87 for _, state := range []string{"closed", "open"} {
88 s := res["task"][state]
89 if s.ComposerBottom == nil || *s.ComposerBottom > s.VVBottom+2 || *s.ComposerTop < s.VVTop-2 {
90 t.Fatalf("task %s: composer %v..%v outside %.1f..%.1f", state, s.ComposerTop, s.ComposerBottom, s.VVTop, s.VVBottom)
91 }
92 }
93}
94