//go:build browser package mapatest import ( "strings" "testing" "amadan.net/rastrillo/rastrillo/harness" "github.com/chromedp/chromedp" "github.com/chromedp/chromedp/kb" ) // The History walk (level-up ยง4.5, L8): from the page, History, a // version under its banner, and Restore, with scripts off as with them. // The File menu and its History: the bar's own History action is // hidden at the walk's width, below 800px, as on a phone. const ( fileMenuOpener = `#mapa-menu-file > summary` fileHistory = `#mapa-menu-file a[href$="/history"]` ) // historyAndRestore opens History as a page, chooses the oldest // version, sees it under its banner, and restores it. func historyAndRestore(t *testing.T, rig *harness.Rig) { path := strings.TrimPrefix(read(t, rig, chromedp.Location()), rig.Origin) drive(t, rig, chromedp.Navigate(rig.Origin+path+"/history")) rig.Screen("aside[mapa-history] a[mapa-ver]", "history") oldest := `aside[mapa-history] li:last-child a[mapa-ver]` if !strings.Contains(text(t, rig, oldest), "Created this page") { t.Fatalf("the oldest version reads %q", text(t, rig, oldest)) } drive(t, rig, press(oldest)) rig.Screen("[mapa-version-bar]", "a version") if !strings.Contains(text(t, rig, "[mapa-version-bar]"), "version,") { t.Fatal("the version has no banner") } drive(t, rig, press(`[mapa-history-foot] button[rst-btn~="primary"]`), chromedp.WaitNotPresent("[mapa-version-bar]")) rig.Screen("header[mapa-page-head]", "restored") if !strings.Contains(text(t, rig, "main"), "Restored that version") { t.Fatal("Restore did not say it restored the version") } } // historyInPlace opens History from the File menu in place, and Esc // closes it with focus back on the menu it came from. func historyInPlace(t *testing.T, rig *harness.Rig) { drive(t, rig, press(fileMenuOpener), chromedp.WaitVisible(fileHistory), press(fileHistory)) rig.Screen("aside[mapa-history][data-mapa-in-place] a[mapa-ver]", "history in place") focused := read(t, rig, chromedp.Evaluate[string]( `document.activeElement.id`)) if focused != "mapa-history-title" { t.Fatalf("focus is on %q, not the panel", focused) } drive(t, rig, chromedp.KeyEvent(kb.Escape), chromedp.WaitNotPresent("aside[mapa-history]")) back := read(t, rig, chromedp.Evaluate[bool]( `document.activeElement.matches('`+fileMenuOpener+`')`)) if !back { t.Fatal("closing History did not give focus back to its menu") } }