| 1 | //go:build browser |
| 2 | |
| 3 | package thintest |
| 4 | |
| 5 | import ( |
| 6 | "amadan.net/oficina/equipo/internal/wire" |
| 7 | "fmt" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func TestBrowserAccessFinalOutcomes(t *testing.T) { |
| 12 | for _, width := range []int64{1280, 390} { |
| 13 | for _, scheme := range []string{"light", "dark"} { |
| 14 | for _, outcome := range []string{"not_owned", "already"} { |
| 15 | t.Run(fmt.Sprintf("%d-%s-%s", width, scheme, outcome), func(t *testing.T) { |
| 16 | r := newToolRigSaying(t, wire.ProtocolCurrent, "Fix carlos/platform") |
| 17 | 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" { |
| 18 | t.Fatal(got) |
| 19 | } |
| 20 | r.runner.Send(r.ctx, "reply", wire.FrameReply, wire.Reply{TurnID: r.turn, Attempt: 1, Text: "Please confirm."}) |
| 21 | r.wait("reply", func(c *Conversation) bool { return c.Turns[r.turn].State == wire.TurnReplied }) |
| 22 | p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") |
| 23 | defer p.stop() |
| 24 | p.open("/conversation") |
| 25 | p.wait(`document.querySelector('[data-access-confirm]')`, "confirmation") |
| 26 | p.click(`[data-access-confirm]`) |
| 27 | _, body, err := r.runner.Expect(r.ctx, wire.FrameRequestAccess) |
| 28 | if err != nil { |
| 29 | t.Fatal(err) |
| 30 | } |
| 31 | cmd := body.(*wire.AccessCommand) |
| 32 | if err := r.runner.Send(r.ctx, "final", wire.FrameAccess, wire.AccessReport{CardID: cmd.CardID, Person: cmd.Person, State: outcome}); err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | p.wait(`document.querySelector('[data-access-state="`+outcome+`"]')`, outcome) |
| 36 | want := "Equipo already has access." |
| 37 | if outcome == "not_owned" { |
| 38 | want = "Amadan can’t ask the owner of carlos for access." |
| 39 | } |
| 40 | p.check(`document.querySelector('[data-access-state] [role="status"]').textContent === `+fmt.Sprintf("%q", want), "clear final copy") |
| 41 | p.check(`!document.querySelector('[data-access-confirm], [data-access-approve], [data-access-aside]')`, "no retry or approval action") |
| 42 | p.fits(outcome) |
| 43 | p.shot(fmt.Sprintf("access-final-%s-%d-%s", outcome, width, scheme)) |
| 44 | }) |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |