| 1 | //go:build browser |
| 2 | |
| 3 | package check |
| 4 | |
| 5 | import ( |
| 6 | "net/http" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/rastrillo/fiesta" |
| 10 | "amadan.net/rastrillo/fiesta/example" |
| 11 | ) |
| 12 | |
| 13 | // What the shell drives read. A page under test comes from one of two |
| 14 | // places. Where an assertion reads only the slot's content, or shell |
| 15 | // structure every shell example carries, the page is a layout example |
| 16 | // with content in its slot (shellPage). Where it depends on chrome the |
| 17 | // examples do not have (a brand, a nav link's id, the language menu's |
| 18 | // id, a view written with whitespace, a layout from before the phone |
| 19 | // index) the page is the one rastrillo's drive rendered at the seed |
| 20 | // commit, read through fixture or legacyLayout, so the assertion keeps |
| 21 | // the page it was written against. |
| 22 | |
| 23 | // shellPage is the default state of the layout example called |
| 24 | // layout-<shell> with content in its slot, its asset links rewritten |
| 25 | // from the tree's ../../css/… and ../../js/… to the root paths |
| 26 | // sizingMux serves (assetLinks), so the page can sit at any path the |
| 27 | // drive chooses. |
| 28 | func shellPage(t *testing.T, shell, content string) string { |
| 29 | t.Helper() |
| 30 | name := "layout-" + shell |
| 31 | m := manifest(t) |
| 32 | state, ok := m.Default(name) |
| 33 | if !ok || state == "" { |
| 34 | t.Fatalf("examples.json names no default state for %s", name) |
| 35 | } |
| 36 | doc, err := example.Document(fiesta.FS(), name, state) |
| 37 | if err != nil { |
| 38 | t.Fatal(err) |
| 39 | } |
| 40 | page, err := example.Slot(doc, content) |
| 41 | if err != nil { |
| 42 | t.Fatalf("%s/%s: %v", name, state, err) |
| 43 | } |
| 44 | return assetLinks(page, "/") |
| 45 | } |
| 46 | |
| 47 | // legacyLayout is a layout as it was before the phone index, rendered |
| 48 | // at the seed commit with the drives' standard blocks and kept under |
| 49 | // testdata/legacy/ so the legacy rules in tokens.css stay pinned to |
| 50 | // real markup. legacyFile (matrix_browser_test.go) does the reading. |
| 51 | func legacyLayout(t *testing.T, name string) string { |
| 52 | t.Helper() |
| 53 | return string(legacyFile(t, name+".html")) |
| 54 | } |
| 55 | |
| 56 | // shellAssets serves pages with everything a layout links. At the |
| 57 | // seed commit it added shell.js and shell.css to the sizing mux; |
| 58 | // sizingMux serves both here, with every other script in the tree, |
| 59 | // so this is the mux under the name the drives call it by. |
| 60 | func shellAssets(t *testing.T, pages map[string]string) *http.ServeMux { |
| 61 | t.Helper() |
| 62 | return sizingMux(t, pages) |
| 63 | } |
| 64 | |