From b5816cd001308533319fcd61b0bfef396e4228dd Mon Sep 17 00:00:00 2001 From: Craig Doremus <942174+cdoremus@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:25:13 -0500 Subject: [PATCH] feat(tests): add `fresh-testing-library` tests (#1990) --- .vscode/import_map.json | 4 +- deno.json | 3 +- .../components/gallery/Background.test.tsx | 16 +++++ tests/www/components/gallery/Button.test.tsx | 18 ++++++ .../www/components/gallery/Carousel.test.tsx | 17 +++++ tests/www/components/gallery/CodeBox.test.tsx | 43 +++++++++++++ .../components/gallery/ColoredButton.test.tsx | 16 +++++ .../www/components/gallery/Features.test.tsx | 31 +++++++++ tests/www/components/gallery/Footer.test.tsx | 29 +++++++++ tests/www/components/gallery/Header.test.tsx | 47 ++++++++++++++ tests/www/components/gallery/Hero.test.tsx | 16 +++++ tests/www/components/gallery/Input.test.tsx | 15 +++++ .../components/gallery/LinkButton.test.tsx | 63 +++++++++++++++++++ tests/www/islands/Counter.test.tsx | 25 ++++++++ tests/www/islands/SearchButton.test.tsx | 32 ++++++++++ tests/www/routes/index.test.tsx | 37 +++++++++++ tests/www/routes/routes.middleware.test.tsx | 14 +++++ www/components/DocsSidebar.tsx | 3 +- www/deno.json | 4 +- www/islands/SearchButton.tsx | 22 +++++-- 20 files changed, 447 insertions(+), 8 deletions(-) create mode 100644 tests/www/components/gallery/Background.test.tsx create mode 100644 tests/www/components/gallery/Button.test.tsx create mode 100644 tests/www/components/gallery/Carousel.test.tsx create mode 100644 tests/www/components/gallery/CodeBox.test.tsx create mode 100644 tests/www/components/gallery/ColoredButton.test.tsx create mode 100644 tests/www/components/gallery/Features.test.tsx create mode 100644 tests/www/components/gallery/Footer.test.tsx create mode 100644 tests/www/components/gallery/Header.test.tsx create mode 100644 tests/www/components/gallery/Hero.test.tsx create mode 100644 tests/www/components/gallery/Input.test.tsx create mode 100644 tests/www/components/gallery/LinkButton.test.tsx create mode 100644 tests/www/islands/Counter.test.tsx create mode 100644 tests/www/islands/SearchButton.test.tsx create mode 100644 tests/www/routes/index.test.tsx create mode 100644 tests/www/routes/routes.middleware.test.tsx diff --git a/.vscode/import_map.json b/.vscode/import_map.json index a9b65fe7..1e99475a 100644 --- a/.vscode/import_map.json +++ b/.vscode/import_map.json @@ -14,6 +14,8 @@ "@preact/signals-core@1.3.0": "https://esm.sh/@preact/signals-core@1.3.0", "$std/": "https://deno.land/std@0.205.0/", "$ga4": "https://raw.githubusercontent.com/denoland/ga4/main/mod.ts", - "$marked-mangle": "https://esm.sh/marked-mangle@1.0.1" + "$marked-mangle": "https://esm.sh/marked-mangle@1.0.1", + "$fresh-testing-library": "https://deno.land/x/fresh_testing_library@0.11.1/mod.ts", + "$fresh-testing-library/": "https://deno.land/x/fresh_testing_library@0.11.1/" } } diff --git a/deno.json b/deno.json index 44b8c0a2..f51c6eb2 100644 --- a/deno.json +++ b/deno.json @@ -7,7 +7,8 @@ "screenshot": "deno run -A www/utils/screenshot.ts", "check:types": "deno check **/*.ts && deno check **/*.tsx", "ok": "deno fmt --check && deno lint && deno task check:types && deno task test", - "install-puppeteer": "PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/install.ts && PUPPETEER_PRODUCT=firefox deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/install.ts" + "install-puppeteer": "PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/install.ts && PUPPETEER_PRODUCT=firefox deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/install.ts", + "test:www": "deno test -A tests/www/" }, "exclude": [ "**/_fresh/*", diff --git a/tests/www/components/gallery/Background.test.tsx b/tests/www/components/gallery/Background.test.tsx new file mode 100644 index 00000000..a0c9e884 --- /dev/null +++ b/tests/www/components/gallery/Background.test.tsx @@ -0,0 +1,16 @@ +import { assertEquals } from "$std/testing/asserts.ts"; +import { cleanup, render, setup } from "$fresh-testing-library"; +import { afterEach, beforeAll, describe, it } from "$std/testing/bdd.ts"; +import Background from "$fresh/www/components/gallery/Background.tsx"; + +describe("components/gallery/Background.tsx", () => { + beforeAll(setup); + afterEach(cleanup); + + it("should display background image", () => { + const { getByTitle } = render(); + const bg = getByTitle("background"); + const style = bg.getAttribute("style"); + assertEquals(style, "background-image: url(/gallery/grid.svg);"); + }); +}); diff --git a/tests/www/components/gallery/Button.test.tsx b/tests/www/components/gallery/Button.test.tsx new file mode 100644 index 00000000..537db63f --- /dev/null +++ b/tests/www/components/gallery/Button.test.tsx @@ -0,0 +1,18 @@ +import { assertEquals, assertExists } from "$std/testing/asserts.ts"; +import { cleanup, render, setup } from "$fresh-testing-library"; +import { afterEach, beforeAll, describe, it } from "$std/testing/bdd.ts"; +import Button from "../../../../www/components/gallery/Button.tsx"; + +describe("components/gallery/LinkButton.tsx", () => { + beforeAll(setup); + afterEach(cleanup); + + it("should show button", () => { + const { getByRole } = render( +