//go:build browser package thintest import ( "amadan.net/oficina/equipo/internal/wire" "fmt" "testing" ) func TestBrowserAccessFinalOutcomes(t *testing.T) { for _, width := range []int64{1280, 390} { for _, scheme := range []string{"light", "dark"} { for _, outcome := range []string{"not_owned", "already"} { t.Run(fmt.Sprintf("%d-%s-%s", width, scheme, outcome), func(t *testing.T) { r := newToolRigSaying(t, wire.ProtocolCurrent, "Fix carlos/platform") if got := r.call("access-proposal", wire.ToolRequestAccess, map[string]any{"target": "carlos/platform", "reason": "I need access to fix the build."}); got.Code != "asked" { t.Fatal(got) } r.runner.Send(r.ctx, "reply", wire.FrameReply, wire.Reply{TurnID: r.turn, Attempt: 1, Text: "Please confirm."}) r.wait("reply", func(c *Conversation) bool { return c.Turns[r.turn].State == wire.TurnReplied }) p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") defer p.stop() p.open("/conversation") p.wait(`document.querySelector('[data-access-confirm]')`, "confirmation") p.click(`[data-access-confirm]`) _, body, err := r.runner.Expect(r.ctx, wire.FrameRequestAccess) if err != nil { t.Fatal(err) } cmd := body.(*wire.AccessCommand) if err := r.runner.Send(r.ctx, "final", wire.FrameAccess, wire.AccessReport{CardID: cmd.CardID, Person: cmd.Person, State: outcome}); err != nil { t.Fatal(err) } p.wait(`document.querySelector('[data-access-state="`+outcome+`"]')`, outcome) want := "Equipo already has access." if outcome == "not_owned" { want = "Amadan can’t ask the owner of carlos for access." } p.check(`document.querySelector('[data-access-state] [role="status"]').textContent === `+fmt.Sprintf("%q", want), "clear final copy") p.check(`!document.querySelector('[data-access-confirm], [data-access-approve], [data-access-aside]')`, "no retry or approval action") p.fits(outcome) p.shot(fmt.Sprintf("access-final-%s-%d-%s", outcome, width, scheme)) }) } } } }