-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,15 @@ | |
"start": "deno run -A --watch=static/,routes/ dev.ts", | ||
"build": "deno run -A dev.ts build", | ||
"preview": "deno run -A main.ts", | ||
"update": "deno run -A -r https://fresh.deno.dev/update ." | ||
"update": "deno run -A -r https://fresh.deno.dev/update .", | ||
"test": "deno test --allow-read --allow-env --allow-net" | ||
}, | ||
"lint": { | ||
"rules": { | ||
"tags": [ | ||
"fresh", | ||
"recommended" | ||
] | ||
"tags": ["fresh", "recommended"] | ||
} | ||
}, | ||
"exclude": [ | ||
"**/_fresh/*" | ||
], | ||
"exclude": ["**/_fresh/*"], | ||
"imports": { | ||
"$fresh/": "https://deno.land/x/[email protected]/", | ||
"preact": "https://esm.sh/[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { createHandler, ServeHandlerInfo } from "$fresh/server.ts"; | ||
import manifest from "../fresh.gen.ts"; | ||
import config from "../fresh.config.ts"; | ||
import { assertEquals } from "$std/assert/assert_equals.ts"; | ||
import { assert } from "$std/assert/assert.ts"; | ||
import { assertExists } from "$std/assert/mod.ts"; | ||
|
||
const CONNECTION: ServeHandlerInfo = { | ||
remoteAddr: { hostname: "localhost", port: 8000, transport: "tcp" }, | ||
}; | ||
|
||
Deno.test("Feature: Listening Pinyin", async (t) => { | ||
const handler = await createHandler(manifest, config); | ||
|
||
await t.step("Get the question", async () => { | ||
const req = new Request("http://localhost/blueprint"); | ||
const resp = await handler(req, CONNECTION); | ||
const text = await resp.text(); | ||
assert(resp.ok); | ||
assert(text.includes('<button type="button">🔈</button>')); | ||
}); | ||
|
||
await t.step("Post the answer", async () => { | ||
const formData = new FormData(); | ||
formData.append("question_id", "1057"); | ||
formData.append("initial", "sh"); | ||
formData.append("final", "eng"); | ||
formData.append("tone", "1st tone"); | ||
const req = new Request("http://localhost/blueprint", { | ||
method: "POST", | ||
body: formData, | ||
}); | ||
const resp = await handler(req, CONNECTION).then((value) => { | ||
const url = new URL(value.headers.get("location")!); | ||
assertEquals(value.status, 303); | ||
assertExists(url.searchParams.get("question")); | ||
assertExists(url.searchParams.get("answer")); | ||
assertExists(url.searchParams.get("truth")); | ||
return handler(new Request(url!)); | ||
}); | ||
|
||
const text = await resp.text(); | ||
assert(resp.ok); | ||
assert(text.includes('<button type="button">shēng</button>')); | ||
}); | ||
|
||
await t.step("Get the correct state", async () => { | ||
const formData = new FormData(); | ||
formData.append("question_id", "1057"); | ||
formData.append("initial", "sh"); | ||
formData.append("final", "eng"); | ||
formData.append("tone", "1st tone"); | ||
const req = new Request("http://localhost/blueprint", { | ||
method: "POST", | ||
body: formData, | ||
}); | ||
const resp = await handler(req, CONNECTION).then((value) => { | ||
const url = value.headers.get("location"); | ||
assertEquals(value.status, 303); | ||
return handler(new Request(url!)); | ||
}); | ||
|
||
const text = await resp.text(); | ||
assert(resp.ok); | ||
assert( | ||
text.includes('<div class="h-screen content-center bg-green-300 ">'), | ||
); | ||
}); | ||
|
||
await t.step("Get the false state", async () => { | ||
const formData = new FormData(); | ||
formData.append("question_id", "1"); | ||
formData.append("initial", "sh"); | ||
formData.append("final", "eng"); | ||
formData.append("tone", "1st tone"); | ||
const req = new Request("http://localhost/blueprint", { | ||
method: "POST", | ||
body: formData, | ||
}); | ||
const resp = await handler(req, CONNECTION).then((value) => { | ||
const url = value.headers.get("location"); | ||
assertEquals(value.status, 303); | ||
return handler(new Request(url!)); | ||
}); | ||
|
||
const text = await resp.text(); | ||
assert(resp.ok); | ||
assert( | ||
text.includes('<div class="h-screen content-center bg-red-300 ">'), | ||
); | ||
}); | ||
}); |