//go:build browser // The whole result opens it (Paul, 2026-10-26: "Can the whole segment be // clickable rather than just the title?"), without taking away text // selection in the snippet (review, 2026-10-26: a stretched overlay made // a double-click select nothing). Run with `make browser`. // // MUTATION-TESTED 2026-10-26, each reverted: the click handler removed → // "clicking the second result's snippet left the page at …"; the // destination taken from the first result → "went to …/documents/2#p0, // want the second result's document"; the selection check when the wait // ends removed → "a double-click to select a word left the page". A // dblclick listener and a second-click cancel were each mutated away and // stayed green beside that check, so both were deleted. package memoriatest import ( "context" "io" "log/slog" "net/http" "path/filepath" "strings" "testing" "time" "amadan.net/rastrillo/rastrillo/db" "amadan.net/rastrillo/rastrillo/harness" "github.com/chromedp/chromedp" memoria "amadan.net/oficina/memoria/internal/memoria" ) func TestTheWholeResultIsALink(t *testing.T) { 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) if err != nil { t.Fatalf("db.Open: %v", err) } t.Cleanup(func() { d.Close() }) mux, a, err := memoria.AppForTest(d, origin, testDEK(t), logger) if err != nil { t.Fatalf("AppForTest: %v", err) } for _, doc := range [][2]string{ {"Office", "## Office Maintenance\n\nAlan Brady works for the management agency and can be contacted any weekday."}, {"Kitchen", "## Supplies\n\nThe agency restocks the kitchen every Monday morning before nine."}, } { if _, err := a.Store().Ingest(context.Background(), memoria.IngestSpec{ Source: "upload", Key: doc[0], Title: doc[0], Body: doc[1], }); err != nil { t.Fatal(err) } } return mux }) run := func(what string, actions ...chromedp.Action[chromedp.Void]) { t.Helper() ctx, cancel := context.WithTimeout(rig.Context(), 20*time.Second) defer cancel() if err := chromedp.Do(ctx, actions...); err != nil { t.Fatalf("%s: %v", what, err) } } search := rig.Origin + "/?q=agency" // Each result opens its own document: the second's snippet goes to // the second's title link, not the first's. var want, at string run("click the second result", chromedp.Navigate(search), chromedp.WaitVisible(chromedp.CSS(`[rst-result]:nth-child(2) [rst-result-snippet]`)), attributeInto(chromedp.CSS(`[rst-result]:nth-child(2) [rst-result-title]`), "href", &want, nil), chromedp.Click(chromedp.CSS(`[rst-result]:nth-child(2) [rst-result-snippet]`)), chromedp.Sleep(800*time.Millisecond), locationInto(&at), ) if !strings.Contains(at, "/documents/") { t.Fatalf("clicking the second result's snippet left the page at %s", at) } if !strings.HasSuffix(at, want) { t.Errorf("went to %s, want the second result's document %s", at, want) } // A double-click selects a word and goes nowhere. var picked string run("double-click a word", chromedp.Navigate(search), chromedp.WaitVisible(chromedp.CSS(`[rst-result-snippet]`)), // A real double-click is two clicks: the first with a click // count of one, then the second with two. chromedp's DoubleClick // sends only the second, which skips the very path under test. chromedp.Click(chromedp.CSS(`[rst-result-snippet] mark`)), chromedp.DoubleClick(chromedp.CSS(`[rst-result-snippet] mark`)), chromedp.Sleep(800*time.Millisecond), evalInto(&picked, `String(window.getSelection())`), locationInto(&at), ) if strings.Contains(at, "/documents/") { t.Errorf("a double-click to select a word left the page for %s", at) } if strings.TrimSpace(picked) == "" { t.Error("a double-click selected nothing") } // Outside a result, a click is just a click. run("click the heading", chromedp.Navigate(search), chromedp.WaitVisible(chromedp.CSS(`h2`)), chromedp.Click(chromedp.CSS(`h2`)), chromedp.Sleep(800*time.Millisecond), locationInto(&at), ) if strings.Contains(at, "/documents/") { t.Errorf("a click on the heading left the page for %s", at) } }