diff --git a/tests/contact.test.js b/tests/contact.test.js new file mode 100644 index 0000000..d2a848d --- /dev/null +++ b/tests/contact.test.js @@ -0,0 +1,109 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; +import { dirname, join } from "node:path"; +import { + MAILTO_TARGET, + buildContactMailto, + handleContactSubmit, + readFormValues, +} from "../js/contact.js"; + +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); +const contactHtml = readFileSync(join(root, "contact.html"), "utf8"); +const indexHtml = readFileSync(join(root, "index.html"), "utf8"); + +/** Minimal stand-in for a DOM form (has querySelectorAll("[name]")). */ +function fakeForm(values) { + return { + querySelectorAll(selector) { + assert.equal(selector, "[name]"); + return Object.entries(values).map(([name, value]) => ({ name, value })); + }, + }; +} + +// --------------------------------------------------------------------------- +// Component tests: the contact page renders the three required fields +// --------------------------------------------------------------------------- + +test("contact page renders a form with name, email, and message fields", () => { + assert.match(contactHtml, /