|
| 1 | +package tui |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/BackendStack21/bodek/internal/client" |
| 7 | +) |
| 8 | + |
| 9 | +// frictionModel builds a recorder model with a friction-gated approval as |
| 10 | +// the queue head — the approval-fatigue state where Alt chords were the only |
| 11 | +// path, which macOS Option-as-UTF-8 terminals cannot deliver. |
| 12 | +func frictionModel(t *testing.T) (*Model, chan string) { |
| 13 | + t.Helper() |
| 14 | + m, actions, _ := approvalRecorder(t) |
| 15 | + busyTurn(m) |
| 16 | + m.handleEvent(client.Event{Type: "approval_request", ID: "apr", Friction: true, FrictionApprovals: 3}) |
| 17 | + return m, actions |
| 18 | +} |
| 19 | + |
| 20 | +// TestFrictionPlainKeysWorkWithoutAlt verifies the friction gate is usable |
| 21 | +// without Alt chords: a bare 'a' opens the confirmation editor (it must NOT |
| 22 | +// approve — the friction gate exists to slow approving), and a bare 'd' |
| 23 | +// denies. Both only fire on an empty composer draft. |
| 24 | +func TestFrictionPlainKeysWorkWithoutAlt(t *testing.T) { |
| 25 | + t.Run("bare a opens editor without approving", func(t *testing.T) { |
| 26 | + m, actions := frictionModel(t) |
| 27 | + m.Update(key("a")) |
| 28 | + if !m.apprEditing { |
| 29 | + t.Fatal("bare 'a' did not open the friction confirmation editor") |
| 30 | + } |
| 31 | + if m.curApproval() == nil { |
| 32 | + t.Fatal("bare 'a' must not answer the approval") |
| 33 | + } |
| 34 | + select { |
| 35 | + case got := <-actions: |
| 36 | + t.Fatalf("bare 'a' sent action %q — friction must require the typed word", got) |
| 37 | + default: |
| 38 | + } |
| 39 | + }) |
| 40 | + |
| 41 | + t.Run("bare d denies", func(t *testing.T) { |
| 42 | + m, actions := frictionModel(t) |
| 43 | + _, cmd := m.Update(key("d")) |
| 44 | + exec(cmd) |
| 45 | + if got := awaitAction(t, actions); got != "deny" { |
| 46 | + t.Fatalf("bare 'd' action = %q, want deny", got) |
| 47 | + } |
| 48 | + }) |
| 49 | + |
| 50 | + t.Run("draft guards plain keys", func(t *testing.T) { |
| 51 | + m, _ := frictionModel(t) |
| 52 | + m.ta.SetValue("draft") |
| 53 | + m.Update(key("d")) |
| 54 | + if m.curApproval() == nil { |
| 55 | + t.Fatal("bare 'd' denied while the composer held a draft") |
| 56 | + } |
| 57 | + if m.ta.Value() != "draftd" { |
| 58 | + t.Fatalf("composer draft = %q, want the letter typed", m.ta.Value()) |
| 59 | + } |
| 60 | + }) |
| 61 | + |
| 62 | + t.Run("editor still requires the word", func(t *testing.T) { |
| 63 | + m, actions := frictionModel(t) |
| 64 | + m.Update(key("a")) |
| 65 | + m.Update(key("approve")) |
| 66 | + _, cmd := m.Update(key("enter")) |
| 67 | + exec(cmd) |
| 68 | + if got := awaitAction(t, actions); got != "approve" { |
| 69 | + t.Fatalf("typed word action = %q, want approve", got) |
| 70 | + } |
| 71 | + }) |
| 72 | +} |
0 commit comments