|
| 1 | +open ReactRouter |
| 2 | +open Vitest |
| 3 | + |
| 4 | +@get external textContent: WebAPI.DOMAPI.element => string = "textContent" |
| 5 | + |
| 6 | +let mockCategories: array<SidebarNav.Category.t> = [ |
| 7 | + { |
| 8 | + name: "Overview", |
| 9 | + items: [ |
| 10 | + {name: "Introduction", href: "/docs/manual/introduction"}, |
| 11 | + {name: "Installation", href: "/docs/manual/installation"}, |
| 12 | + ], |
| 13 | + }, |
| 14 | + { |
| 15 | + name: "Language Features", |
| 16 | + items: [ |
| 17 | + {name: "Primitive Types", href: "/docs/manual/primitive-types"}, |
| 18 | + {name: "Record", href: "/docs/manual/record"}, |
| 19 | + {name: "Object", href: "/docs/manual/object"}, |
| 20 | + ], |
| 21 | + }, |
| 22 | +] |
| 23 | + |
| 24 | +let mockToc: TableOfContents.t = { |
| 25 | + title: "Introduction", |
| 26 | + entries: [ |
| 27 | + {header: "What is ReScript", href: "#what-is-rescript"}, |
| 28 | + {header: "Prerequisites", href: "#prerequisites"}, |
| 29 | + {header: "Getting Started", href: "#getting-started"}, |
| 30 | + ], |
| 31 | +} |
| 32 | + |
| 33 | +test("docs layout marks the textual content for DocSearch crawling", async () => { |
| 34 | + await viewport(1440, 900) |
| 35 | + |
| 36 | + let screen = await render( |
| 37 | + <MemoryRouter initialEntries=["/docs/manual/introduction"]> |
| 38 | + <DocsLayout categories=mockCategories activeToc=mockToc docSearchLvl0="Manual"> |
| 39 | + <div> {React.string("This is the documentation content.")} </div> |
| 40 | + </DocsLayout> |
| 41 | + </MemoryRouter>, |
| 42 | + ) |
| 43 | + |
| 44 | + let _mainContent = await screen->getByTestId("side-layout-children") |
| 45 | + |
| 46 | + let mainContent = switch document->WebAPI.Document.querySelector( |
| 47 | + "[data-testid='side-layout-children']", |
| 48 | + ) { |
| 49 | + | Value(element) => element |
| 50 | + | Null => failwith("expected docs layout main content") |
| 51 | + } |
| 52 | + |
| 53 | + let className = switch mainContent->WebAPI.Element.getAttribute("class") { |
| 54 | + | Value(value) => value |
| 55 | + | Null => "" |
| 56 | + } |
| 57 | + |
| 58 | + expect(className->String.includes("DocSearch-content"))->toBe(true) |
| 59 | + |
| 60 | + let lvl0 = switch document->WebAPI.Document.querySelector(".DocSearch-lvl0") { |
| 61 | + | Value(element) => element |
| 62 | + | Null => failwith("expected docs layout to render a DocSearch lvl0 marker") |
| 63 | + } |
| 64 | + |
| 65 | + expect(lvl0->textContent)->toBe("Manual") |
| 66 | +}) |
0 commit comments