| 1 | //go:build browser |
| 2 | |
| 3 | package mapatest |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | "time" |
| 8 | |
| 9 | "github.com/chromedp/chromedp" |
| 10 | ) |
| 11 | |
| 12 | // The import page's vertical rhythm (Paul, 2026-11-22: "The spacing is |
| 13 | // all over the place here"), held by Fiesta's rhythm audit in every |
| 14 | // state the page has: connect, connected, reading, stopped, writing, |
| 15 | // interrupted, failed and done, and the three confirm pages. In each, |
| 16 | // every gap between two blocks is a step of the spacing scale, no text |
| 17 | // sits closer than --rst-sp-2 to a control, and every heading is closer |
| 18 | // to its own content than to the block before it. |
| 19 | |
| 20 | // importRhythmSkip is what the audit leaves alone on the import page: |
| 21 | // rst-form is Fiesta's form, whose rhythm (and the extra air above its |
| 22 | // closing row) is Fiesta's to set and its own gates' to check. |
| 23 | var importRhythmSkip = []string{"[rst-form]"} |
| 24 | |
| 25 | func TestImportPageRhythm(t *testing.T) { |
| 26 | rig, server, database := importRig(t) |
| 27 | rig.Run(scripts(false)) |
| 28 | page := rig.Origin + "/import/notion" |
| 29 | audit := func(stage string) { |
| 30 | auditRhythm(t, rig, stage, importRhythmSkip) |
| 31 | } |
| 32 | drive(t, rig, chromedp.Navigate(page)) |
| 33 | audit("connect") |
| 34 | drive(t, rig, chromedp.SendKeys(`input[name="token"]`, "secret_test"), |
| 35 | press(`form[action="/import/notion/connect"] button`), |
| 36 | chromedp.WaitVisible(`form[action="/import/notion/start"]`)) |
| 37 | audit("connected") |
| 38 | server.Lock() |
| 39 | drive(t, rig, press(`form[action="/import/notion/start"] button`), |
| 40 | chromedp.WaitVisible(`form[action="/import/notion/stop"]`)) |
| 41 | audit("reading") |
| 42 | drive(t, rig, press(`form[action="/import/notion/stop"] button`), |
| 43 | chromedp.WaitVisible(`form[action="/import/notion/resume"]`)) |
| 44 | server.Unlock() |
| 45 | audit("stopped") |
| 46 | now := time.Now().UTC() |
| 47 | for _, state := range []string{"writing", "interrupted", "failed"} { |
| 48 | database().Exec("UPDATE notion_runs SET state = ?, total = 5,"+ |
| 49 | " written = 2, error_code = 'unauthorized', heartbeat_at = ?,"+ |
| 50 | " progress_at = ?", state, now, now) |
| 51 | drive(t, rig, chromedp.Navigate(page)) |
| 52 | audit(state) |
| 53 | } |
| 54 | database().Exec("UPDATE notion_runs SET state = 'stopped', total = 0," + |
| 55 | " written = 0, error_code = ''") |
| 56 | drive(t, rig, chromedp.Navigate(page), |
| 57 | press(`form[action="/import/notion/resume"] button`)) |
| 58 | waitFor(t, rig, "Run complete") |
| 59 | audit("done") |
| 60 | for _, act := range []string{"finish", "disconnect", "forget"} { |
| 61 | drive(t, rig, chromedp.Navigate(page+"/"+act)) |
| 62 | audit("confirm " + act) |
| 63 | } |
| 64 | } |
| 65 | |