diff --git a/src/components/Heading.tsx b/src/components/Heading.tsx new file mode 100644 index 0000000..8825751 --- /dev/null +++ b/src/components/Heading.tsx @@ -0,0 +1,58 @@ +import { JSX } from "preact"; + +type HeadingProps = { + variant: "h1" | "h2" | "h3" | "h4" | "h5" | "h6"; + text: string; +} & JSX.HTMLAttributes; + +export function Heading({ variant, text, ...props }: HeadingProps) { + if (variant === "h1") { + return ( +

+ {text} +

+ ); + } + + if (variant === "h2") { + return ( +

+ {text} +

+ ); + } + + if (variant === "h3") { + return ( +

+ {text} +

+ ); + } + + if (variant === "h4") { + return ( +

+ {text} +

+ ); + } + + if (variant === "h5") { + return ( +
+ {text} +
+ ); + } + + if (variant === "h6") { + return ( +
+ {text} +
+ ); + } + + return
; +} diff --git a/src/routes/about.tsx b/src/routes/about.tsx index 3b3045e..98c7893 100644 --- a/src/routes/about.tsx +++ b/src/routes/about.tsx @@ -1,6 +1,7 @@ import { Handlers, PageProps, RouteContext } from "$fresh/server.ts"; import { Partial } from "$fresh/runtime.ts"; import NextContentButton from "#src/islands/NextContentButton.tsx"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; const loadFooValue = () => { @@ -34,14 +35,16 @@ export default async function AboutPage(props: PageProps, ctx: RouteContext) { return (
-

About

-

This is the about page.

- -
You are on the page '{props.url.href}'.
-

foo is: {value}

-
-
- + +
+

This is the about page.

+ +
You are on the page '{props.url.href}'.
+

foo is: {value}

+
+
+ +
diff --git a/src/routes/chart.tsx b/src/routes/chart.tsx index 0b67685..b21c2dd 100644 --- a/src/routes/chart.tsx +++ b/src/routes/chart.tsx @@ -1,5 +1,6 @@ import ChartIsland from "#src/islands/Chart.tsx"; import { ChartColors } from "$fresh_charts/utils.ts"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; const createRandomNumber = () => { @@ -13,7 +14,7 @@ const createChartNumberArray = () => { export default function Home() { return ( -

Chart

+
{ date.setHours(date.getHours() + 1); return ( +

Count Down

The big event is happening . diff --git a/src/routes/greet/[name].tsx b/src/routes/greet/[name].tsx index fde67a7..e542b42 100644 --- a/src/routes/greet/[name].tsx +++ b/src/routes/greet/[name].tsx @@ -1,5 +1,6 @@ import { Head } from "$fresh/runtime.ts"; import { PageProps, RouteConfig } from "$fresh/server.ts"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; export const config: RouteConfig = { @@ -16,7 +17,7 @@ export default function GreetPage(props: PageProps) {

-

Greetings to you, {name}!

+

This page is not{" "} applied layout because I want to check ignore layout config. diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 77f0b00..05a5baf 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -1,6 +1,7 @@ import { Handlers, PageProps, RouteConfig } from "$fresh/server.ts"; import { type ContentSecurityPolicy, useCSP } from "$fresh/runtime.ts"; import { useSignal } from "@preact/signals"; +import { Heading } from "#src/components/Heading.tsx"; import { Link } from "#src/components/Link.tsx"; import Counter from "#src/islands/Counter.tsx"; @@ -59,15 +60,16 @@ export default function Home({ data }: PageProps) { src="/logo.svg" alt="the Fresh logo: a sliced lemon dripping with juice" /> -

Nyaomaru Deno Sample

-

I am a cat being!!

-
-
-

- Counter -

+
+ +
+

I am a cat being!!

+
+ +
+

@@ -77,17 +79,15 @@ export default function Home({ data }: PageProps) {

-
-

- Page Buttons -

+
+
-
+
{ return ( - + +
+ +
); }); diff --git a/src/routes/markdowns/[slug].tsx b/src/routes/markdowns/[slug].tsx index d4293e1..161e8ea 100644 --- a/src/routes/markdowns/[slug].tsx +++ b/src/routes/markdowns/[slug].tsx @@ -2,6 +2,7 @@ import { Handlers, PageProps } from "$fresh/server.ts"; import { extract } from "$std/front_matter/yaml.ts"; import { CSS, render } from "$gfm"; import { Head } from "$fresh/runtime.ts"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; const markdownText = `--- @@ -64,11 +65,14 @@ export default function MarkdownPage({ data }: PageProps) {
-
{JSON.stringify(data.data)}
-
+ +
+
{JSON.stringify(data.data)}
+
+
diff --git a/src/routes/partials/about/[id].tsx b/src/routes/partials/about/[id].tsx index fbdf14a..47e45cc 100644 --- a/src/routes/partials/about/[id].tsx +++ b/src/routes/partials/about/[id].tsx @@ -1,5 +1,6 @@ import { defineRoute, RouteConfig } from "$fresh/server.ts"; import { Partial } from "$fresh/runtime.ts"; +import { Heading } from "#src/components/Heading.tsx"; const contents = [ "This is the documentation page. It should contain all the \n information you need to get started with the project.", @@ -11,7 +12,7 @@ const loadContent = (id: string) => { return (
-

Documentation: {id}

+

{currentContent}

diff --git a/src/routes/projects/[id].tsx b/src/routes/projects/[id].tsx index 80768c8..9c02d6e 100644 --- a/src/routes/projects/[id].tsx +++ b/src/routes/projects/[id].tsx @@ -1,4 +1,5 @@ import { Handlers, PageProps } from "$fresh/server.ts"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; const projects = [{ id: 1, name: "Project 1", stars: 10 }, { @@ -36,8 +37,12 @@ export default function ProjectPage(props: PageProps) { return ( -

{props.data.name}

-

{props.data.stars} stars

+ + +
+ +

{props.data.stars} stars

+
); } diff --git a/src/routes/search.tsx b/src/routes/search.tsx index 48cfcf7..1571f1d 100644 --- a/src/routes/search.tsx +++ b/src/routes/search.tsx @@ -1,4 +1,5 @@ import { Handlers, PageProps } from "$fresh/server.ts"; +import { Heading } from "#src/components/Heading.tsx"; import { PageLayout } from "#src/components/PageLayout.tsx"; const NAMES = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Frank"]; @@ -21,7 +22,7 @@ export default function Page({ data }: PageProps) { const { results, query } = data; return ( -

Search

+
Promise, + pageUrl: string, + expectedText: string, +) => { + const resp = await handler( + new Request(`http://127.0.0.1/${pageUrl}`), + CONN_INFO, + ); + const text = await resp.text(); + modAssert.assert(text.includes(expectedText)); +}; + Deno.test("HTTP assert test.", async (t) => { const handler = await createHandler(manifest, config); @@ -17,20 +30,42 @@ Deno.test("HTTP assert test.", async (t) => { }); await t.step("#2 GET /about", async () => { - const resp = await handler( - new Request("http://127.0.0.1/about"), - CONN_INFO, - ); - const text = await resp.text(); - modAssert.assert(text.includes("This is the about page.")); + await verifyPageContainsText(handler, "about", "This is the about page."); }); await t.step("#3 GET /404", async () => { - const resp = await handler( - new Request("http://127.0.0.1/404"), - CONN_INFO, + await verifyPageContainsText(handler, "404", "404 - Page not found"); + }); + + await t.step("#4 GET /chart", async () => { + await verifyPageContainsText(handler, "chart", "Chart"); + }); + + await t.step("#5 GET /countdown", async () => { + await verifyPageContainsText( + handler, + "countdown", + "The big event is happening", ); - const text = await resp.text(); - modAssert.assert(text.includes("404 - Page not found")); + }); + + await t.step("#6 GET /map", async () => { + await verifyPageContainsText(handler, "map", "Map"); + }); + + await t.step("#7 GET /search", async () => { + await verifyPageContainsText(handler, "search", "Search"); + }); + + await t.step("#8 GET /greet", async () => { + await verifyPageContainsText(handler, "greet/test", "test"); + }); + + await t.step("#9 GET /markdown", async () => { + await verifyPageContainsText(handler, "markdowns/string", "Markdown"); + }); + + await t.step("#10 GET /project", async () => { + await verifyPageContainsText(handler, "projects/1", "Project 1"); }); });