| index ba04fc0..11bdad5 100644 |
| --- a/internal/memoriatest/rhythm_browser_test.go |
| +++ b/internal/memoriatest/rhythm_browser_test.go |
| @@ -20,11 +20,20 @@ |
| // root is always walked. Fiesta's own components inside them (a callout, |
| // a table, a list row) are still Fiesta's. |
| // |
| -// The skips, and only these: the document's own text inside the paper |
| -// card ([rst-passage], the renderer's paragraphs, lists, tables and |
| -// quotes, spaced as a document is and not as a screen), and the |
| -// connect pages' and the door's insides, which are estilo's and Home's |
| -// and audited there (estilo 6238a47; Home 8125a3c). |
| +// One skip: the Colophon's list ([estilo-credits]), estilo's template |
| +// and stylesheet, whose h1 and list keep the browser's margins (18.8px); |
| +// that is estilo's to put on a stack. The door's card and the connect |
| +// pages are estilo's too, and opaque here by their estilo- and rst- |
| +// names without a skip; estilo audits its own card (6238a47). |
| +// |
| +// Screens are drawn in the states that change their blocks: the front |
| +// page with recent searches, a fact box, ?explain=facts, an AI answer, |
| +// no results, a document, its delete question, Add content (and with |
| +// its outcome flash), Sources and Notion unconnected and then connected |
| +// with an import behind them and suite apps in each breaker state, a |
| +// correction, Reports with a row, the 👎 page, the Colophon, a 404, and |
| +// team mode's partial lists. Not the upload tray: it is fixed in the |
| +// corner, out of the page's flow. |
| // |
| // Written against origin/main (5d9034d) first, its static/ and |
| // templates/ under this branch's go.mod: 72 findings on 26 of the 34 |
| @@ -61,7 +70,9 @@ import ( |
| "github.com/chromedp/chromedp" |
| |
| memoria "amadan.net/oficina/memoria/internal/memoria" |
| + "amadan.net/oficina/memoria/internal/memoria/notion" |
| "amadan.net/oficina/memoria/internal/memoria/provider" |
| + "amadan.net/oficina/memoria/internal/memoria/sibling" |
| ) |
| |
| // quickAI answers at once, with a paragraph and a list, so the answer |
| @@ -91,6 +102,8 @@ var rhythmRegions = []string{ |
| "[rst-fact-box]", |
| "[rst-paper]", |
| "[rst-correct]", |
| + "[rst-correct-form]", |
| + "[rst-dropzone]", |
| "[rst-sources] > li", |
| "[rst-report]", |
| "[rst-page-footer]", |
| @@ -98,8 +111,6 @@ var rhythmRegions = []string{ |
| |
| // rhythmSkip are the regions whose spacing is not the page's. |
| var rhythmSkip = []string{ |
| - "[rst-passage]", |
| - "[rst-doc-props]", |
| // The Colophon is estilo's template and estilo's stylesheet |
| // (estilo/credits); its h1 and list keep the browser's margins, which |
| // is estilo's to put on its stack. |
| @@ -137,6 +148,12 @@ var settle = evalOnly(`document.fonts.ready.then(() => true)`, func(p *runtime.E |
| // TestEveryScreenKeepsTheRhythm is the audit over every signed-in |
| // screen, at a desktop width and a phone's. |
| func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| + var app interface { |
| + Store() *memoria.Store |
| + UseFakeSource(memoria.SourceClient, func(context.Context, string) (string, error)) |
| + UseSiblings(memoria.Custody) |
| + PreviewUnknownStanding() |
| + } |
| rig := harness.New(t, func(origin string) http.Handler { |
| logger := slog.New(slog.NewTextHandler(io.Discard, nil)) |
| d, err := db.Open(filepath.Join(t.TempDir(), "app.db"), logger) |
| @@ -148,6 +165,7 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| if err != nil { |
| t.Fatalf("AppForTest: %v", err) |
| } |
| + app = a |
| a.UseFakeModel(quickAI{}) |
| for _, doc := range [][2]string{ |
| {"Office", "## Office Address\n\nThe office phone number is: +353 (0)1 547 7854\n\n" + |
| @@ -205,6 +223,27 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| feedback = u.Path |
| } |
| |
| + audit := func(path string, width int64, actions ...chromedp.Action[chromedp.Void]) { |
| + t.Helper() |
| + ctx, cancel := context.WithTimeout(rig.Context(), 30*time.Second) |
| + defer cancel() |
| + err := chromedp.Do(ctx, append([]chromedp.Action[chromedp.Void]{chromedp.EmulateViewport(width, 900)}, append(actions, settle)...)...) |
| + var found []rhythm.Finding |
| + if err == nil { |
| + found, err = auditRhythm(ctx) |
| + } |
| + if err != nil { |
| + t.Fatalf("%s at %dpx: %v", path, width, err) |
| + } |
| + if len(found) > 0 { |
| + t.Errorf("%s at %dpx: %s", path, width, rhythm.Report(found)) |
| + } |
| + } |
| + visit := func(path, ready string, width int64) { |
| + t.Helper() |
| + audit(path, width, chromedp.Navigate(rig.Origin+path), chromedp.WaitVisible(chromedp.CSS(ready))) |
| + } |
| + |
| screens := []struct{ path, ready string }{ |
| {"/", `[rst-home]`}, |
| {"/?q=" + url.QueryEscape("office phone number"), `[rst-fact-box]`}, |
| @@ -225,26 +264,101 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| } |
| for _, width := range []int64{1280, 390} { |
| for _, s := range screens { |
| - ctx, cancel := context.WithTimeout(rig.Context(), 30*time.Second) |
| - err := chromedp.Do(ctx, |
| - chromedp.EmulateViewport(width, 900), |
| - chromedp.Navigate(rig.Origin+s.path), |
| - chromedp.WaitVisible(chromedp.CSS(s.ready)), |
| - settle, |
| - ) |
| - var found []rhythm.Finding |
| - if err == nil { |
| - found, err = auditRhythm(ctx) |
| - } |
| - cancel() |
| - if err != nil { |
| - t.Fatalf("%s at %dpx: %v", s.path, width, err) |
| - } |
| - if len(found) > 0 { |
| - t.Errorf("%s at %dpx: %s", s.path, width, rhythm.Report(found)) |
| - } |
| + visit(s.path, s.ready, width) |
| + } |
| + // Add content with its outcome: the flash under the form. |
| + audit("/add, stored", width, |
| + chromedp.Navigate(rig.Origin+"/add"), |
| + chromedp.WaitVisible(chromedp.CSS(`textarea[name="body"]`)), |
| + chromedp.SendKeys(chromedp.CSS(`textarea[name="body"]`), "The fire drill is on Thursdays."), |
| + chromedp.Click(chromedp.CSS(`[rst-actions] button`)), |
| + chromedp.WaitVisible(chromedp.CSS(`main [rst-callout]`)), |
| + ) |
| + } |
| + |
| + // Sources and Notion connected, with an import behind them, and the |
| + // suite apps in the breaker's three states (tools/drive's seed). |
| + seedRhythmConnector(t, app) |
| + seedRhythmSiblings(t, app) |
| + for _, width := range []int64{1280, 390} { |
| + visit("/connectors/notion", `[rst-facts]`, width) |
| + visit("/connectors", `[rst-source-name]`, width) |
| + } |
| + |
| + // Team mode with the reader's standing unknown: the list pages are |
| + // partial, with the notice. |
| + app.PreviewUnknownStanding() |
| + for _, width := range []int64{1280, 390} { |
| + for _, path := range []string{"/", "/documents", "/reports", "/?q=" + url.QueryEscape("office phone number")} { |
| + visit(path, `main [rst-callout]`, width) |
| + } |
| + } |
| +} |
| + |
| +// rhythmSource is a two-page stand-in for Notion. |
| +type rhythmSource struct{} |
| + |
| +func (rhythmSource) Roots(context.Context) (roots, orphans []notion.Ref, err error) { |
| + return []notion.Ref{{ID: "handbook", Title: "Handbook", EditedTime: "t1", Kind: notion.KindPage}}, nil, nil |
| +} |
| + |
| +func (rhythmSource) Fetch(_ context.Context, ref notion.Ref) (*notion.Content, error) { |
| + c := ¬ion.Content{Markdown: "## " + ref.Title + "\n\nImported for the rhythm audit.", UnreadBlocks: 2} |
| + if ref.ID == "handbook" { |
| + c.Children = []notion.Ref{{ID: "onboarding", Title: "Onboarding", Path: []string{"Handbook"}, EditedTime: "t1", Kind: notion.KindPage}} |
| + } |
| + return c, nil |
| +} |
| + |
| +// seedRhythmConnector connects Notion and runs one import to the end. |
| +func seedRhythmConnector(t *testing.T, app interface { |
| + Store() *memoria.Store |
| + UseFakeSource(memoria.SourceClient, func(context.Context, string) (string, error)) |
| +}) { |
| + t.Helper() |
| + ctx := context.Background() |
| + app.UseFakeSource(rhythmSource{}, func(context.Context, string) (string, error) { return "rhythm-workspace", nil }) |
| + if err := app.Store().SaveConnector(ctx, "notion", "ntn_rhythm_token", "rhythm-workspace"); err != nil { |
| + t.Fatal(err) |
| + } |
| + c, err := app.Store().Connector(ctx, "notion") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + run, err := app.Store().StartRun(ctx, c.ID) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + memoria.NewSyncer(app.Store(), slog.New(slog.NewTextHandler(io.Discard, nil))).RunWith(ctx, rhythmSource{}, c.ID, run.ID) |
| +} |
| + |
| +// seedRhythmSiblings puts three suite apps on Sources, quiet, firing and |
| +// cannot-determine, as tools/drive does. |
| +func seedRhythmSiblings(t *testing.T, app interface { |
| + Store() *memoria.Store |
| + UseSiblings(memoria.Custody) |
| +}) { |
| + t.Helper() |
| + ctx := context.Background() |
| + custody, err := memoria.NewSiblings("rhythm", nil, []sibling.Sibling{ |
| + {Name: "Docs", BaseURL: "https://rhythm.docs.oficina.works", Token: "rhythm"}, |
| + {Name: "Sheets", BaseURL: "https://rhythm.sheets.oficina.works", Token: "rhythm"}, |
| + {Name: "Calendar", BaseURL: "https://rhythm.calendar.oficina.works", Token: "rhythm"}, |
| + }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + app.UseSiblings(custody) |
| + store, now := app.Store(), time.Now().UTC() |
| + for app, since := range map[string]time.Time{"Docs": now.AddDate(0, 0, -30), "Sheets": now.AddDate(0, 0, -30), "Calendar": now.AddDate(0, 0, -2)} { |
| + if err := store.StartCounting(ctx, app, since); err != nil { |
| + t.Fatal(err) |
| } |
| } |
| + for _, who := range []string{"ana@example.com", "ben@example.com", "cleo@example.com"} { |
| + store.SeedTallyForDrive(ctx, "Sheets", who, now.AddDate(0, 0, -3), 5, 0) |
| + store.SeedTallyForDrive(ctx, "Sheets", who, now, 0, 4) |
| + } |
| } |
| |
| // TestTheDoorKeepsTheRhythm: the signed-out pages, drawn through the |