| new file mode 100644 |
| index 0000000..d5cd32f |
| --- /dev/null |
| +++ b/internal/slidestest/quieter_inventory_test.go |
| @@ -0,0 +1,190 @@ |
| +package slidestest |
| + |
| +import ( |
| + "net/http" |
| + "regexp" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// The quieter editor's inventory (docs/superpowers/specs/2026-11-17-quieter-editor-design.md): |
| +// one table naming where every field and command of the editor lives. |
| +// A task that moves a control changes that control's row first; the test |
| +// then says whether the markup agrees. A needle must be found in its |
| +// home and nowhere else in the editor page outside <template> elements. |
| + |
| +// The homes. A block field's home is homeCardBlock+":"+group, the group |
| +// being the data-group of the card's block form ("" is the form's tail |
| +// after its last group, where Delete block sits). |
| +const ( |
| + homeCardSlide = "card-slide" // the card's slide form, every group of it |
| + homeCardBlock = "card-block" // + ":" + group, the card's block form |
| + homeCardDeck = "card-deck" // the card's deck form; Task Q2 retires it |
| + homePopBackground = "pop-background" // #slides-pop-background[popover] |
| + homePopTransition = "pop-transition" // #slides-pop-transition[popover] |
| + homeDeckDialog = "deck-dialog" // <dialog slides-deck-dialog> |
| + homeBoxMenu = "box-menu" // [slides-box-menu] |
| + homeInsertMenu = "insert-menu" // the menubar's Insert menu |
| + homeOutline = "outline" // #slides-outline[popover] |
| + homePhoneOnly = "phone-only" // what only the phone view shows |
| + homeStrip = "strip" // the strip's own rows |
| +) |
| + |
| +// needle is one control, found by a string specific enough to mean only |
| +// it, and the home it has today. |
| +type needle struct{ needle, home string } |
| + |
| +// homes is the inventory, from the editor on main: every field, command |
| +// and list the old inspector held, plus the stage bar's five marks. |
| +var homes = buildHomes() |
| + |
| +func buildHomes() []needle { |
| + var t []needle |
| + add := func(home string, needles ...string) { |
| + for _, n := range needles { |
| + t = append(t, needle{n, home}) |
| + } |
| + } |
| + |
| + for _, n := range []string{"title", "theme", "accent", "font-heading", "font-body"} { |
| + add(homeCardDeck, `name="rst-deck-`+n+`"`) |
| + } |
| + add(homeCardDeck, `data-command="accent-reset"`, `<fieldset slides-unused-assets`) |
| + |
| + for _, n := range []string{"layout", "template", "background", "background-color", "transition", "phone"} { |
| + add(homeCardSlide, `name="rst-slide-`+n+`"`) |
| + } |
| + add(homeCardSlide, |
| + `slides-confirm`, `data-command="slide-delete"`, `data-command="slide-delete-cancel"`, |
| + `slides-blocks-buttons`) |
| + for _, kind := range []string{"heading", "text", "list", "quote", "image", "columns", "code", "shape", "table", "divider", "spacer"} { |
| + add(homeCardSlide, `data-add-block="`+kind+`"`) |
| + } |
| + |
| + 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"}, |
| + {"radius", "style"}, // R16: Style for images and shapes alike, not the spec table's Image |
| + {"image", "image"}, {"fit", "image"}, |
| + {"alt", "description"}, {"decorative", "description"}, |
| + {"region", "place"}, {"x", "place"}, {"y", "place"}, {"w", "place"}, {"h", "place"}, |
| + {"phone-hidden", "phone"}, {"phone-order", "phone"}, {"phone-size", "phone"}, |
| + } { |
| + add(homeCardBlock+":"+f.group, `name="rst-block-`+f.name+`"`) |
| + } |
| + for _, mark := range []string{"b", "i", "c", "h", "href"} { |
| + add(homeCardBlock+":text", `data-mark="`+mark+`"`) |
| + } |
| + add(homeCardBlock+":phone", `slides-phone-badge`, `data-command="phone-reset"`) |
| + add(homeCardBlock+":place", |
| + `data-command="block-forward"`, `data-command="block-back"`, |
| + `data-command="block-move-up"`, `data-command="block-move-down"`) |
| + add(homeCardBlock+":", `data-command="block-delete"`) |
| + return t |
| +} |
| + |
| +// homeOf is the slice of page that home denotes, or "" when the page |
| +// has no such markup (yet). To give a new home a case, add one line to |
| +// the switch: find its opening tag, return extentAt of it. |
| +func homeOf(page, home string) string { |
| + // from returns the element whose opening tag matches re. |
| + from := func(re string) string { |
| + loc := regexp.MustCompile(re).FindStringIndex(page) |
| + if loc == nil { |
| + return "" |
| + } |
| + return extent(page, loc[0]) |
| + } |
| + form := func(section string) string { |
| + card := from(`<aside slides-inspector`) |
| + for _, loc := range regexp.MustCompile(`<form [^>]*slides-inspector-form[^>]*>`).FindAllStringIndex(card, -1) { |
| + if strings.Contains(card[loc[0]:loc[1]], `data-section="`+section+`"`) { |
| + return extent(card, loc[0]) |
| + } |
| + } |
| + return "" |
| + } |
| + |
| + switch { |
| + case home == homeCardSlide: |
| + return form("slide") |
| + case home == homeCardDeck: |
| + return form("deck") |
| + case strings.HasPrefix(home, homeCardBlock+":"): |
| + block, group := form("block"), strings.TrimPrefix(home, homeCardBlock+":") |
| + gs := tidyGroups(block) |
| + if group == "" { |
| + if len(gs) == 0 { |
| + return "" |
| + } |
| + return block[gs[len(gs)-1].end:] |
| + } |
| + for _, g := range gs { |
| + if g.name == group { |
| + return block[g.start:g.end] |
| + } |
| + } |
| + return "" |
| + case home == homePopBackground: |
| + return from(`<[a-z]+ [^>]*id="slides-pop-background"`) |
| + case home == homePopTransition: |
| + return from(`<[a-z]+ [^>]*id="slides-pop-transition"`) |
| + case home == homeDeckDialog: |
| + return from(`<dialog [^>]*slides-deck-dialog`) |
| + case home == homeBoxMenu: |
| + return from(`<div [^>]*slides-box-menu`) |
| + case home == homeInsertMenu: |
| + return from(`<details [^>]*slides-menu="insert"`) |
| + case home == homeOutline: |
| + return from(`<[a-z]+ [^>]*id="slides-outline"`) |
| + case home == homeStrip: |
| + return from(`<ol [^>]*slides-strip[\s>]`) |
| + } |
| + return "" |
| +} |
| + |
| +// TestQuieterNothingIsLost: every needle in homes is in its home, and |
| +// nowhere else in the editor page outside <template> elements. |
| +func TestQuieterNothingIsLost(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() |
| + live := regexp.MustCompile(`(?s)<template.*?</template>`).ReplaceAllString(page, "") |
| + |
| + for _, n := range homes { |
| + where := homeOf(live, n.home) |
| + if where == "" { |
| + t.Errorf("%s: its home %q has no markup in the editor page", n.needle, n.home) |
| + continue |
| + } |
| + in, all := strings.Count(where, n.needle), strings.Count(live, n.needle) |
| + if in == all && in > 0 { |
| + continue |
| + } |
| + t.Errorf("%s: %d of its %d occurrences are in its home %q; found in: %s", |
| + n.needle, in, all, n.home, foundIn(live, n.needle)) |
| + } |
| +} |
| + |
| +// foundIn names the homes (the ones the table uses, with the block |
| +// form's groups) whose markup holds needle, for a failure message. |
| +func foundIn(live, needle string) string { |
| + var got []string |
| + for _, h := range []string{ |
| + homeCardSlide, homeCardDeck, homePopBackground, homePopTransition, homeDeckDialog, |
| + homeBoxMenu, homeInsertMenu, homeOutline, homeStrip, homeCardBlock + ":", |
| + homeCardBlock + ":style", homeCardBlock + ":text", homeCardBlock + ":alignment", |
| + homeCardBlock + ":image", homeCardBlock + ":description", homeCardBlock + ":place", |
| + homeCardBlock + ":phone", |
| + } { |
| + if strings.Contains(homeOf(live, h), needle) { |
| + got = append(got, h) |
| + } |
| + } |
| + if len(got) == 0 { |
| + return "no home in the table" |
| + } |
| + return strings.Join(got, ", ") |
| +} |