oficina / slides Public

Editor: a test that nothing the card held on main is lost

TestEditorTidyNothingIsLost reads its table from origin/main's
editor.html: every deck, slide and block field, the inspector's
commands, the five marks, the eleven Add block kinds, the Boxes list,
Unused images, the phone badge and the delete confirmation. Each must be
in the card, in its form and in the group spec §4.2 and §4.3 name. The
five slide commands must have left the card and still be in the Slide
menu and the strip's item menu, and the stage bar keeps the switch and
no marks. It fails now on grouping and placement only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 9e15d3c527c5ceae2d724dac5515679a3851d045 parent fe5fbab
1 file changed, +225 −0
  • internal/slidestest/editor_tidy_test.go +225 −0
diff --git a/internal/slidestest/editor_tidy_test.go b/internal/slidestest/editor_tidy_test.go
index 325ed46..bcffd71 100644
--- a/internal/slidestest/editor_tidy_test.go
+++ b/internal/slidestest/editor_tidy_test.go
@@ -412,3 +412,228 @@ func TestEditorTidyCardShowsOneThing(t *testing.T) {
t.Errorf("with no slides, the notes icon is %s; want it disabled", b)
}
}
+
+// extent is the element whose opening tag starts at at: from there to
+// the end of its matching close tag, nested elements of the same name
+// counted. The template is well formed, so counting is enough.
+func extent(page string, at int) string {
+ m := regexp.MustCompile(`^<([a-z]+)`).FindStringSubmatch(page[at:])
+ if m == nil {
+ return ""
+ }
+ open := regexp.MustCompile(`<` + m[1] + `[\s>]|</` + m[1] + `>`)
+ depth := 0
+ for _, loc := range open.FindAllStringIndex(page[at:], -1) {
+ if page[at+loc[0]+1] == '/' {
+ depth--
+ if depth == 0 {
+ return page[at : at+loc[1]]
+ }
+ } else {
+ depth++
+ }
+ }
+ return ""
+}
+
+// tidyGroup is one labelled group in the card: its name and where it
+// starts and ends inside the form that holds it.
+type tidyGroup struct {
+ name string
+ start, end int
+}
+
+// tidyGroups lists the estilo-inspector-group elements in form, in
+// order, each named by its data-group.
+func tidyGroups(form string) []tidyGroup {
+ var out []tidyGroup
+ name := regexp.MustCompile(`\sdata-group="([^"]+)"`)
+ for _, loc := range regexp.MustCompile(`<div estilo-inspector-group[^>]*>`).FindAllStringIndex(form, -1) {
+ g := tidyGroup{start: loc[0], end: loc[0] + len(extent(form, loc[0]))}
+ if n := name.FindStringSubmatch(form[loc[0]:loc[1]]); n != nil {
+ g.name = n[1]
+ }
+ out = append(out, g)
+ }
+ return out
+}
+
+// TestEditorTidyNothingIsLost (spec E8, E10, §4.2, §4.3): every field,
+// command and list the inspector held on main (read off main's
+// editor.html at the plan's base, with the stage bar's five marks) is
+// still in the card, in the form and the group the spec puts it in;
+// the five slide commands that left the card are still in the Slide
+// menu and in each slide's own menu in the strip; and the stage bar
+// keeps the view switch and no marks.
+func TestEditorTidyNothingIsLost(t *testing.T) {
+ a := newApp(t)
+ cookies := signedIn(t, a, allowedAddress)
+ page := mustGet(t, a, deckWithSlides(t, a, cookies, 2), http.StatusOK, cookies).Body.String()
+
+ at := strings.Index(page, "<aside slides-inspector")
+ if at < 0 {
+ t.Fatal("no <aside slides-inspector> in the editor")
+ }
+ card := extent(page, at)
+ forms := map[string]string{}
+ section := regexp.MustCompile(`\sdata-section="([^"]+)"`)
+ for _, loc := range regexp.MustCompile(`<form [^>]*slides-inspector-form[^>]*>`).FindAllStringIndex(card, -1) {
+ if s := section.FindStringSubmatch(card[loc[0]:loc[1]]); s != nil {
+ forms[s[1]] = extent(card, loc[0])
+ }
+ }
+
+ // group "" is the form itself, outside every group.
+ type needle struct{ needle, section, group string }
+ var table []needle
+ for _, n := range []string{"title", "theme", "accent", "font-heading", "font-body"} {
+ table = append(table, needle{`name="rst-deck-` + n + `"`, "deck", "deck"})
+ }
+ table = append(table,
+ needle{`data-command="accent-reset"`, "deck", "deck"},
+ needle{`<fieldset slides-unused-assets`, "deck", "deck"},
+ )
+ for _, n := range []string{"layout", "template", "background", "background-color", "transition", "phone"} {
+ table = append(table, needle{`name="rst-slide-` + n + `"`, "slide", "slide"})
+ }
+ table = append(table,
+ needle{`slides-confirm`, "slide", ""},
+ needle{`data-command="slide-delete"`, "slide", ""},
+ needle{`data-command="slide-delete-cancel"`, "slide", ""},
+ needle{`slides-blocks-buttons`, "slide", "boxes"},
+ )
+ for _, kind := range []string{"heading", "text", "list", "quote", "image", "columns", "code", "shape", "table", "divider", "spacer"} {
+ table = append(table, needle{`data-add-block="` + kind + `"`, "slide", "boxes"})
+ }
+ for _, f := range []struct{ name, group string }{
+ {"level", "style"}, {"size", "style"}, {"style", "style"}, {"cite", "style"}, {"count", "style"},
+ {"language", "style"}, {"kind", "style"}, {"fill", "style"}, {"stroke", "style"}, {"strokeWidth", "style"},
+ {"label", "style"}, {"rows", "style"}, {"cols", "style"}, {"header", "style"}, {"spacer-size", "style"},
+ {"align", "alignment"},
+ {"image", "image"}, {"fit", "image"}, {"radius", "image"},
+ {"alt", "description"}, {"decorative", "description"},
+ {"region", "place"}, {"x", "place"}, {"y", "place"}, {"w", "place"}, {"h", "place"},
+ {"phone-hidden", "phone"}, {"phone-order", "phone"}, {"phone-size", "phone"},
+ } {
+ table = append(table, needle{`name="rst-block-` + f.name + `"`, "block", f.group})
+ }
+ for _, mark := range []string{"b", "i", "c", "h", "href"} {
+ table = append(table, needle{`data-mark="` + mark + `"`, "block", "text"})
+ }
+ table = append(table,
+ needle{`slides-phone-badge`, "block", "phone"},
+ needle{`data-command="phone-reset"`, "block", "phone"},
+ needle{`data-command="block-forward"`, "block", "place"},
+ needle{`data-command="block-back"`, "block", "place"},
+ needle{`data-command="block-move-up"`, "block", "place"},
+ needle{`data-command="block-move-down"`, "block", "place"},
+ needle{`data-command="block-delete"`, "block", ""},
+ )
+
+ for _, n := range table {
+ c := strings.Count(card, n.needle)
+ if c == 0 {
+ t.Errorf("%s is not in the card", n.needle)
+ continue
+ }
+ form := forms[n.section]
+ if f := strings.Count(form, n.needle); f != c {
+ t.Errorf("%s: %d of the %d in the card are in the %s form", n.needle, f, c, n.section)
+ continue
+ }
+ groups := tidyGroups(form)
+ for off := 0; ; {
+ i := strings.Index(form[off:], n.needle)
+ if i < 0 {
+ break
+ }
+ i += off
+ off = i + len(n.needle)
+ in := ""
+ for _, g := range groups {
+ if g.start < i && i < g.end {
+ in = g.name
+ }
+ }
+ if in != n.group {
+ t.Errorf("%s is in the %s form's group %q, want %q", n.needle, n.section, in, n.group)
+ }
+ }
+ }
+
+ // The groups themselves: estilo's labelled group, its label's id the
+ // group's name, in the spec's order.
+ for _, w := range []struct {
+ section string
+ names []string
+ }{
+ {"block", []string{"style", "text", "alignment", "image", "description", "place", "phone"}},
+ {"slide", []string{"slide", "boxes"}},
+ {"deck", []string{"deck"}},
+ } {
+ var got []string
+ form := forms[w.section]
+ for _, g := range tidyGroups(form) {
+ got = append(got, g.name)
+ open := form[g.start : g.start+strings.Index(form[g.start:], ">")+1]
+ if want := `<div estilo-inspector-group role="group" aria-labelledby="slides-g-` + g.name + `" data-group="` + g.name + `">`; open != want {
+ t.Errorf("the %s group opens %s, want %s", g.name, open, want)
+ }
+ if !regexp.MustCompile(`^<div[^>]*>\s*<span estilo-inspector-label id="slides-g-` + regexp.QuoteMeta(g.name) + `">[^<]+</span>`).MatchString(form[g.start:g.end]) {
+ t.Errorf("the %s group does not begin with its <span estilo-inspector-label id=\"slides-g-%s\">", g.name, g.name)
+ }
+ }
+ if strings.Join(got, " ") != strings.Join(w.names, " ") {
+ t.Errorf("the %s form's groups are %v, want %v", w.section, got, w.names)
+ }
+ }
+ if block := forms["block"]; block != "" {
+ del := regexp.MustCompile(`<button[^>]*\sslides-block-delete[^>]*>`).FindStringIndex(block)
+ if del == nil || !strings.Contains(block[del[0]:del[1]], `data-command="block-delete"`) {
+ t.Error("Delete block is not a button[slides-block-delete]")
+ } else if gs := tidyGroups(block); len(gs) > 0 && del[0] < gs[len(gs)-1].end {
+ t.Error("Delete block is not after the last group of the box's options")
+ }
+ }
+ if slide := forms["slide"]; slide != "" {
+ confirm := strings.Index(slide, "slides-confirm")
+ if gs := tidyGroups(slide); confirm < 0 || (len(gs) > 0 && confirm > gs[0].start) {
+ t.Error("the delete confirmation is not first in the slide's options")
+ }
+ }
+
+ // The slide's own commands left the card, and are where they were.
+ for _, c := range []string{"slide-move-up", "slide-move-down", "slide-add-after", "duplicate-slide", "slide-delete-ask"} {
+ if strings.Contains(card, `data-command="`+c+`"`) {
+ t.Errorf("the card still holds data-command=%q", c)
+ }
+ }
+ menubar := regexp.MustCompile(`(?s)<nav estilo-menubar slides-menubar.*?</nav>`).FindString(page)
+ menu := regexp.MustCompile(`(?s)<details[^>]*slides-menu="slide".*?</details>`).FindString(menubar)
+ if menu == "" {
+ t.Fatal("no Slide menu in [slides-menubar]")
+ }
+ for _, c := range []string{"new-slide", "duplicate-slide", "slide-move-up", "slide-move-down", "slide-delete-ask"} {
+ if !strings.Contains(menu, `data-command="`+c+`"`) {
+ t.Errorf("the Slide menu has no data-command=%q", c)
+ }
+ }
+ tmpl := regexp.MustCompile(`(?s)<template slides-strip-item-template>.*?</template>`).FindString(page)
+ for _, c := range []string{"add-after", "duplicate", "move-up", "move-down", "delete"} {
+ if !strings.Contains(tmpl, `data-slide-command="`+c+`"`) {
+ t.Errorf("the strip item's menu has no data-slide-command=%q", c)
+ }
+ }
+
+ bar := strings.Index(page, "<div slides-stage-bar")
+ if bar < 0 {
+ t.Fatal("no [slides-stage-bar] in the editor")
+ }
+ stageBar := extent(page, bar)
+ if !strings.Contains(stageBar, "slides-switcher") {
+ t.Error("the stage bar has no view switch")
+ }
+ if strings.Contains(stageBar, "data-mark") {
+ t.Error("the stage bar still holds marks")
+ }
+}