| 1 | //go:build browser |
| 2 | |
| 3 | package plan3test |
| 4 | |
| 5 | import ( |
| 6 | "amadan.net/oficina/equipo/internal/testci" |
| 7 | "amadan.net/rastrillo/rastrillo/harness" |
| 8 | "context" |
| 9 | "github.com/chromedp/cdproto/cdp" |
| 10 | "github.com/chromedp/cdproto/emulation" |
| 11 | "github.com/chromedp/cdproto/network" |
| 12 | "github.com/chromedp/chromedp" |
| 13 | "net/http" |
| 14 | "os" |
| 15 | "os/exec" |
| 16 | "strings" |
| 17 | "testing" |
| 18 | "time" |
| 19 | ) |
| 20 | |
| 21 | func TestTeamsHierarchyBrowser(t *testing.T) { |
| 22 | // The browser harness.ChromePath finds: RASTRILLO_CHROME (the CI box |
| 23 | // sets it to its pinned Chromium), or one on PATH. |
| 24 | found := os.Getenv("RASTRILLO_CHROME") != "" |
| 25 | for _, name := range []string{"chromium", "chromium-browser", "google-chrome", "google-chrome-stable"} { |
| 26 | if _, err := exec.LookPath(name); err == nil { |
| 27 | found = true |
| 28 | break |
| 29 | } |
| 30 | } |
| 31 | if !found { |
| 32 | testci.Absent(t, "Chrome/Chromium binary unavailable; scriptless Teams hierarchy needs the chromedp fixture") |
| 33 | } |
| 34 | f := newFixture(t) |
| 35 | task := f.createTask(t) |
| 36 | if body := f.get(t, owner, "/journey").Body.String(); !strings.Contains(body, `href="/tasks/`+task.ID+`"`) { |
| 37 | t.Fatal("fixture task missing from journey", body) |
| 38 | } |
| 39 | rig := harness.New(t, func(string) http.Handler { return f.Handler }, harness.WithScrollbars()) |
| 40 | run := func(label string, steps ...chromedp.Action[chromedp.Void]) { |
| 41 | t.Helper() |
| 42 | t.Log(label) |
| 43 | drive, cancel := context.WithTimeout(rig.Context(), 10*time.Second) |
| 44 | defer cancel() |
| 45 | if err := chromedp.Do(drive, steps...); err != nil { |
| 46 | t.Fatalf("%s: %v; page: %s", label, err, harness.Evaluate[string](rig, `location.href+"\n"+document.querySelector("main").outerHTML`)) |
| 47 | } |
| 48 | } |
| 49 | cookie := f.Cookies[owner.Address] |
| 50 | run("set session and disable scripts", chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| 51 | if _, err := cdp.Call(ctx, target, network.SetCookie, network.SetCookieParams{Name: cookie.Name, Value: cookie.Value, URL: rig.Origin, Path: "/"}); err != nil { |
| 52 | return err |
| 53 | } |
| 54 | if _, err := cdp.Call(ctx, target, emulation.SetEmulatedMedia, emulation.SetEmulatedMediaParams{Features: []*emulation.MediaFeature{{Name: "prefers-reduced-motion", Value: "reduce"}}}); err != nil { |
| 55 | return err |
| 56 | } |
| 57 | _, err := cdp.Call(ctx, target, emulation.SetScriptExecutionDisabled, emulation.SetScriptExecutionDisabledParams{Value: true}) |
| 58 | return err |
| 59 | })) |
| 60 | // Teams left the sidebar's team heading for Settings in 2e53061 |
| 61 | // ("old pages out of the nav"; equipotest pins the heading without |
| 62 | // it). On a desktop the Settings rail lists it. |
| 63 | run("desktop Settings", chromedp.EmulateViewport(1280, 900), chromedp.Navigate(rig.Origin+"/conversation/settings")) |
| 64 | if !harness.Evaluate[bool](rig, `(()=>{const a=document.querySelector('[equipo-settings-rail] a[data-rail-settings="teams"]');return !!a && a.getAttribute('href')==='/teams' && a.getBoundingClientRect().width>0 && !document.querySelector('#nav-teams')})()`) { |
| 65 | t.Fatal("desktop Settings rail lacks a visible Teams link") |
| 66 | } |
| 67 | run("phone directory", chromedp.EmulateViewport(390, 844), chromedp.Navigate(rig.Origin+"/teams")) |
| 68 | if !harness.Evaluate[bool](rig, `document.querySelector('[equipo-current-team]').getBoundingClientRect().width>0 && document.documentElement.scrollWidth<=innerWidth`) { |
| 69 | t.Fatal("phone directory hidden or overflowing") |
| 70 | } |
| 71 | run("open current team", chromedp.Click(chromedp.CSS(`[equipo-current-team]`)), chromedp.WaitVisible(chromedp.CSS(`#nav-tasks`))) |
| 72 | // The phone home screen hides its back strip on purpose (index |
| 73 | // browser test: no strip above the home screen); its parent is still |
| 74 | // Teams. |
| 75 | if !harness.Evaluate[bool](rig, `document.querySelector('[rst-shell-back] a').getAttribute('href')==='/teams'`) { |
| 76 | t.Fatal("team index parent is not Teams") |
| 77 | } |
| 78 | // Journey is an old page out of the nav since 2e53061; it is still |
| 79 | // served for its links and its parent is still the team. |
| 80 | run("open Journey", chromedp.Navigate(rig.Origin+"/journey"), chromedp.WaitVisible(chromedp.CSS(`main a[href="/tasks/`+task.ID+`"]`))) |
| 81 | if !harness.Evaluate[bool](rig, `document.querySelector('[rst-shell-back] a').getAttribute('href').startsWith('/work')`) { |
| 82 | t.Fatal("page parent is not team") |
| 83 | } |
| 84 | run("open task", chromedp.Click(chromedp.CSS(`main a[href="/tasks/`+task.ID+`"]`)), chromedp.WaitVisible(chromedp.CSS(`main a[href="/tasks/`+task.ID+`/thread"]`))) |
| 85 | if !harness.Evaluate[bool](rig, `document.querySelector('[rst-shell-back] a').getAttribute('href')==='/journey'`) { |
| 86 | t.Fatal("task parent is not page") |
| 87 | } |
| 88 | run("open thread", chromedp.Click(chromedp.CSS(`main a[href="/tasks/`+task.ID+`/thread"]`))) |
| 89 | run("thread parent", chromedp.WaitVisible(chromedp.CSS(`[rst-shell-back] a[href="/tasks/`+task.ID+`"]`))) |
| 90 | run("back to task", chromedp.Click(chromedp.CSS(`[rst-shell-back] a`)), chromedp.WaitVisible(chromedp.CSS(`[rst-shell-back] a[href="/journey"]`))) |
| 91 | } |
| 92 | |