Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions apps/docs/__tests__/BlogArticleBehavior_.test.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open ReactRouter
open Vitest

@get external textContent: WebAPI.DOMAPI.element => string = "textContent"
@get external textContent: WebAPI.Element.t => string = "textContent"

let mockAuthor: BlogFrontmatter.author = {
username: "test-author",
Expand Down Expand Up @@ -33,14 +33,18 @@ test("blog article marks body content for DocSearch crawling", async () => {
</MemoryRouter>,
)

switch document->WebAPI.Document.querySelector("article.DocSearch-content") {
switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("article.DocSearch-content") {
| Value(_) => ()
| Null => failwith("expected blog article body to be marked as DocSearch content")
| Null => panic("expected blog article body to be marked as DocSearch content")
}

let lvl0 = switch document->WebAPI.Document.querySelector("article .DocSearch-lvl0") {
let lvl0 = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("article .DocSearch-lvl0") {
| Value(element) => element
| Null => failwith("expected blog article to render a DocSearch lvl0 marker")
| Null => panic("expected blog article to render a DocSearch lvl0 marker")
}

expect(lvl0->textContent)->toBe("Blog")
Expand Down
8 changes: 5 additions & 3 deletions apps/docs/__tests__/BreadcrumbsBehavior_.test.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open ReactRouter
open Vitest

@get external textContent: WebAPI.DOMAPI.element => string = "textContent"
@get external textContent: WebAPI.Element.t => string = "textContent"

test("breadcrumbs do not repeat the current page crumb when it is already included", async () => {
await viewport(1440, 900)
Expand All @@ -21,9 +21,11 @@ test("breadcrumbs do not repeat the current page crumb when it is already includ
)

let _breadcrumbs = await screen->getByTestId("breadcrumbs")
let breadcrumbs = switch document->WebAPI.Document.querySelector("[data-testid='breadcrumbs']") {
let breadcrumbs = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("[data-testid='breadcrumbs']") {
| Value(breadcrumbs) => breadcrumbs
| Null => failwith("expected breadcrumbs")
| Null => panic("expected breadcrumbs")
}

expect(breadcrumbs->textContent)->toBe("Docs / API / Stdlib")
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/__tests__/CommunityLayoutBehavior_.test.res
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module CurrentPage = {
@react.component
let make = () => {
let {pathname} = ReactRouter.useLocation()
<div dataTestId="current-page"> {React.string((pathname :> string))} </div>
<div dataTestId="current-page"> {React.string(pathname :> string)} </div>
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/__tests__/CopyButtons_.test.res
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test(
let button = await screen->getByText("Copy Share Link")
await button->click
await element(button)->toBeDisabled
expect(copied.contents)->toEqual(Some(window.location.href))
expect(copied.contents)->toEqual(Some((WebAPI.DOM.window->WebAPI.Window.location).href))
complete.contents(Error(Clipboard.WriteFailed))
let retry = await screen->getByText("Copy failed, try again")
await element(retry)->notToBeDisabled
Expand Down
16 changes: 9 additions & 7 deletions apps/docs/__tests__/DocsLayoutBehavior_.test.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open ReactRouter
open Vitest

@get external textContent: WebAPI.DOMAPI.element => string = "textContent"
@get external textContent: WebAPI.Element.t => string = "textContent"

let mockCategories: array<SidebarNav.Category.t> = [
{
Expand Down Expand Up @@ -43,11 +43,11 @@ test("docs layout marks the textual content for DocSearch crawling", async () =>

let _mainContent = await screen->getByTestId("side-layout-children")

let mainContent = switch document->WebAPI.Document.querySelector(
"[data-testid='side-layout-children']",
) {
let mainContent = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("[data-testid='side-layout-children']") {
| Value(element) => element
| Null => failwith("expected docs layout main content")
| Null => panic("expected docs layout main content")
}

let className = switch mainContent->WebAPI.Element.getAttribute("class") {
Expand All @@ -57,9 +57,11 @@ test("docs layout marks the textual content for DocSearch crawling", async () =>

expect(className->String.includes("DocSearch-content"))->toBe(true)

let lvl0 = switch document->WebAPI.Document.querySelector(".DocSearch-lvl0") {
let lvl0 = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector(".DocSearch-lvl0") {
| Value(element) => element
| Null => failwith("expected docs layout to render a DocSearch lvl0 marker")
| Null => panic("expected docs layout to render a DocSearch lvl0 marker")
}

expect(lvl0->textContent)->toBe("Manual")
Expand Down
22 changes: 12 additions & 10 deletions apps/docs/__tests__/DocsOverviewBehavior_.test.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@ test("docs overview uses unversioned docs links", async () => {
</MemoryRouter>,
)

let overviewLink = switch document->WebAPI.Document.querySelector(
"a[href='/docs/manual/introduction']",
) {
let overviewLink = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("a[href='/docs/manual/introduction']") {
| Value(link) => link
| Null => failwith("expected docs overview to link to the unversioned manual introduction")
| Null => panic("expected docs overview to link to the unversioned manual introduction")
}
await element(overviewLink)->toBeVisible

let genTypeLink = switch document->WebAPI.Document.querySelector(
"a[href='/docs/manual/typescript-integration']",
) {
let genTypeLink = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("a[href='/docs/manual/typescript-integration']") {
| Value(link) => link
| Null => failwith("expected docs overview to link to the unversioned GenType docs page")
| Null => panic("expected docs overview to link to the unversioned GenType docs page")
}
await element(genTypeLink)->toBeVisible

switch document->WebAPI.Document.querySelector("a[href*='/docs/manual/v']") {
| Value(_) => failwith("expected docs overview to avoid versioned manual links")
switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("a[href*='/docs/manual/v']") {
| Value(_) => panic("expected docs overview to avoid versioned manual links")
| Null => ()
}
})
71 changes: 38 additions & 33 deletions apps/docs/__tests__/LandingPageBehavior_.test.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ open ReactRouter
open Vitest

let getOpenGraphImageUrl = () => {
switch document->WebAPI.Document.querySelector("meta[property='og:image']") {
switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("meta[property='og:image']") {
| Value(meta) =>
switch meta->WebAPI.Element.getAttribute("content") {
| Value(content) => WebAPI.URL.make(~url=content)
| Null => failwith("expected Open Graph image metadata to have content")
| Null => panic("expected Open Graph image metadata to have content")
}
| Null => failwith("expected Open Graph image metadata")
| Null => panic("expected Open Graph image metadata")
}
}

Expand All @@ -22,10 +24,9 @@ test("landing page Open Graph image targets its absolute page URL", async () =>
let imageUrl = getOpenGraphImageUrl()
let targetUrl = switch imageUrl.searchParams
->WebAPI.URLSearchParams.get("url")
->Nullable.make
->Nullable.toOption {
->Null.toOption {
| Some(targetUrl) => WebAPI.URL.make(~url=targetUrl)
| None => failwith("expected Open Graph image URL to include a page URL")
| None => panic("expected Open Graph image URL to include a page URL")
}

expect(imageUrl.origin)->toBe(pageUrl.origin)
Expand All @@ -44,21 +45,22 @@ test(

let _ = await screen->getByText("Edit this example in Playground")

let href = switch document->WebAPI.Document.querySelector("a[href*='/try?code=']") {
let href = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("a[href*='/try?code=']") {
| Value(link) =>
switch link->WebAPI.Element.getAttribute("href") {
| Value(href) => href
| Null => failwith("expected landing page playground link to have an href")
| Null => panic("expected landing page playground link to have an href")
}
| Null => failwith("expected to find the landing page playground link")
| Null => panic("expected to find the landing page playground link")
}

let {pathname, searchParams} = WebAPI.URL.make(~url=href, ~base="https://rescript-lang.org")

expect(pathname)->toBe("/try")

let compressedCode =
searchParams->WebAPI.URLSearchParams.get("code")->Nullable.make->Nullable.toOption
let compressedCode = searchParams->WebAPI.URLSearchParams.get("code")->Null.toOption

let decodedCode =
compressedCode
Expand All @@ -81,18 +83,18 @@ test("landing page playground hero renders highlighted code tokens", async () =>

let _ = await screen->getByText("Write in ReScript")

let rescriptCodeBlock = switch document->WebAPI.Document.querySelector(
"[data-testid='landing-playground-hero'] code.lang-res",
) {
let rescriptCodeBlock = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("[data-testid='landing-playground-hero'] code.lang-res") {
| Value(codeBlock) => codeBlock
| Null => failwith("expected landing playground hero to render the ReScript code block")
| Null => panic("expected landing playground hero to render the ReScript code block")
}

let javascriptCodeBlock = switch document->WebAPI.Document.querySelector(
"[data-testid='landing-playground-hero'] code.lang-js",
) {
let javascriptCodeBlock = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("[data-testid='landing-playground-hero'] code.lang-js") {
| Value(codeBlock) => codeBlock
| Null => failwith("expected landing playground hero to render the JavaScript code block")
| Null => panic("expected landing playground hero to render the JavaScript code block")
}

expect(rescriptCodeBlock.innerHTML->String.includes("<span"))->toBe(true)
Expand Down Expand Up @@ -159,11 +161,11 @@ test(
</MemoryRouter>,
)

let sourceSection = switch document->WebAPI.Document.querySelector(
"[data-testid='landing-playground-hero']",
) {
let sourceSection = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("[data-testid='landing-playground-hero']") {
| Value(section) => section
| Null => failwith("expected to find the landing playground hero section")
| Null => panic("expected to find the landing playground hero section")
}

let sandboxTestId = "landing-playground-hero-sandbox"
Expand All @@ -180,29 +182,32 @@ test(

let _ = await snapshotScreen->getByTestId(sandboxTestId)

let sandbox = switch document->WebAPI.Document.querySelector(
"[data-testid='landing-playground-hero-sandbox']",
) {
let sandbox = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector("[data-testid='landing-playground-hero-sandbox']") {
| Value(sandbox) => sandbox
| Null => failwith("expected to find the sandboxed landing playground hero")
| Null => panic("expected to find the sandboxed landing playground hero")
}

let sandboxRect: WebAPI.DOMAPI.domRect = sandbox->WebAPI.Element.getBoundingClientRect
let sandboxRect: WebAPI.DOM.domRect = sandbox->WebAPI.Element.getBoundingClientRect

let rescriptCodeBlock = switch document->WebAPI.Document.querySelector(
let rescriptCodeBlock = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector(
"[data-testid='landing-playground-hero-sandbox'] code.lang-res",
) {
| Value(codeBlock) => codeBlock
| Null =>
failwith("expected sandboxed landing playground hero to render the ReScript code block")
| Null => panic("expected sandboxed landing playground hero to render the ReScript code block")
}

let javascriptCodeBlock = switch document->WebAPI.Document.querySelector(
let javascriptCodeBlock = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector(
"[data-testid='landing-playground-hero-sandbox'] code.lang-js",
) {
| Value(codeBlock) => codeBlock
| Null =>
failwith("expected sandboxed landing playground hero to render the JavaScript code block")
panic("expected sandboxed landing playground hero to render the JavaScript code block")
}

expect(sandboxRect.width > 1000.0)->toBe(true)
Expand Down
6 changes: 4 additions & 2 deletions apps/docs/__tests__/LandingPageInstallInstructions_.test.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ open Vitest

test("install instructions update their class prop and keep copying available", async () => {
let screen = await render(<LandingPageInstallInstructions className="initial-layout" />)
let root = switch document->WebAPI.Document.querySelector(".initial-layout") {
let root = switch WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector(".initial-layout") {
| Value(root) => root
| Null => failwith("expected the install instructions root")
| Null => panic("expected the install instructions root")
}
await element(root)->toHaveAttribute("class", "w-full max-w-400 initial-layout")

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/__tests__/LandingPagePlaygroundLoader_.test.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test(
~url=data.playgroundHref,
~base="https://rescript-lang.org",
)
let code = searchParams->WebAPI.URLSearchParams.get("code")
let code = searchParams->WebAPI.URLSearchParams.get("code")->Null.getOrThrow

expect(pathname)->toBe("/try")
expect(LzString.lzString.decompressFromEncodedURIComponent(code))->toBe(
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/__tests__/LandingPageVideo_.test.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
open Vitest

let attribute = (selector, name) =>
document
WebAPI.DOM.window
->WebAPI.Window.document
->WebAPI.Document.querySelector(selector)
->Null.toOption
->Option.flatMap(element => element->WebAPI.Element.getAttribute(name)->Null.toOption)
Expand Down
Loading
Loading