oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "amadan.net/oficina/equipo/internal/wire"
5 "bytes"
6 "encoding/json"
7 "strings"
8 "testing"
9 "time"
10)
11
12func TestPlacementChipUsesSharedMenu(t *testing.T) {
13 var b bytes.Buffer
14 v := taskLineOf(wire.Task{ID: "tkmove", Project: "Calendar", Stage: wire.StageNoted}, "owner@example.com")
15 if err := pages["work_task"].ExecuteTemplate(&b, "placement-chip", v); err != nil {
16 t.Fatal(err)
17 }
18 for _, want := range []string{"Wrong project?", "Move to another project", "Make it a new project", "/tasks/tkmove/move", "/tasks/tkmove/move?new=1", "<details"} {
19 if !strings.Contains(b.String(), want) {
20 t.Fatalf("missing %q: %s", want, b.String())
21 }
22 }
23}
24
25func TestPlacementPendingHasNoOldActions(t *testing.T) {
26 task := wire.Task{ID: "tkmove", Creator: "owner@example.com", Stage: wire.StageInReview, Moving: true, CopyHold: true, CopyCanSkip: true, NeedsYou: wire.NeedsFixRounds, Checks: wire.ChecksFailed}
27 v := taskLineOf(task, task.Creator)
28 v.richOf(task, task.Creator, nil, time.Now())
29 if v.Decision != nil || len(v.Menu) != 0 || v.Merge || v.Cancel || v.Retry {
30 t.Fatal("pending move offers old work actions", v.Decision, v.Menu)
31 }
32 if v.Eyebrow() != copyText("placement.pending") || summaryOf(task, v) != copyText("placement.pending") {
33 t.Fatal("pending move lost its status")
34 }
35}
36
37func TestPlacementNeedsCardHasMenu(t *testing.T) {
38 var b bytes.Buffer
39 task := taskLine{Task: wire.Task{ID: "tkneeds", Project: "Calendar"}, Decision: &decisionView{}}
40 if err := pages["work_needs"].ExecuteTemplate(&b, "decision", map[string]any{"Task": task, "Head": true, "From": "needs"}); err != nil {
41 t.Fatal(err)
42 }
43 if !strings.Contains(b.String(), `href="/tasks/tkneeds/move"`) {
44 t.Fatal("Needs you task has no project correction menu")
45 }
46}
47
48func TestPlacementHeldChipHasAbandonAndReason(t *testing.T) {
49 for _, reason := range []string{"runner", "creation", "destination", "owner", "publication", "protocol"} {
50 var b bytes.Buffer
51 v := taskLineOf(wire.Task{ID: "tkheld", Project: "Calendar", Moving: true, MoveHoldReason: reason, Revision: 4}, "owner@example.com")
52 if err := pages["work_task"].ExecuteTemplate(&b, "placement-chip", v); err != nil {
53 t.Fatal(err)
54 }
55 for _, want := range []string{`name="abandon"`, `value="4"`, copyText("placement.held_" + reason), "Abandon move"} {
56 if !strings.Contains(b.String(), want) {
57 t.Errorf("missing %s: %s", want, b.String())
58 }
59 }
60 if strings.Contains(b.String(), `href="/tasks/tkheld/move"`) {
61 t.Fatal("held chip offers a second move")
62 }
63 }
64}
65
66func TestPlacementAbandonStoppingView(t *testing.T) {
67 var task wire.Task
68 if err := json.Unmarshal([]byte(`{"id":"tkstop","creator":"owner@example.com","stage":"in_progress","stopping":true}`), &task); err != nil {
69 t.Fatal(err)
70 }
71 v := taskLineOf(task, task.Creator)
72 v.richOf(task, task.Creator, nil, time.Now())
73 if v.StageLine != "Stopping…" || v.Eyebrow() != "Stopping…" || summaryOf(task, v) != "Stopping…" {
74 t.Fatal("abandoned move does not show Stopping", v.StageLine, v.Eyebrow(), summaryOf(task, v))
75 }
76 if v.Decision != nil || len(v.Menu) != 0 || v.Cancel || v.Retry || v.Merge {
77 t.Fatal("stopping offers work actions")
78 }
79 var b bytes.Buffer
80 if err := pages["work_task"].ExecuteTemplate(&b, "placement-chip", v); err != nil {
81 t.Fatal(err)
82 }
83 if strings.Contains(b.String(), "/move") {
84 t.Fatal("stopping offers another move", b.String())
85 }
86}
87