/** * The newsletter signup is a framework feature: one component, one endpoint. * * `` ships in the framework defaults and every signup on * stacksjs.com (and the framework's own ComingSoon page) uses it, so a fix to * the form or its messages lands everywhere at once. These pin that, and the * component's own contract: stx bindings, a plain-form fallback, and an * answer for every outcome the endpoint can give. */ import { readFileSync } from 'node:fs' import { join } from 'node:path' import { describe, expect, test } from 'bun:test' import { subscribeOutcomeFrom } from '../../resources/data/blog' const root = join(import.meta.dir, '../..') const read = (path: string) => readFileSync(join(root, path), 'utf8') const component = read('storage/framework/defaults/resources/components/Marketing/SubscribeForm.stx') describe('SubscribeForm', () => { test('is bound with stx, not by querying the document', () => { expect(component).toContain('@submit.prevent="submit()"') expect(component).toContain('x-model.trim="email"') expect(component).not.toMatch(/document\.|window\.|querySelector/) }) test('still posts as a plain form without JavaScript', () => { expect(component).toContain('action="/api/email/subscribe"') expect(component).toContain('method="POST"') for (const field of ['source', 'list', 'return']) expect(component).toContain(`name="${field}"`) }) test('renders what it shows before its script has run', () => { // As an island the form paints before hydration. Every string and class a // reader sees, and every value a plain post sends, has to be in the // server-rendered markup, with the binding taking over afterwards. expect(component).toMatch(/