General enquries feature

This commit is contained in:
2026-05-04 20:32:24 +12:00
parent bf9331bb5b
commit fa1bc1a615
27 changed files with 657 additions and 164 deletions
+13 -2
View File
@@ -1,5 +1,6 @@
import { error, redirect } from '@sveltejs/kit';
import { staticPages, type StaticPageSlug } from '$lib/content/static-pages';
import { isGeneralEnquiryEnabled } from '$lib/server/feature-flags';
import { getSharedPageContent } from '$lib/server/content';
export async function load({ params }) {
@@ -12,14 +13,24 @@ export async function load({ params }) {
}
const slug = params.slug as StaticPageSlug;
const page = staticPages[slug];
const generalEnquiryEnabled = isGeneralEnquiryEnabled();
const sourcePage = staticPages[slug];
if (!page) {
if (!sourcePage) {
throw error(404, 'Page not found');
}
const page =
slug === 'contact-us' && !generalEnquiryEnabled
? {
...sourcePage,
description: 'Book a Meet & Greet with Goodwalk Auckland dog walking services.'
}
: sourcePage;
return {
content: await getSharedPageContent(),
generalEnquiryEnabled,
page,
slug
};
+1 -1
View File
@@ -193,7 +193,7 @@
{:else if data.slug === 'privacy-policy'}
<LegalPage pageContent={privacyPolicyContent} />
{:else if data.slug === 'contact-us'}
<BookingPage booking={data.content.booking} />
<BookingPage booking={data.content.booking} allowGeneralEnquiry={data.generalEnquiryEnabled} />
{:else}
<main class="static-page">
<section class="static-page-hero">
@@ -15,6 +15,7 @@ import { load } from './+page.server';
describe('static slug page server load', () => {
beforeEach(() => {
getSharedPageContent.mockReset();
vi.unstubAllEnvs();
});
it('redirects the legacy about-us slug to /about', async () => {
@@ -42,8 +43,35 @@ describe('static slug page server load', () => {
await expect(load({ params: { slug: 'pack-walks' } } as never)).resolves.toEqual({
content: sharedPageContent,
generalEnquiryEnabled: false,
page: staticPages['pack-walks'],
slug: 'pack-walks'
});
});
it('keeps general enquiries disabled on contact-us by default', async () => {
getSharedPageContent.mockResolvedValue(sharedPageContent);
await expect(load({ params: { slug: 'contact-us' } } as never)).resolves.toEqual({
content: sharedPageContent,
generalEnquiryEnabled: false,
page: {
...staticPages['contact-us'],
description: 'Book a Meet & Greet with Goodwalk Auckland dog walking services.'
},
slug: 'contact-us'
});
});
it('enables general enquiries on contact-us when the env flag is turned on', async () => {
vi.stubEnv('ENABLE_GENERAL_ENQUIRIES', 'enabled');
getSharedPageContent.mockResolvedValue(sharedPageContent);
await expect(load({ params: { slug: 'contact-us' } } as never)).resolves.toEqual({
content: sharedPageContent,
generalEnquiryEnabled: true,
page: staticPages['contact-us'],
slug: 'contact-us'
});
});
});
+17
View File
@@ -43,4 +43,21 @@ describe('static slug route page', () => {
expect(screen.queryByText('Why people choose us!')).not.toBeInTheDocument();
}
);
it('shows the general enquiry option on the contact page only', () => {
const { rerender } = render(SlugPage, {
data: {
...createStaticRouteData('contact-us'),
generalEnquiryEnabled: true
}
});
expect(screen.getByLabelText(/General enquiry/i)).toBeInTheDocument();
rerender({
data: createStaticRouteData('pack-walks')
});
expect(screen.queryByLabelText(/General enquiry/i)).not.toBeInTheDocument();
});
});
+1
View File
@@ -12,6 +12,7 @@ describe('home page route', () => {
expect(screen.getAllByText("Your Dog's Day!").length).toBeGreaterThan(0);
expect(document.body.textContent).toContain('Happy pets,');
expect(screen.getByText('Locations & Hours')).toBeInTheDocument();
expect(screen.queryByLabelText(/General enquiry/i)).not.toBeInTheDocument();
expect(document.title).toBe('Home | Auckland Dog Walking | Goodwalk');
expect(document.head.innerHTML).toContain('FAQPage');
expect(document.head.innerHTML).toContain('https://www.goodwalk.co.nz/images/auckland-dog-walking-happy-dog-hero.png');