| index ec3f2c2..112cae6 100644 |
| --- a/internal/slidestest/editor_tidy_test.go |
| +++ b/internal/slidestest/editor_tidy_test.go |
| @@ -65,6 +65,9 @@ func TestEditorTidyDeskIsEstilos(t *testing.T) { |
| if strings.Contains(rule, "gradient") { |
| t.Errorf("the deck list's ground still has a gradient:\n%s", rule) |
| } |
| + if !strings.Contains(rule, "var(--slides-desk)") { |
| + t.Errorf("the deck list's ground does not read var(--slides-desk):\n%s", rule) |
| + } |
| } |
| |
| func readStatic(t *testing.T, name string) string { |
| @@ -93,7 +96,11 @@ func TestEditorTidyNewSlideInStripFoot(t *testing.T) { |
| } |
| foot := regexp.MustCompile(`(?s)</ol>\s*<div slides-strip-foot>\s*<div slides-strip-add>`).FindStringIndex(nav) |
| if foot == nil { |
| - t.Errorf("[slides-strip-add] is not the first thing in a <div slides-strip-foot> after the list:\n%s", nav[strings.LastIndex(nav, "</ol>"):]) |
| + tail := nav |
| + if i := strings.LastIndex(nav, "</ol>"); i >= 0 { |
| + tail = nav[i:] |
| + } |
| + t.Errorf("[slides-strip-add] is not the first thing in a <div slides-strip-foot> after the list:\n%s", tail) |
| } |
| } |
| |
| @@ -715,3 +722,165 @@ func TestEditorTidyBarControls(t *testing.T) { |
| t.Errorf("undo and redo share the name %q", buttons[0][2]) |
| } |
| } |
| + |
| +// readSource is a file of the slides package, by its path under |
| +// internal/slides. |
| +func readSource(t *testing.T, name string) string { |
| + t.Helper() |
| + b, err := os.ReadFile(filepath.Join("..", "slides", filepath.FromSlash(name))) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return string(b) |
| +} |
| + |
| +// goStrings is the quoted strings of the Go var declared as |
| +// `var name = []string{…}` in src. |
| +func goStrings(t *testing.T, src, name string) []string { |
| + t.Helper() |
| + block := regexp.MustCompile(`(?s)var ` + name + ` = \[\]string\{(.*?)\}`).FindStringSubmatch(src) |
| + if block == nil { |
| + t.Fatalf("editor.go declares no var %s = []string{…}", name) |
| + } |
| + var out []string |
| + for _, m := range regexp.MustCompile(`"([^"]*)"`).FindAllStringSubmatch(block[1], -1) { |
| + out = append(out, m[1]) |
| + } |
| + return out |
| +} |
| + |
| +// TestEditorTidyStrings: the strings of the tidied editor are catalog |
| +// keys, each in en.toml with the strings table's English and in |
| +// editorStrings; every key in editorStrings is read (by editor.html |
| +// through L, by its add-block menus as type.<block type>, or by |
| +// editor.go itself through page.S); every key editor.html reads is in |
| +// editorStrings; and the keys the old inspector and notes switch read |
| +// are gone from both. The table's group labels that already had a key |
| +// with the same English reuse it: Text is format.label, Alignment |
| +// block.align, On a phone block.phone and Deck inspector.deck. |
| +func TestEditorTidyStrings(t *testing.T) { |
| + toml := readSource(t, "locales/en.toml") |
| + catalog := map[string]string{} |
| + for _, m := range regexp.MustCompile(`(?m)^slides\.editor\.(\S+) = "(.*)"$`).FindAllStringSubmatch(toml, -1) { |
| + catalog[m[1]] = m[2] |
| + } |
| + src := readSource(t, "editor.go") |
| + listed := map[string]bool{} |
| + keys := goStrings(t, src, "editorStrings") |
| + for _, k := range keys { |
| + listed[k] = true |
| + } |
| + |
| + for _, c := range []struct{ key, english string }{ |
| + {"head.format", "Format"}, |
| + {"notes.title", "Notes"}, |
| + {"notes.close", "Close notes"}, |
| + {"notes.open", "Show notes"}, |
| + {"notes.open.has", "Show notes (this slide has notes)"}, |
| + {"notes.resize", "Resize notes"}, |
| + {"view.both.title", "Both, side by side"}, |
| + {"group.style", "Style"}, |
| + {"group.image", "Image"}, |
| + {"group.description", "Description"}, |
| + {"group.place", "Place"}, |
| + {"group.boxes", "Boxes"}, |
| + {"group.slide", "This slide"}, |
| + // reused, not new |
| + {"format.label", "Text"}, |
| + {"block.align", "Alignment"}, |
| + {"block.phone", "On a phone"}, |
| + {"inspector.deck", "Deck"}, |
| + } { |
| + if got, ok := catalog[c.key]; !ok { |
| + t.Errorf("en.toml has no slides.editor.%s", c.key) |
| + } else if got != c.english { |
| + t.Errorf("slides.editor.%s is %q, want %q", c.key, got, c.english) |
| + } |
| + if !listed[c.key] { |
| + t.Errorf("editorStrings does not list %s", c.key) |
| + } |
| + } |
| + |
| + // Each group in the card is labelled by the key the table gives it. |
| + tmpl := readSource(t, "templates/editor.html") |
| + for group, key := range map[string]string{ |
| + "slide": "group.slide", "boxes": "group.boxes", "deck": "inspector.deck", |
| + "style": "group.style", "text": "format.label", "alignment": "block.align", |
| + "image": "group.image", "description": "group.description", "place": "group.place", |
| + "phone": "block.phone", |
| + } { |
| + label := `<span estilo-inspector-label id="slides-g-` + group + `">{{.L "` + key + `"}}</span>` |
| + if !strings.Contains(tmpl, label) { |
| + t.Errorf("editor.html has no %s", label) |
| + } |
| + } |
| + |
| + // Every listed key is read, and every key read is listed. |
| + read := map[string]bool{} |
| + for _, m := range regexp.MustCompile(`\.L "([^"]+)"`).FindAllStringSubmatch(tmpl, -1) { |
| + read[m[1]] = true |
| + } |
| + for _, m := range regexp.MustCompile(`\.L \(printf "([^"%]*)%s" \.\)`).FindAllStringSubmatch(tmpl, -1) { |
| + for _, b := range goStrings(t, src, "blockTypes") { |
| + read[m[1]+b] = true |
| + } |
| + } |
| + for _, m := range regexp.MustCompile(`page\.S\["([^"]+)"\]`).FindAllStringSubmatch(src, -1) { |
| + read[m[1]] = true |
| + } |
| + for _, k := range keys { |
| + if !read[k] { |
| + t.Errorf("editorStrings lists %s, which nothing reads", k) |
| + } |
| + if _, ok := catalog[k]; !ok { |
| + t.Errorf("editorStrings lists %s, which en.toml does not define", k) |
| + } |
| + } |
| + for _, m := range regexp.MustCompile(`\.L "([^"]+)"`).FindAllStringSubmatch(tmpl, -1) { |
| + if !listed[m[1]] { |
| + t.Errorf("editor.html reads %s, which editorStrings does not list", m[1]) |
| + } |
| + } |
| + |
| + // The old inspector's and the notes switch's keys are gone. |
| + for _, k := range []string{"head.inspector", "inspector", "inspector.empty", "inspector.slide", "inspector.block", "inspector.blocks", "slide.notes.show"} { |
| + if _, ok := catalog[k]; ok { |
| + t.Errorf("en.toml still defines slides.editor.%s", k) |
| + } |
| + if listed[k] { |
| + t.Errorf("editorStrings still lists %s", k) |
| + } |
| + } |
| + |
| + // The view switch is icons now; the catalog's note on it says so. |
| + if strings.Contains(toml, "never icons alone") { |
| + t.Error("en.toml still says the view switch is words, never icons alone") |
| + } |
| +} |
| + |
| +// TestEditorTidyNoDeadSelectors: what the inspector's <details>, its |
| +// off switch and the notes switch were drawn and wired by is gone from |
| +// the stylesheet and the bundle's sources; and the view switch's first |
| +// corner is estilo's, which rounds the first segment after a <legend>. |
| +func TestEditorTidyNoDeadSelectors(t *testing.T) { |
| + files := []string{filepath.Join("..", "slides", "static", "editor.css"), filepath.Join("..", "..", "fixtures", "editor-entry.js")} |
| + mjs, err := filepath.Glob(filepath.Join("..", "..", "fixtures", "*.mjs")) |
| + if err != nil || len(mjs) == 0 { |
| + t.Fatalf("no fixtures/*.mjs (%v)", err) |
| + } |
| + files = append(files, mjs...) |
| + for _, f := range files { |
| + b, err := os.ReadFile(f) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, dead := range []string{"data-inspector-off", "slides-notes-toggle", "details[slides-inspector]"} { |
| + if strings.Contains(string(b), dead) { |
| + t.Errorf("%s still mentions %s", filepath.Base(f), dead) |
| + } |
| + } |
| + } |
| + if regexp.MustCompile(`\[slides-switcher\][^{]*nth-child`).MatchString(readStatic(t, "editor.css")) { |
| + t.Error("static/editor.css still rounds the view switch's first segment itself (estilo does)") |
| + } |
| +} |