oficina / mapa Public

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

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package mapatest
4
5import (
6 "strings"
7 "testing"
8
9 "amadan.net/rastrillo/rastrillo/harness"
10 "github.com/chromedp/chromedp"
11 "github.com/chromedp/chromedp/kb"
12)
13
14// The History walk (level-up §4.5, L8): from the page, History, a
15// version under its banner, and Restore, with scripts off as with them.
16
17// The File menu and its History: the bar's own History action is
18// hidden at the walk's width, below 800px, as on a phone.
19const (
20 fileMenuOpener = `#mapa-menu-file > summary`
21 fileHistory = `#mapa-menu-file a[href$="/history"]`
22)
23
24// historyAndRestore opens History as a page, chooses the oldest
25// version, sees it under its banner, and restores it.
26func historyAndRestore(t *testing.T, rig *harness.Rig) {
27 path := strings.TrimPrefix(read(t, rig, chromedp.Location()),
28 rig.Origin)
29 drive(t, rig, chromedp.Navigate(rig.Origin+path+"/history"))
30 rig.Screen("aside[mapa-history] a[mapa-ver]", "history")
31 oldest := `aside[mapa-history] li:last-child a[mapa-ver]`
32 if !strings.Contains(text(t, rig, oldest), "Created this page") {
33 t.Fatalf("the oldest version reads %q", text(t, rig, oldest))
34 }
35 drive(t, rig, press(oldest))
36 rig.Screen("[mapa-version-bar]", "a version")
37 if !strings.Contains(text(t, rig, "[mapa-version-bar]"), "version,") {
38 t.Fatal("the version has no banner")
39 }
40 drive(t, rig, press(`[mapa-history-foot] button[rst-btn~="primary"]`),
41 chromedp.WaitNotPresent("[mapa-version-bar]"))
42 rig.Screen("header[mapa-page-head]", "restored")
43 if !strings.Contains(text(t, rig, "main"), "Restored that version") {
44 t.Fatal("Restore did not say it restored the version")
45 }
46}
47
48// historyInPlace opens History from the File menu in place, and Esc
49// closes it with focus back on the menu it came from.
50func historyInPlace(t *testing.T, rig *harness.Rig) {
51 drive(t, rig, press(fileMenuOpener), chromedp.WaitVisible(fileHistory),
52 press(fileHistory))
53 rig.Screen("aside[mapa-history][data-mapa-in-place] a[mapa-ver]",
54 "history in place")
55 focused := read(t, rig, chromedp.Evaluate[string](
56 `document.activeElement.id`))
57 if focused != "mapa-history-title" {
58 t.Fatalf("focus is on %q, not the panel", focused)
59 }
60 drive(t, rig, chromedp.KeyEvent(kb.Escape),
61 chromedp.WaitNotPresent("aside[mapa-history]"))
62 back := read(t, rig, chromedp.Evaluate[bool](
63 `document.activeElement.matches('`+fileMenuOpener+`')`))
64 if !back {
65 t.Fatal("closing History did not give focus back to its menu")
66 }
67}
68