oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package thintest
2
3import (
4 "regexp"
5 "strings"
6 "testing"
7)
8
9// taskRow is one task's row on a list page.
10func taskRow(t *testing.T, page, id string) string {
11 t.Helper()
12 row := regexp.MustCompile(`(?s)<li equipo-row equipo-trow data-task="` + regexp.QuoteMeta(id) + `".*?\n</li>`).FindString(page)
13 if row == "" {
14 t.Fatalf("no row for %s in:\n%s", id, page)
15 }
16 return row
17}
18
19// TestPagesTaskRows: every row is one grid of project, task, status,
20// from, updated and the action slot. A Needs you row carries its one
21// action, mapped to the handler its decision card uses; an exploration
22// waiting on its direction leads with What next?, which opens the
23// direction card. Done shows the newest row and the rest behind "Show N
24// more".
25func TestPagesTaskRows(t *testing.T) {
26 f := newRowsFixture(t, 2)
27 r := f.r
28 owner := r.inst.Cookie()
29 tasks := r.get(owner, "/tasks", 200)
30
31 // The column names, once, for the eye only.
32 if n := strings.Count(tasks, `<div equipo-tcols aria-hidden="true">`); n != 1 {
33 t.Fatalf("%d column heads", n)
34 }
35 for _, col := range []string{"<span>Project</span>", "<span>Task</span>", "<span>Status</span>", "<span>From</span>", "<span>Updated</span>"} {
36 if !strings.Contains(tasks, col) {
37 t.Fatalf("column head lacks %s", col)
38 }
39 }
40
41 // One action per Needs you row, each the decision's own handler.
42 for _, c := range []struct{ id, kind, label, open string }{
43 {f.retry, "retry", "Retry", `<form method="post" action="/conversation/tasks/` + f.retry + `/retry">`},
44 {f.push, "retry", "Retry push", `<form method="post" action="/conversation/tasks/` + f.push + `/retry">`},
45 {f.rounds, "round", "Another round", `<form method="post" action="/conversation/tasks/` + f.rounds + `/round">`},
46 {f.explore, "next", "What next?", `<a equipo-act href="/tasks/` + f.explore + `#decide" data-act="next">`},
47 } {
48 row := taskRow(t, tasks, c.id)
49 if strings.Count(row, "equipo-act ") != 1 || !strings.Contains(row, `data-act="`+c.kind+`"`) || !strings.Contains(row, "<span>"+c.label+"</span>") || !strings.Contains(row, c.open) {
50 t.Fatalf("%s row's action is not %s:\n%s", c.kind, c.label, row)
51 }
52 if !strings.Contains(row, `data-group="needs"`) || !strings.Contains(row, `<svg class="icon"`) || strings.Count(row, `aria-hidden="true" viewBox="0 0 16 16"`) != 1 {
53 t.Fatalf("%s row: group or icon:\n%s", c.kind, row)
54 }
55 }
56 // The primary action is not repeated in the row's menu.
57 if n := strings.Count(tasks, `action="/conversation/tasks/`+f.retry+`/retry"`); n != 1 {
58 t.Fatalf("Retry %d times on its row", n)
59 }
60 // Under Needs you the status drops the heading's "Needs you:".
61 rounds := taskRow(t, tasks, f.rounds)
62 if !strings.Contains(rounds, ">Still not approved after two fix rounds</p>") || strings.Contains(rounds, "Needs you: still") {
63 t.Fatalf("rounds status:\n%s", rounds)
64 }
65 // The project, the stepper's words, who and from where, the age.
66 retry := taskRow(t, tasks, f.retry)
67 for _, want := range []string{`data-placement-task="` + f.retry + `"`, `href="/tasks/` + f.retry + `/move"`, `<span equipo-project-name>Sample</span>`,
68 `role="img" aria-label="Step 3 of 6"`, ">Stopped: the model connection failed</p>",
69 "<span data-short>Conversation, ", "<span data-long>From your conversation, ", ">You</span>", "equipo-ago data-at=", `aria-label="More actions"`,
70 `href="/conversation?about=` + f.retry + `" data-ask-about>Ask about this</a>`} {
71 if !strings.Contains(retry, want) {
72 t.Fatalf("retry row lacks %q:\n%s", want, retry)
73 }
74 }
75 // The detail line says its badges once, in words, with the whole line
76 // as its tooltip.
77 if row := taskRow(t, tasks, f.rounds); !strings.Contains(row, `<span equipo-trow-note title="No checks found. Changes requested.">`) {
78 t.Fatalf("rounds detail:\n%s", row)
79 }
80 // Rows that wait on nobody carry no action, only the quiet menu.
81 if row := taskRow(t, tasks, f.noted[0]); strings.Contains(row, "equipo-act") || !strings.Contains(row, "equipo-menu") {
82 t.Fatalf("noted row:\n%s", row)
83 }
84 // The long title is whole in the page; the screen clamps it.
85 if !strings.Contains(tasks, rowsLongTitle+"</a>") {
86 t.Fatal("long title cut in the markup")
87 }
88
89 // Done: the newest, then "Show 2 more"; with ?done=all, all three.
90 done := strings.Count(tasks, `data-group="done">`)
91 if done != 1 || !strings.Contains(tasks, `<a equipo-trow-more href="/tasks?done=all#done">Show 2 more</a>`) || !strings.Contains(tasks, `<section equipo-group data-group="done" id="done">`) {
92 t.Fatalf("Done shows %d rows, or no Show 2 more", done)
93 }
94 all := r.get(owner, "/tasks?done=all", 200)
95 if n := strings.Count(all, `data-group="done">`); n != 3 || strings.Contains(all, "equipo-trow-more") {
96 t.Fatalf("?done=all shows %d done rows", n)
97 }
98 // The filters keep their choice through Show N more.
99 pid := r.task(f.done[0]).ProjectID
100 if p := r.get(owner, "/tasks?project="+pid, 200); !strings.Contains(p, `href="/tasks?done=all&amp;project=`+pid+`#done"`) {
101 t.Fatal("Show N more drops the project filter")
102 }
103
104 // What next? opens the direction card on the task page.
105 if p := r.get(owner, "/tasks/"+f.explore, 200); !strings.Contains(p, `id="decide"`) || !strings.Contains(p, `value="build"`) {
106 t.Fatal("no direction card to open")
107 }
108 // The project page shares the rows, without the project column.
109 project := r.get(owner, "/projects/"+pid, 200)
110 if !strings.Contains(project, `<div equipo-tasklist data-scope="project">`) || !strings.Contains(project, `href="/projects/`+pid+`?done=all#done"`) || !strings.Contains(project, `data-act="next"`) {
111 t.Fatal("project page rows")
112 }
113}
114