//go:build browser package plan3test import ( "amadan.net/oficina/equipo/internal/testci" "amadan.net/rastrillo/rastrillo/harness" "context" "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/emulation" "github.com/chromedp/cdproto/network" "github.com/chromedp/chromedp" "net/http" "os" "os/exec" "strings" "testing" "time" ) func TestTeamsHierarchyBrowser(t *testing.T) { // The browser harness.ChromePath finds: RASTRILLO_CHROME (the CI box // sets it to its pinned Chromium), or one on PATH. found := os.Getenv("RASTRILLO_CHROME") != "" for _, name := range []string{"chromium", "chromium-browser", "google-chrome", "google-chrome-stable"} { if _, err := exec.LookPath(name); err == nil { found = true break } } if !found { testci.Absent(t, "Chrome/Chromium binary unavailable; scriptless Teams hierarchy needs the chromedp fixture") } f := newFixture(t) task := f.createTask(t) if body := f.get(t, owner, "/journey").Body.String(); !strings.Contains(body, `href="/tasks/`+task.ID+`"`) { t.Fatal("fixture task missing from journey", body) } rig := harness.New(t, func(string) http.Handler { return f.Handler }, harness.WithScrollbars()) run := func(label string, steps ...chromedp.Action[chromedp.Void]) { t.Helper() t.Log(label) drive, cancel := context.WithTimeout(rig.Context(), 10*time.Second) defer cancel() if err := chromedp.Do(drive, steps...); err != nil { t.Fatalf("%s: %v; page: %s", label, err, harness.Evaluate[string](rig, `location.href+"\n"+document.querySelector("main").outerHTML`)) } } cookie := f.Cookies[owner.Address] run("set session and disable scripts", chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { if _, err := cdp.Call(ctx, target, network.SetCookie, network.SetCookieParams{Name: cookie.Name, Value: cookie.Value, URL: rig.Origin, Path: "/"}); err != nil { return err } if _, err := cdp.Call(ctx, target, emulation.SetEmulatedMedia, emulation.SetEmulatedMediaParams{Features: []*emulation.MediaFeature{{Name: "prefers-reduced-motion", Value: "reduce"}}}); err != nil { return err } _, err := cdp.Call(ctx, target, emulation.SetScriptExecutionDisabled, emulation.SetScriptExecutionDisabledParams{Value: true}) return err })) // Teams left the sidebar's team heading for Settings in 2e53061 // ("old pages out of the nav"; equipotest pins the heading without // it). On a desktop the Settings rail lists it. run("desktop Settings", chromedp.EmulateViewport(1280, 900), chromedp.Navigate(rig.Origin+"/conversation/settings")) 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')})()`) { t.Fatal("desktop Settings rail lacks a visible Teams link") } run("phone directory", chromedp.EmulateViewport(390, 844), chromedp.Navigate(rig.Origin+"/teams")) if !harness.Evaluate[bool](rig, `document.querySelector('[equipo-current-team]').getBoundingClientRect().width>0 && document.documentElement.scrollWidth<=innerWidth`) { t.Fatal("phone directory hidden or overflowing") } run("open current team", chromedp.Click(chromedp.CSS(`[equipo-current-team]`)), chromedp.WaitVisible(chromedp.CSS(`#nav-tasks`))) // The phone home screen hides its back strip on purpose (index // browser test: no strip above the home screen); its parent is still // Teams. if !harness.Evaluate[bool](rig, `document.querySelector('[rst-shell-back] a').getAttribute('href')==='/teams'`) { t.Fatal("team index parent is not Teams") } // Journey is an old page out of the nav since 2e53061; it is still // served for its links and its parent is still the team. run("open Journey", chromedp.Navigate(rig.Origin+"/journey"), chromedp.WaitVisible(chromedp.CSS(`main a[href="/tasks/`+task.ID+`"]`))) if !harness.Evaluate[bool](rig, `document.querySelector('[rst-shell-back] a').getAttribute('href').startsWith('/work')`) { t.Fatal("page parent is not team") } run("open task", chromedp.Click(chromedp.CSS(`main a[href="/tasks/`+task.ID+`"]`)), chromedp.WaitVisible(chromedp.CSS(`main a[href="/tasks/`+task.ID+`/thread"]`))) if !harness.Evaluate[bool](rig, `document.querySelector('[rst-shell-back] a').getAttribute('href')==='/journey'`) { t.Fatal("task parent is not page") } run("open thread", chromedp.Click(chromedp.CSS(`main a[href="/tasks/`+task.ID+`/thread"]`))) run("thread parent", chromedp.WaitVisible(chromedp.CSS(`[rst-shell-back] a[href="/tasks/`+task.ID+`"]`))) run("back to task", chromedp.Click(chromedp.CSS(`[rst-shell-back] a`)), chromedp.WaitVisible(chromedp.CSS(`[rst-shell-back] a[href="/journey"]`))) }