BS-007 Implement accepted Contact page and independent enquiry service

This commit is contained in:
rob
2026-11-10 19:45:11 +00:00
parent 21d048a1ff
commit 5bfb128e94
46 changed files with 837 additions and 145 deletions
+2 -1
View File
@@ -7,11 +7,11 @@ import Homepage from "./views/Home/Homepage";
import RoutePlaceholder from "./views/RoutePlaceholder";
import Services from "./views/Services/Services";
import About from "./views/About/About";
import Contact from "./views/Contact/Contact";
const pages = [
["projects", "Projects", "Project details will be added after publication permissions and genuine imagery are confirmed."],
["projects/:slug", "Project details", "This case study is not available. Only verified, approved work will be published."],
["contact", "Contact", "The enquiry form and verified business email will be available here. Enquiries cannot be submitted yet."],
["privacy", "Privacy policy", "Privacy information is awaiting review against the actual website data flows before publication."],
];
@@ -26,6 +26,7 @@ export default function App() {
<Route index element={<><PageMeta /><Homepage /></>} />
<Route path="services" element={<><PageMeta title="Services" description="Website development, custom software, API integration and managed hosting from BortStack." /><Services /></>} />
<Route path="about" element={<><PageMeta title="About" description="BortStack’s approach to practical software development, clear communication and ongoing support." /><About /></>} />
<Route path="contact" element={<><PageMeta title="Contact" description="Discuss your software project with BortStack." /><Contact /></>} />
{pages.map(([path, title, description]) => (
<Route key={path} path={path} element={<>
<PageMeta title={title} description={description} noIndex />
+115 -68
View File
@@ -1,82 +1,129 @@
import { useState } from "react";
import { Button, Form } from "react-bootstrap";
import { useEffect, useRef, useState } from "react";
import { Button, Container, Form } from "react-bootstrap";
import { FiMail, FiSend } from "react-icons/fi";
import styles from "./Contact.module.scss";
const initialValues = {
name: "",
email: "",
subject: "",
message: "",
website: "",
};
import ServiceSelect from "./ServiceSelect";
const empty = { name: "", email: "", service: "", description: "", website: "" };
export default function Contact() {
const [values, setValues] = useState(initialValues);
const [status, setStatus] = useState("idle");
const [error, setError] = useState("");
function update(field, value) {
setValues((current) => ({ ...current, [field]: value }));
const [values, setValues] = useState(empty);
const [config, setConfig] = useState(null);
const [errors, setErrors] = useState({});
const [status, setStatus] = useState({ kind: "idle", message: "" });
const key = useRef(null);
const statusRef = useRef(null);
const formRef = useRef(null);
const sending = status.kind === "sending";
useEffect(() => {
let active = true;
fetch("/api/contact/config").then(r => {
if (!r.ok) throw new Error();
return r.json();
}).then(data => {
const email = typeof data.email === "string" && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email) ? data.email : null;
if (active) setConfig({ email, available: data.available === true });
}).catch(() => { if (active) setConfig({ email: null, available: false }); });
return () => { active = false; };
}, []);
useEffect(() => {
if (["error", "success"].includes(status.kind)) statusRef.current?.focus();
}, [status]);
function change(event) {
const { name, value } = event.target;
setValues(previous => ({ ...previous, [name]: value }));
setErrors(previous => ({ ...previous, [name]: undefined }));
key.current = null;
if (!sending) setStatus({ kind: "idle", message: "" });
}
async function submit(event) {
event.preventDefault();
setStatus("sending");
setError("");
if (sending) return;
const invalid = {};
if (!values.name.trim()) invalid.name = "Enter your name.";
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(values.email.trim())) invalid.email = "Enter a valid email address.";
if (values.description.trim().length < 10) invalid.description = "Describe your project in at least 10 characters.";
setErrors(invalid);
if (Object.keys(invalid).length) {
formRef.current.elements.namedItem(Object.keys(invalid)[0])?.focus();
return;
}
key.current ??= crypto.randomUUID();
setStatus({ kind: "sending", message: "Sending your enquiry…" });
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 15000);
try {
const response = await fetch("/api/contact", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(values),
method: "POST", headers: { "Content-Type": "application/json", "Idempotency-Key": key.current },
body: JSON.stringify(values), signal: controller.signal,
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.message || "Unable to send message");
const data = await response.json().catch(() => ({}));
if (!response.ok || data.success !== true) {
const fieldErrors = {};
for (const name of Object.keys(empty)) {
if (name !== "website" && typeof data.errors?.[name] === "string") fieldErrors[name] = data.errors[name];
}
setErrors(fieldErrors);
throw new Error(typeof data.message === "string" ? data.message : "Unable to send right now. Your draft is kept; please retry.");
}
setValues(initialValues);
setStatus("sent");
} catch (requestError) {
setError(requestError.message);
setStatus("error");
}
setStatus({ kind: "success", message: "Your enquiry has been accepted for delivery. Thank you." });
setValues(empty);
key.current = null;
} catch (error) {
setStatus({ kind: "error", message: error.name === "AbortError" || error instanceof TypeError
? "Sending could not be confirmed. Your draft is kept; please retry."
: error.message || "Unable to send right now. Your draft is kept; please retry." });
} finally { clearTimeout(timer); }
}
return (
<main className={styles.contact}>
<section>
<h1>Contact</h1>
<p>Use this form to contact the application team.</p>
{status === "sent" ? (
<p role="status">Your message has been sent.</p>
) : (
<Form onSubmit={submit}>
<Form.Group className={styles.field} controlId="contact-name">
<Form.Label>Name</Form.Label>
<Form.Control value={values.name} maxLength={100} onChange={(event) => update("name", event.target.value)} required />
</Form.Group>
<Form.Group className={styles.field} controlId="contact-email">
<Form.Label>Email</Form.Label>
<Form.Control type="email" value={values.email} onChange={(event) => update("email", event.target.value)} required />
</Form.Group>
<Form.Group className={styles.field} controlId="contact-subject">
<Form.Label>Subject</Form.Label>
<Form.Control value={values.subject} maxLength={150} onChange={(event) => update("subject", event.target.value)} required />
</Form.Group>
<Form.Group className={styles.field} controlId="contact-message">
<Form.Label>Message</Form.Label>
<Form.Control as="textarea" rows={6} minLength={10} maxLength={5000} value={values.message} onChange={(event) => update("message", event.target.value)} required />
</Form.Group>
<div className={styles.honeypot} aria-hidden="true">
<label htmlFor="contact-website">Website</label>
<input id="contact-website" name="website" tabIndex={-1} autoComplete="off" value={values.website} onChange={(event) => update("website", event.target.value)} />
</div>
{error && <p role="alert">{error}</p>}
<Button type="submit" disabled={status === "sending"}>
{status === "sending" ? "Sending…" : "Send message"}
</Button>
</Form>
)}
return <div className={styles.contactPage}>
<Container>
<section className={styles.hero} aria-labelledby="contact-heading">
<div className={styles.heroCopy}>
<p className={styles.eyebrow}>Contact <span aria-hidden="true" /></p>
<h1 id="contact-heading">Have a <span>project</span> in mind?</h1>
<p className={styles.intro}>Let’s discuss your software project, idea or requirement. <br />Send a message to start the conversation.</p>
</div>
<svg className={styles.illustration} viewBox="0 0 440 260" fill="none" aria-hidden="true">
<g stroke="currentColor" strokeWidth="1.5"><path d="m80 170 140-60 140 60-140 60Z" /><path d="m80 115 140-60 140 60-140 60Z" fill="var(--site-surface)" /><path d="M80 60 220 0 360 60 220 120Z" fill="var(--site-surface)" /></g>
<g stroke="currentColor" opacity=".12"><path d="m0 140 300 120M0 180 200 80m-80 180L440 120M40 260 440 80m-80 180L40 120m160 140L0 180" /></g>
</svg>
</section>
</main>
);
<div className={styles.content}>
<Form ref={formRef} onSubmit={submit} noValidate className={styles.form} aria-label="Project enquiry" aria-busy={sending}>
<fieldset disabled={sending}>
<legend className="visually-hidden">Tell BortStack about your project</legend>
<div className={styles.nameEmail}>
{[['name', 'Name', 'text', 100], ['email', 'Email', 'email', 254]].map(([name, label, type, max]) => <Form.Group controlId={`contact-${name}`} key={name}>
<Form.Label>{label}</Form.Label>
<Form.Control name={name} type={type} autoComplete={name} maxLength={max} required value={values[name]} onChange={change} isInvalid={!!errors[name]} aria-invalid={!!errors[name]} aria-describedby={errors[name] ? `${name}-error` : undefined} />
<Form.Control.Feedback type="invalid" id={`${name}-error`}>{errors[name]}</Form.Control.Feedback>
</Form.Group>)}
</div>
<Form.Group controlId="contact-service">
<Form.Label id="contact-service-label">Service <span>(optional)</span></Form.Label>
<ServiceSelect value={values.service} onChange={change} invalid={!!errors.service} disabled={sending} />
<Form.Control.Feedback type="invalid" id="service-error" className={errors.service ? "d-block" : undefined}>{errors.service}</Form.Control.Feedback>
</Form.Group>
<Form.Group controlId="contact-description">
<Form.Label>Project description</Form.Label>
<Form.Control as="textarea" name="description" required minLength={10} maxLength={5000} value={values.description} onChange={change} isInvalid={!!errors.description} aria-invalid={!!errors.description} aria-describedby={errors.description ? "description-error" : undefined} />
<Form.Control.Feedback type="invalid" id="description-error">{errors.description}</Form.Control.Feedback>
</Form.Group>
<div hidden aria-hidden="true"><label htmlFor="contact-website">Website</label><input id="contact-website" name="website" tabIndex={-1} autoComplete="off" value={values.website} onChange={change} /></div>
<Button type="submit" className={styles.send}><FiSend aria-hidden="true" />{sending ? "Sending…" : "Send Message"}</Button>
</fieldset>
<div ref={statusRef} tabIndex={-1} role={status.kind === "error" ? "alert" : "status"} className={styles.status} data-kind={status.kind}>{status.message}</div>
</Form>
<aside className={styles.details} aria-labelledby="contact-aside-heading">
<h2 id="contact-aside-heading">Let’s build<br />something useful.</h2>
<p>Custom software, web applications, APIs, hosting and ongoing support — practical solutions tailored to your needs.</p>
<div className={styles.email}>
<FiMail aria-hidden="true" />
{config?.email ? <a href={`mailto:${config.email}`}>{config.email}</a> : <span>{config === null ? "Loading contact details…" : "Business email will be published once verified."}</span>}
</div>
{config?.available === false && <p className={styles.availability}>Enquiries are temporarily unavailable. Messages cannot be sent right now.</p>}
</aside>
</div>
</Container>
</div>;
}
+53 -15
View File
@@ -1,20 +1,58 @@
.contact {
display: grid;
place-items: center;
section {
width: min(100%, 36rem);
.contactPage {
min-height: 890px; overflow: clip;
background: radial-gradient(ellipse at 85% 22%, var(--site-glow), transparent 32%), radial-gradient(ellipse at 60% 110%, var(--site-glow), transparent 48%);
:global(.container) { width: calc(100% - 120px); max-width: 1536px; padding-inline: 0; }
}
.hero { position: relative; min-height: 309px; padding: 49px 17px 40px; }
.heroCopy { position: relative; z-index: 1; width: 76%; }
.eyebrow { display: flex; align-items: center; gap: 30px; color: var(--site-link); text-transform: uppercase; font-size: 20px; line-height: 28px; font-weight: 600; letter-spacing: .17em; margin: 0 0 17px; span { width: 300px; height: 1px; background: linear-gradient(90deg, var(--site-link), transparent); } }
.hero h1 { font-size: clamp(40px, 4.3vw, 70px); line-height: 1.2; font-weight: 600; margin: 0 0 16px; letter-spacing: -.035em; span { color: var(--site-link); } }
.intro { font-size: 24px; line-height: 35px; margin: 0; }
.illustration { position: absolute; right: 0; top: 49px; width: 31%; height: 245px; color: var(--site-link); }
.content { display: grid; grid-template-columns: minmax(0, 1.965fr) minmax(0, 1fr); align-items: start; gap: 38px; padding-bottom: 58px; }
.form, .details { border: 1px solid var(--site-line); border-radius: 16px; background: linear-gradient(140deg, var(--site-glow), transparent 65%), var(--site-surface); }
.form {
padding: 34px 40px 30px;
fieldset { min-width: 0; }
:global(.form-label) { color: var(--site-text); font-size: 20px; line-height: 28px; font-weight: 600; margin-bottom: 7px; span { color: var(--site-muted); font-size: 15px; font-weight: 400; } }
:global(.form-control), :global(.form-select) { background-color: var(--site-bg); color: var(--site-text); border: 1px solid var(--bs-steel-blue); border-radius: 10px; min-height: 50px; font-size: 18px; padding: 9px 14px; &:focus { border-color: var(--site-link); box-shadow: 0 0 0 3px var(--site-glow); } }
:global(.form-select) {
color: var(--site-text);
}
:global(textarea.form-control) { min-height: 125px; resize: vertical; }
:global(.form-control.is-invalid), :global(.form-select.is-invalid) { border-color: var(--bs-danger-text-emphasis); }
:global(.invalid-feedback) { color: var(--bs-danger-text-emphasis); }
:global(.form-control:disabled) { opacity: .7; }
:global(.form-group), fieldset > div:not(.nameEmail) { margin-bottom: 15px; }
}
.nameEmail { display: grid; grid-template-columns: 1fr 1fr; gap: 38px; margin-bottom: 18px; min-width: 0; > div { min-width: 0; } }
.send { display: inline-flex; align-items: center; gap: 18px; min-height: 60px; margin-top: 15px; padding: 10px 35px; border-radius: 11px; font-size: 22px; line-height: 34px; font-weight: 600; svg { width: 29px; height: 29px; } }
.status { margin: 0; font-size: 15px; overflow-wrap: anywhere; &:not(:empty) { margin-top: 22px; } &[data-kind="error"] { color: var(--bs-danger-text-emphasis); } }
.details { padding: 32px 36px; min-height: 448px; h2 { position: relative; font-size: 36px; line-height: 42px; font-weight: 600; margin: 0 0 22px; padding-left: 23px; &::before { content: ''; position: absolute; width: 4px; top: 6px; bottom: 6px; left: 0; background: var(--site-link); border-radius: 4px; } } > p { font-size: 19px; line-height: 31px; margin: 0 0 28px; } .availability { font-size: 14px; line-height: 23px; color: var(--site-muted); margin: 18px 0 0; } }
.email { border-top: 1px solid var(--site-line); padding-top: 28px; display: flex; gap: 22px; align-items: flex-start; font-size: 17px; line-height: 27px; overflow-wrap: anywhere; svg { color: var(--site-link); flex-shrink: 0; width: 28px; height: 28px; } a, span { min-width: 0; } }
:global(.app):has(.contactPage) :global(nav[aria-label="Main navigation"]) { min-height: 88px; &::after { left: 50px; right: 50px; } :global(.container) { max-width: 1536px; width: calc(100% - 160px); min-height: 87px; } :global(.nav-link) { font-size: 20px; padding-inline: 24px !important; } :global(.nav-link[aria-current="page"]) { position: relative; &::after { content: ''; position: absolute; left: 24px; right: 24px; bottom: 0; height: 3px; background: var(--site-link); } } }
@media (max-width: 1199.98px) { .contactPage :global(.container) { width: calc(100% - 64px); } .hero { padding-inline: 0; min-height: 290px; } .intro { font-size: 19px; line-height: 30px; } .content { gap: 24px; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); } .form { padding: 28px; } .nameEmail { gap: 20px; } .details { padding: 28px 24px; h2 { font-size: 27px; line-height: 36px; } > p { font-size: 16px; line-height: 27px; } } :global(.app):has(.contactPage) :global(nav[aria-label="Main navigation"]) { :global(.container) { width: calc(100% - 64px); } :global(.nav-link) { font-size: 14px; padding-inline: 12px !important; } } }
@media (max-width: 991.98px) { .content { grid-template-columns: 1fr; } .details { min-height: auto; } .heroCopy { width: 78%; } .hero h1 { font-size: 39px; } .intro { max-width: 490px; } .illustration { width: 25%; opacity: .65; top: 70px; } .eyebrow { font-size: 16px; } }
@media (max-width: 767.98px) { .contactPage { min-height: auto; :global(.container) { width: calc(100% - 40px); } } .hero { padding-top: 32px; padding-bottom: 26px; } .heroCopy { width: 100%; } .hero h1 { font-size: clamp(34px, 9vw, 48px); } .intro { font-size: 16px; line-height: 27px; br { display: none; } } .eyebrow { font-size: 14px; gap: 18px; span { max-width: 150px; } } .illustration { position: relative; display: block; width: 100%; height: 150px; top: auto; right: auto; margin-top: 20px; opacity: 1; } .form { padding: 24px 20px; :global(.form-label) { font-size: 17px; } :global(.form-control), :global(.form-select) { font-size: 16px; } } .nameEmail { grid-template-columns: 1fr; gap: 15px; } .send { width: 100%; padding-inline: 14px; font-size: 19px; gap: 12px; } .content { padding-bottom: 32px; } .details { padding: 28px 22px; h2 { font-size: 28px; line-height: 37px; } } .email { gap: 15px; font-size: 16px; } :global(.app):has(.contactPage) :global(nav[aria-label="Main navigation"]) { min-height: 67px; &::after { left: 20px; right: 20px; } :global(.container) { width: calc(100% - 40px); min-height: 43px; } :global(.nav-link) { font-size: 15px; } } }
@media (min-width: 1200px) { :global(.app):has(.contactPage) :global(a[aria-label^="BortStack home"]) > span:last-child { font-size: 40px; } }
.field {
margin-bottom: 1rem;
.serviceSelect { position: relative; }
.form .serviceTrigger {
display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; text-align: left; background-image: none;
span { min-width: 0; overflow-wrap: anywhere; } svg { flex-shrink: 0; width: 18px; height: 18px; }
&:disabled { opacity: .7; }
}
.honeypot {
position: absolute;
left: -10000px;
width: 1px;
height: 1px;
overflow: hidden;
.serviceOptions {
position: absolute; z-index: 30; top: calc(100% + 7px); left: 0; right: 0;
max-height: min(320px, 45vh); overflow-y: auto; padding: 6px;
background: var(--site-surface); color: var(--site-text); border: 1px solid var(--bs-steel-blue); border-radius: 10px;
box-shadow: 0 12px 30px rgba(0, 0, 0, .25);
}
.serviceOption {
display: flex; align-items: center; justify-content: space-between; gap: 12px;
padding: 11px 13px; min-height: 44px; border-radius: 6px; font-size: 16px; line-height: 24px; cursor: pointer;
span { min-width: 0; overflow-wrap: anywhere; } svg { flex-shrink: 0; color: var(--site-link); }
&[aria-selected="true"] { font-weight: 600; }
&[data-active="true"] { background: var(--bs-steel-blue); color: #F5F7FA; svg { color: #F5F7FA; } }
}
@media (max-width: 767.98px) { .serviceOption { font-size: 14px; padding: 10px; } }
+57
View File
@@ -0,0 +1,57 @@
import { useEffect, useRef, useState } from "react";
import { FiCheck, FiChevronDown } from "react-icons/fi";
import PropTypes from "prop-types";
import styles from "./Contact.module.scss";
const options = ["", "Website Development", "Custom Software & Web Applications", "API Development & Integration", "Managed Hosting & Maintenance"];
const label = value => value || "Select a service";
export default function ServiceSelect({ value, onChange, invalid, disabled }) {
const [open, setOpen] = useState(false);
const [active, setActive] = useState(0);
const root = useRef(null);
const button = useRef(null);
const selected = Math.max(0, options.indexOf(value));
useEffect(() => {
if (!open) return;
const close = event => { if (!root.current?.contains(event.target)) setOpen(false); };
document.addEventListener("pointerdown", close);
return () => document.removeEventListener("pointerdown", close);
}, [open]);
useEffect(() => {
if (open) root.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({ block: "nearest" });
}, [active, open]);
function choose(index) {
onChange({ target: { name: "service", value: options[index] } });
setOpen(false);
button.current?.focus();
}
function keyDown(event) {
const key = event.key;
if (["ArrowDown", "ArrowUp", "Home", "End", "Enter", " ", "Escape"].includes(key)) event.preventDefault();
if (key === "Escape" || key === "Tab") { setOpen(false); return; }
if (key === "Enter" || key === " ") {
if (open) choose(active);
else { setActive(selected); setOpen(true); }
} else if (["ArrowDown", "ArrowUp", "Home", "End"].includes(key)) {
const base = open ? active : selected;
setActive(key === "Home" ? 0 : key === "End" ? options.length - 1 : (base + (key === "ArrowDown" ? 1 : -1) + options.length) % options.length);
setOpen(true);
} else if (key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
const match = options.findIndex(option => label(option).toLowerCase().startsWith(key.toLowerCase()));
if (match >= 0) { event.preventDefault(); setActive(match); setOpen(true); }
}
}
return <div ref={root} className={styles.serviceSelect} onBlur={event => { if (!event.currentTarget.contains(event.relatedTarget)) setOpen(false); }}>
<input type="hidden" name="service" value={value} />
<button ref={button} id="contact-service" type="button" role="combobox" aria-labelledby="contact-service-label" aria-haspopup="listbox" aria-expanded={open && !disabled} aria-controls={open && !disabled ? "contact-service-options" : undefined} aria-activedescendant={open && !disabled ? `service-option-${active}` : undefined} aria-invalid={invalid} aria-describedby={invalid ? "service-error" : undefined} disabled={disabled} className={`${styles.serviceTrigger} form-select ${invalid ? 'is-invalid' : ''}`} onKeyDown={keyDown} onClick={() => { setActive(selected); setOpen(!open); }}>
<span>{label(value)}</span><FiChevronDown aria-hidden="true" />
</button>
{open && !disabled && <div id="contact-service-options" role="listbox" aria-labelledby="contact-service-label" className={styles.serviceOptions}>
{options.map((option, index) => <div id={`service-option-${index}`} key={option} role="option" aria-selected={selected === index} data-active={active === index} className={styles.serviceOption} onPointerMove={() => setActive(index)} onMouseDown={event => event.preventDefault()} onClick={() => choose(index)}>
<span>{label(option)}</span>{selected === index && <FiCheck aria-hidden="true" />}
</div>)}
</div>}
</div>;
}
ServiceSelect.propTypes = { value: PropTypes.string.isRequired, onChange: PropTypes.func.isRequired, invalid: PropTypes.bool, disabled: PropTypes.bool };
+9 -5
View File
@@ -1,4 +1,4 @@
import { fireEvent, render, screen, within } from "@testing-library/react";
import { fireEvent, render, screen, within, waitFor } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import App from "../App";
@@ -7,15 +7,19 @@ describe("public marketing routes", () => {
it.each([
["/services", "Services"], ["/projects", "Projects"],
["/projects/example", "Project details"], ["/about", "About BortStack"],
["/contact", "Contact"], ["/privacy", "Privacy policy"],
["/contact", "Have a project in mind?"], ["/privacy", "Privacy policy"],
["/login", "Page not found"], ["/register", "Page not found"], ["/dashboard", "Page not found"],
])("loads %s without account infrastructure", (path, heading) => {
const fetchMock = vi.fn();
])("loads %s without account infrastructure", async (path, heading) => {
const fetchMock = vi.fn().mockResolvedValue({ ok: true, json: async () => ({ email: null, available: false }) });
vi.stubGlobal("fetch", fetchMock);
window.history.replaceState({}, "", path);
render(<App />);
expect(screen.getByRole("heading", { level: 1, name: heading })).toBeInTheDocument();
expect(fetchMock).not.toHaveBeenCalled();
if (path === "/contact") {
expect(fetchMock).toHaveBeenCalledWith("/api/contact/config");
await waitFor(() => expect(screen.getByText(/Enquiries are temporarily unavailable/)).toBeInTheDocument());
}
else expect(fetchMock).not.toHaveBeenCalled();
expect(screen.queryByRole("link", { name: /login|register|dashboard/i })).not.toBeInTheDocument();
});
it("exposes the four marketing links and closes navigation on selection", async () => {
+6 -8
View File
@@ -31,11 +31,10 @@ describe("generic public pages", () => {
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "Example Person" } });
fireEvent.change(screen.getByLabelText("Email"), { target: { value: "person@example.com" } });
fireEvent.change(screen.getByLabelText("Subject"), { target: { value: "A question" } });
fireEvent.change(screen.getByLabelText("Message"), { target: { value: "A message long enough to send." } });
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
fireEvent.change(screen.getByLabelText("Project description"), { target: { value: "A message long enough to send." } });
fireEvent.click(screen.getByRole("button", { name: "Send Message" }));
await waitFor(() => expect(screen.getByRole("status")).toHaveTextContent("message has been sent"));
await waitFor(() => expect(screen.getByRole("status")).toHaveTextContent("accepted for delivery"));
expect(fetchMock).toHaveBeenCalledWith("/api/contact", expect.objectContaining({ method: "POST" }));
});
@@ -48,11 +47,10 @@ describe("generic public pages", () => {
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "Example Person" } });
fireEvent.change(screen.getByLabelText("Email"), { target: { value: "person@example.com" } });
fireEvent.change(screen.getByLabelText("Subject"), { target: { value: "A question" } });
fireEvent.change(screen.getByLabelText("Message"), { target: { value: "A message long enough to send." } });
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
fireEvent.change(screen.getByLabelText("Project description"), { target: { value: "A message long enough to send." } });
fireEvent.click(screen.getByRole("button", { name: "Send Message" }));
await waitFor(() => expect(screen.getByRole("alert")).toHaveTextContent("Unable to send message right now"));
expect(screen.getByRole("button", { name: "Send message" })).toBeEnabled();
expect(screen.getByRole("button", { name: "Send Message" })).toBeEnabled();
});
});