//go:build browser package check import ( "net/http" "testing" "amadan.net/rastrillo/fiesta" "amadan.net/rastrillo/fiesta/example" ) // What the shell drives read. A page under test comes from one of two // places. Where an assertion reads only the slot's content, or shell // structure every shell example carries, the page is a layout example // with content in its slot (shellPage). Where it depends on chrome the // examples do not have (a brand, a nav link's id, the language menu's // id, a view written with whitespace, a layout from before the phone // index) the page is the one rastrillo's drive rendered at the seed // commit, read through fixture or legacyLayout, so the assertion keeps // the page it was written against. // shellPage is the default state of the layout example called // layout- with content in its slot, its asset links rewritten // from the tree's ../../css/… and ../../js/… to the root paths // sizingMux serves (assetLinks), so the page can sit at any path the // drive chooses. func shellPage(t *testing.T, shell, content string) string { t.Helper() name := "layout-" + shell m := manifest(t) state, ok := m.Default(name) if !ok || state == "" { t.Fatalf("examples.json names no default state for %s", name) } doc, err := example.Document(fiesta.FS(), name, state) if err != nil { t.Fatal(err) } page, err := example.Slot(doc, content) if err != nil { t.Fatalf("%s/%s: %v", name, state, err) } return assetLinks(page, "/") } // legacyLayout is a layout as it was before the phone index, rendered // at the seed commit with the drives' standard blocks and kept under // testdata/legacy/ so the legacy rules in tokens.css stay pinned to // real markup. legacyFile (matrix_browser_test.go) does the reading. func legacyLayout(t *testing.T, name string) string { t.Helper() return string(legacyFile(t, name+".html")) } // shellAssets serves pages with everything a layout links. At the // seed commit it added shell.js and shell.css to the sizing mux; // sizingMux serves both here, with every other script in the tree, // so this is the mux under the name the drives call it by. func shellAssets(t *testing.T, pages map[string]string) *http.ServeMux { t.Helper() return sizingMux(t, pages) }