| 1 | package memoriatest |
| 2 | |
| 3 | import ( |
| 4 | "html" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // The typeahead (§8.14), through the real route: the box's one checked |
| 10 | // answer and the documents, never a best guess and never §8.9's model |
| 11 | // step. Until Fable's review (2026-11-02) its only coverage was a browser |
| 12 | // test and the team lapse test, so `make ci` could not see either rule. |
| 13 | // |
| 14 | // MUTATION-TESTED 2026-11-02, each seen red and reverted: the `Guess == |
| 15 | // nil` condition dropped → "a best guess"; /suggest calling Search for |
| 16 | // SearchWhileTyping → "the model was called". |
| 17 | func TestTheTypeaheadNeverGuessesOrCallsTheModel(t *testing.T) { |
| 18 | m := &countingModel{} |
| 19 | h, _ := appWithModel(t, m) |
| 20 | store(t, h, "Reception", "## Front desk\n\nOffice phone: +353 (0)1 547 9999") |
| 21 | store(t, h, "Contacts", "## Phones\n\nReception: +353 (0)1 547 0001\n\nSales: +353 (0)1 547 0002\n\nFax: +353 (0)1 547 0003\n\nSupport: +353 (0)1 547 0004") |
| 22 | |
| 23 | // The presence half: a checked answer is the answer row. |
| 24 | one := get(t, h, "/suggest?q=office+phone") |
| 25 | if b := html.UnescapeString(one.Body.String()); one.Code != 200 || !strings.Contains(b, "rst-suggest-fact") || !strings.Contains(b, "547 9999") { |
| 26 | t.Fatalf("a checked answer is not the typeahead's answer row (%d):\n%s", one.Code, b) |
| 27 | } |
| 28 | |
| 29 | // Four phones and nothing to choose between them: the results page's |
| 30 | // best guess, never the typeahead's answer. |
| 31 | rec := get(t, h, "/suggest?q=phone+number") |
| 32 | b := html.UnescapeString(rec.Body.String()) |
| 33 | if strings.Contains(b, "rst-suggest-fact") { |
| 34 | t.Errorf("the typeahead shows a best guess as its answer:\n%s", b) |
| 35 | } |
| 36 | if !strings.Contains(get(t, h, "/?q=phone+number").Body.String(), "rst-fact-guess") { |
| 37 | t.Fatal("the results page makes no guess here, so the absence above proves nothing") |
| 38 | } |
| 39 | |
| 40 | before := m.calls |
| 41 | get(t, h, "/suggest?q=office+address") |
| 42 | if m.calls != before { |
| 43 | t.Errorf("the model was called %d times by a keystroke; the typeahead never runs §8.9", m.calls-before) |
| 44 | } |
| 45 | } |
| 46 | |