2026-07-12 18:03:44 -07:00
|
|
|
import { describe, test, expect } from 'vitest';
|
|
|
|
|
import { FormButton } from './FormButton';
|
|
|
|
|
|
|
|
|
|
const toHtml = (FormButton as any).toHtml;
|
|
|
|
|
|
|
|
|
|
describe('FormButton.toHtml', () => {
|
|
|
|
|
test('normal text renders as-is', () => {
|
|
|
|
|
const { html } = toHtml({ text: 'Send it' }, '');
|
|
|
|
|
expect(html).toContain('>Send it<');
|
|
|
|
|
expect(html).toContain('type="submit"');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('type="submit" is a hardcoded literal, not prop-driven', () => {
|
|
|
|
|
const { html } = toHtml({ text: 'Submit' }, '');
|
|
|
|
|
expect(html).toMatch(/<button type="submit"/);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('text content is escaped for <, >, &, and " (consistent with escapeHtml)', () => {
|
|
|
|
|
const { html } = toHtml({ text: '<script>alert(1)</script> & "quoted"' }, '');
|
|
|
|
|
expect(html).not.toContain('<script>');
|
|
|
|
|
expect(html).toContain('<script>alert(1)</script>');
|
|
|
|
|
expect(html).toContain('&');
|
|
|
|
|
expect(html).toContain('"quoted"');
|
|
|
|
|
});
|
2026-07-14 06:44:21 -07:00
|
|
|
|
|
|
|
|
test('box-model style (margin/border/box-shadow/opacity) flows through via the style prop', () => {
|
|
|
|
|
const { html } = toHtml({ text: 'Submit', style: { marginTop: '12px', border: '2px solid #000', boxShadow: '0 2px 4px rgba(0,0,0,.2)', opacity: '0.8' } }, '');
|
|
|
|
|
expect(html).toContain('margin-top:12px');
|
|
|
|
|
expect(html).toContain('border:2px solid #000');
|
|
|
|
|
expect(html).toContain('opacity:0.8');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('FormButton.craft.props includes animation/visibility defaults', () => {
|
|
|
|
|
test('has blank/false defaults', () => {
|
|
|
|
|
expect(FormButton.craft!.props).toMatchObject({
|
|
|
|
|
animation: '', animationDelay: '', hideOnDesktop: false, hideOnTablet: false, hideOnMobile: false,
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-07-12 18:03:44 -07:00
|
|
|
});
|