www: fully remove component gallery (#2430)
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
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(<Background title="background" />);
|
||||
const bg = getByTitle("background");
|
||||
const style = bg.getAttribute("style");
|
||||
assertEquals(style, "background-image: url(/gallery/grid.svg);");
|
||||
});
|
||||
});
|
||||
@@ -1,18 +0,0 @@
|
||||
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(
|
||||
<Button value="Click Me!" />,
|
||||
);
|
||||
const button = getByRole("button");
|
||||
assertExists(button);
|
||||
assertEquals((button as HTMLButtonElement).value, "Click Me!");
|
||||
});
|
||||
});
|
||||
@@ -1,17 +0,0 @@
|
||||
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 Carousel from "../../../../www/components/gallery/Carousel.tsx";
|
||||
|
||||
describe("Carousel.tsx", () => {
|
||||
beforeAll(setup);
|
||||
afterEach(cleanup);
|
||||
|
||||
it("should display navigation buttons", () => {
|
||||
const { getAllByRole } = render(
|
||||
<Carousel showNavigation={true} automatic={true} interval={1000} />,
|
||||
);
|
||||
const buttons = getAllByRole("button");
|
||||
assertEquals(buttons.length, 6);
|
||||
});
|
||||
});
|
||||
@@ -1,43 +0,0 @@
|
||||
import { assert } from "$std/testing/asserts.ts";
|
||||
import { cleanup, fireEvent, render, setup } from "$fresh-testing-library";
|
||||
import { afterEach, beforeAll, describe, it } from "$std/testing/bdd.ts";
|
||||
import CodeBox from "$fresh/www/components/gallery/CodeBox.tsx";
|
||||
|
||||
describe("components/gallery/LinkButton.tsx", () => {
|
||||
beforeAll(setup);
|
||||
afterEach(cleanup);
|
||||
|
||||
it("should show Copy button", async () => {
|
||||
const code = "console.log('Hello World')";
|
||||
const { getByText, getByRole, findByText } = render(
|
||||
<CodeBox code={code} />,
|
||||
);
|
||||
// summary
|
||||
assert(getByText("Code"));
|
||||
// button text
|
||||
assert(getByText("Copy"));
|
||||
const button = getByRole("button");
|
||||
// click button, button text should change to "Copied!"
|
||||
fireEvent.click(button);
|
||||
const copied = await findByText("Copied!");
|
||||
assert(copied);
|
||||
});
|
||||
|
||||
it("should show source code", () => {
|
||||
const code = "console.log('Hello World')";
|
||||
const { getByText, getByRole } = render(<CodeBox code={code} />);
|
||||
// find code
|
||||
const codeElement = getByRole("code");
|
||||
const content = codeElement.textContent;
|
||||
// Prism library breaks up code for styling purposes
|
||||
assert(
|
||||
getByText((content) => content.includes("console")),
|
||||
);
|
||||
assert(
|
||||
getByText((content) => content.includes("log")),
|
||||
);
|
||||
assert(
|
||||
getByText((content) => content.includes("Hello World")),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,16 +0,0 @@
|
||||
import { assert } from "$std/testing/asserts.ts";
|
||||
import { cleanup, render, setup } from "$fresh-testing-library";
|
||||
import { afterEach, beforeAll, describe, it } from "$std/testing/bdd.ts";
|
||||
import ColoredButton from "$fresh/www/components/gallery/ColoredButton.tsx";
|
||||
|
||||
describe("components/gallery/ColoredButton.tsx", () => {
|
||||
beforeAll(setup);
|
||||
afterEach(cleanup);
|
||||
|
||||
it("should have disabled set to false", () => {
|
||||
const { getByTitle } = render(<ColoredButton title="colored button" />);
|
||||
const bg = getByTitle("colored button");
|
||||
const disabled = bg.getAttribute("disabled");
|
||||
assert(!disabled);
|
||||
});
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
import { assert, 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 Features from "$fresh/www/components/gallery/Features.tsx";
|
||||
|
||||
describe("components/gallery/Features.tsx", () => {
|
||||
beforeAll(setup);
|
||||
afterEach(cleanup);
|
||||
|
||||
it("should only display 2 links", () => {
|
||||
const screen = render(<Features />);
|
||||
const links = screen.getAllByRole("link");
|
||||
assertEquals(links.length, 2);
|
||||
});
|
||||
|
||||
it("should display all feature descriptions", () => {
|
||||
const screen = render(<Features />);
|
||||
const desc1 = screen.getByText(
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc ut aliquam aliquam",
|
||||
);
|
||||
assert(desc1);
|
||||
const desc2 = screen.getByText(
|
||||
"Nunc nisl aliquet nisl, eget aliquam nisl nisl sit amet lorem. Sed euismod, nunc ut aliquam aliquam, nunc nisl aliquet nisl,",
|
||||
);
|
||||
assert(desc2);
|
||||
const desc3 = screen.getByText(
|
||||
"Eget aliquam nisl nisl sit amet lorem.",
|
||||
);
|
||||
assert(desc3);
|
||||
});
|
||||
});
|
||||
@@ -1,29 +0,0 @@
|
||||
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 Footer from "../../../../www/components/gallery/Footer.tsx";
|
||||
|
||||
describe("Footer.tsx", () => {
|
||||
beforeAll(setup);
|
||||
afterEach(cleanup);
|
||||
|
||||
it("should display text", () => {
|
||||
//@ts-ignore Ignore missing 'children' prop
|
||||
const { getByText, getAllByText } = render(<Footer></Footer>);
|
||||
const fresh = getByText("Fresh");
|
||||
assertEquals(fresh.textContent, "Fresh");
|
||||
const frameworkText = getAllByText("Full Stack Framework");
|
||||
assertExists(frameworkText);
|
||||
});
|
||||
|
||||
it("should display menu", () => {
|
||||
//@ts-ignore Ignore missing 'children' prop
|
||||
const { getByText } = render(<Footer></Footer>);
|
||||
const menu1 = getByText("Getting Started");
|
||||
assertExists(menu1);
|
||||
const menu2 = getByText("Community");
|
||||
assertExists(menu2);
|
||||
const menu3 = getByText("Discord");
|
||||
assertExists(menu3);
|
||||
});
|
||||
});
|
||||
@@ -1,47 +0,0 @@
|
||||
import { assertEquals, fail } from "$std/testing/asserts.ts";
|
||||
import { cleanup, render, setup } from "$fresh-testing-library";
|
||||
import { afterEach, beforeAll, describe, it } from "$std/testing/bdd.ts";
|
||||
import Header from "$fresh/www/components/gallery/Header.tsx";
|
||||
|
||||
describe("components/gallery/Header.tsx", () => {
|
||||
beforeAll(setup);
|
||||
afterEach(cleanup);
|
||||
|
||||
it("should show 2 links", () => {
|
||||
const screen = render(<Header active="" />);
|
||||
const links = screen.getAllByRole("link");
|
||||
assertEquals(links.length, 2);
|
||||
});
|
||||
|
||||
it("should show '/docs' as active", () => {
|
||||
const screen = render(<Header active="/docs" />);
|
||||
const links = screen.getAllByRole("link");
|
||||
let docsActive = false;
|
||||
for (const link of links) {
|
||||
if (link.getAttribute("href") === "/docs") {
|
||||
if (link.classList.contains("border-b-2")) {
|
||||
docsActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!docsActive) {
|
||||
fail("The '/docs' link should be active!!");
|
||||
}
|
||||
});
|
||||
|
||||
it("should show '/docs' as not active", () => {
|
||||
const screen = render(<Header active="/" />);
|
||||
const links = screen.getAllByRole("link");
|
||||
let docsActive = false;
|
||||
for (const link of links) {
|
||||
if (link.getAttribute("href") === "/docs") {
|
||||
if (link.classList.contains("border-b-2")) {
|
||||
docsActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (docsActive) {
|
||||
fail("The '/docs' link should NOT be active!!");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,16 +0,0 @@
|
||||
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 Hero from "$fresh/www/components/gallery/Hero.tsx";
|
||||
|
||||
describe("components/gallery/Hero.tsx", () => {
|
||||
beforeAll(setup);
|
||||
afterEach(cleanup);
|
||||
|
||||
it("should show 2 links", () => {
|
||||
const { getAllByRole } = render(<Hero />);
|
||||
// Two anchor links in component
|
||||
const links = getAllByRole("link");
|
||||
assertEquals(links.length, 2);
|
||||
});
|
||||
});
|
||||
@@ -1,15 +0,0 @@
|
||||
import { assert } from "$std/testing/asserts.ts";
|
||||
import { cleanup, render, setup } from "$fresh-testing-library";
|
||||
import { afterEach, beforeAll, describe, it } from "$std/testing/bdd.ts";
|
||||
import Input from "../../../../www/components/gallery/Input.tsx";
|
||||
|
||||
describe("Input.tsx", () => {
|
||||
beforeAll(setup);
|
||||
afterEach(cleanup);
|
||||
|
||||
it("should be disabled", () => {
|
||||
const screen = render(<Input placeholder="text input" disabled />);
|
||||
const input = screen.getByPlaceholderText("text input");
|
||||
assert((input as HTMLInputElement).disabled);
|
||||
});
|
||||
});
|
||||
@@ -1,63 +0,0 @@
|
||||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertExists,
|
||||
assertFalse,
|
||||
assertStringIncludes,
|
||||
} from "$std/testing/asserts.ts";
|
||||
import { cleanup, fireEvent, render, setup } from "$fresh-testing-library";
|
||||
import { afterEach, beforeAll, describe, it } from "$std/testing/bdd.ts";
|
||||
import LinkButton from "../../../../www/components/gallery/LinkButton.tsx";
|
||||
import IconHeart from "https://deno.land/x/tabler_icons_tsx@0.0.6/tsx/heart.tsx";
|
||||
|
||||
describe("components/gallery/LinkButton.tsx", () => {
|
||||
beforeAll(setup);
|
||||
afterEach(cleanup);
|
||||
|
||||
it("should show link button title", () => {
|
||||
const screen = render(
|
||||
<LinkButton title="Link Button" href="https://google.com" />,
|
||||
);
|
||||
const anchor = screen.getByRole("link");
|
||||
const attr = anchor.getAttribute("title");
|
||||
assertEquals(attr, "Link Button");
|
||||
});
|
||||
|
||||
it("should show link button classes", () => {
|
||||
const screen = render(
|
||||
<LinkButton title="Link Button" href="https://google.com" />,
|
||||
);
|
||||
const anchor = screen.getByRole("link");
|
||||
const classes = anchor.classList;
|
||||
// can only test for twind classes
|
||||
assert(classes.contains("rounded"));
|
||||
assert(classes.contains("bg-white"));
|
||||
});
|
||||
|
||||
it("should show link button text", () => {
|
||||
const screen = render(
|
||||
<LinkButton title="Link Button" href="https://google.com">
|
||||
Click Me!
|
||||
</LinkButton>,
|
||||
);
|
||||
const anchor = screen.getByRole("link");
|
||||
const text = screen.getByText("Click Me!");
|
||||
assertExists(text);
|
||||
});
|
||||
|
||||
it("should render IconHeart component", () => {
|
||||
const screen = render(
|
||||
<LinkButton href="https://google.com">
|
||||
<IconHeart
|
||||
class="w-5 h-5 mr-1 inline-block text-gray-400"
|
||||
aria-hidden="true"
|
||||
title="icon-heart"
|
||||
/>
|
||||
Like me
|
||||
</LinkButton>,
|
||||
);
|
||||
const icon = screen.getByTitle("icon-heart");
|
||||
const hidden = icon.getAttribute("aria-hidden");
|
||||
assert(hidden);
|
||||
});
|
||||
});
|
||||
@@ -1,25 +0,0 @@
|
||||
import { assertExists, assertFalse } from "$std/testing/asserts.ts";
|
||||
import { cleanup, fireEvent, render, setup } from "$fresh-testing-library";
|
||||
import { afterEach, beforeAll, describe, it } from "$std/testing/bdd.ts";
|
||||
import Counter from "../../../www/islands/Counter.tsx";
|
||||
|
||||
describe("islands/Counter.tsx", () => {
|
||||
beforeAll(setup);
|
||||
afterEach(cleanup);
|
||||
|
||||
it("should display count and increment/decrement it correctly", async () => {
|
||||
const count = 9;
|
||||
const screen = render(<Counter start={count} />);
|
||||
const plusOne = screen.getByTitle("Add 1");
|
||||
const minusOne = screen.getByTitle("Subtract 1");
|
||||
assertExists(screen.queryByText("9"));
|
||||
|
||||
await fireEvent.click(plusOne);
|
||||
assertFalse(screen.queryByText("9"));
|
||||
assertExists(screen.queryByText("10"));
|
||||
|
||||
await fireEvent.click(minusOne);
|
||||
assertExists(screen.queryByText("9"));
|
||||
assertFalse(screen.queryByText("10"));
|
||||
});
|
||||
});
|
||||
@@ -1,32 +0,0 @@
|
||||
import { assert, assertExists, assertFalse } from "$std/testing/asserts.ts";
|
||||
import {
|
||||
cleanup,
|
||||
fireEvent,
|
||||
render,
|
||||
setup,
|
||||
} from "$fresh-testing-library/components.ts";
|
||||
import { fn } from "$fresh-testing-library/expect.ts";
|
||||
import { afterEach, beforeAll, describe, it } from "$std/testing/bdd.ts";
|
||||
import SearchButton from "../../../www/islands/SearchButton.tsx";
|
||||
import docsearch from "https://esm.sh/@docsearch/js@3?target=es2020";
|
||||
|
||||
describe("islands/SearchButton.tsx", () => {
|
||||
beforeAll(setup);
|
||||
afterEach(cleanup);
|
||||
|
||||
it("should contain class applied in props", () => {
|
||||
// create mock implementation of docsearch
|
||||
// @ts-ignore mock impl
|
||||
const dsearch = fn(docsearch).mockImplementation((
|
||||
applId: string,
|
||||
apiKey: string,
|
||||
indexName: string,
|
||||
container: HTMLElement | string,
|
||||
) => {});
|
||||
const { getByTitle } = render(
|
||||
<SearchButton class="font-bold" docsearch={dsearch} />,
|
||||
);
|
||||
const search = getByTitle("Search Button");
|
||||
assert(search.classList.contains("font-bold"));
|
||||
});
|
||||
});
|
||||
@@ -1,14 +0,0 @@
|
||||
import { runBuild, waitForText, withPageName } from "../test_utils.ts";
|
||||
|
||||
Deno.test("www - docs navigation", async () => {
|
||||
await runBuild("./www/dev.ts");
|
||||
await withPageName("./www/main.ts", async (page, address) => {
|
||||
await page.goto(`${address}`);
|
||||
|
||||
await page.click(`a[href="/docs"]`);
|
||||
await waitForText(page, "h1", "Introduction");
|
||||
|
||||
await page.click(`a[href="/docs/getting-started/create-a-project"]`);
|
||||
await waitForText(page, "h1", "Create a project");
|
||||
});
|
||||
});
|
||||
@@ -1,35 +0,0 @@
|
||||
import { createHandlerContext } from "$fresh-testing-library/server.ts";
|
||||
import { expect } from "$fresh-testing-library/expect.ts";
|
||||
import { handler } from "../../../www/routes/index.tsx";
|
||||
import manifest from "../../../demo/fresh.gen.ts";
|
||||
|
||||
Deno.test("index.tsx route handler test...", async (t) => {
|
||||
await t.step("should redirect to init.ts", () => {
|
||||
expect(handler.GET).toBeDefined();
|
||||
const req = new Request("http://localhost:8000/");
|
||||
req.headers.set("user-agent", "Chrome");
|
||||
// @ts-ignore manifest typing doesn't matter
|
||||
const ctx = createHandlerContext(req, { manifest });
|
||||
// @ts-ignore handler is not null
|
||||
const resp = handler.GET(req, ctx) as Response;
|
||||
expect(resp.status).toBe(307);
|
||||
expect(resp.headers.get("Location")?.endsWith("init.ts"));
|
||||
});
|
||||
|
||||
await t.step("should not redirect and return status=200", () => {
|
||||
expect(handler.GET).toBeDefined();
|
||||
const req = new Request("http://localhost:8000/");
|
||||
req.headers.set("user-agent", "Chrome");
|
||||
req.headers.set("accept", "text/html");
|
||||
// @ts-ignore manifest typing doesn't matter
|
||||
const ctx = createHandlerContext(req, { manifest });
|
||||
// mock render to return Response-like object
|
||||
// @ts-ignore mock object used
|
||||
ctx.render = () => {
|
||||
return ({ body: "Hello World!", status: 200 });
|
||||
};
|
||||
// @ts-ignore handler is not null
|
||||
const resp = handler.GET(req, ctx) as Response;
|
||||
expect(resp.status).toBe(200);
|
||||
});
|
||||
});
|
||||
@@ -1,14 +0,0 @@
|
||||
import { createMiddlewareHandlerContext } from "$fresh-testing-library/server.ts";
|
||||
import { expect } from "$fresh-testing-library/expect.ts";
|
||||
import { handler } from "../../../www/routes/_middleware.ts";
|
||||
import manifest from "../../../demo/fresh.gen.ts";
|
||||
|
||||
Deno.test("should return middleware status=200 & content-type", async () => {
|
||||
const req = new Request(`http://localhost:3000/`);
|
||||
// @ts-ignore ignores "type ... is not assignable to type Manifest" error
|
||||
const ctx = createMiddlewareHandlerContext(req, { manifest });
|
||||
const resp = await handler(req, ctx);
|
||||
// console.log("Response", resp);
|
||||
expect(resp.status).toBe(200);
|
||||
expect(resp.headers.get("content-type")).toBe("text/plain;charset=UTF-8");
|
||||
});
|
||||
Reference in New Issue
Block a user