37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import { renderMarkdownToHtml } from '../../frontend/src/app/core/services/markdown.pure';
|
|
|
|
describe('Landing welcome binding (mirrors landing.component.ts/.html)', () => {
|
|
function welcomeHtmlFor(payload: { welcomeMarkdown: string } | null | undefined): string {
|
|
return renderMarkdownToHtml(payload?.welcomeMarkdown ?? '');
|
|
}
|
|
|
|
it('renders the welcome Markdown from the bootstrap payload', () => {
|
|
const html = welcomeHtmlFor({
|
|
welcomeMarkdown: '# Welcome\n\nCreate the first admin to get started.',
|
|
});
|
|
expect(typeof html).toBe('string');
|
|
expect(html).toContain('<h1>Welcome</h1>');
|
|
expect(html).toContain('Create the first admin to get started.');
|
|
expect(html).not.toContain('=>{if');
|
|
});
|
|
|
|
it('produces a safe empty string when payload is missing', () => {
|
|
expect(typeof welcomeHtmlFor(null)).toBe('string');
|
|
expect(welcomeHtmlFor(null)).not.toContain('=>{if');
|
|
});
|
|
|
|
it('produces a safe empty string when welcomeMarkdown is empty', () => {
|
|
expect(typeof welcomeHtmlFor({ welcomeMarkdown: '' })).toBe('string');
|
|
expect(welcomeHtmlFor({ welcomeMarkdown: '' })).not.toContain('=>{if');
|
|
});
|
|
|
|
it('keeps sanitization when the welcome Markdown contains hostile content', () => {
|
|
const html = welcomeHtmlFor({
|
|
welcomeMarkdown: '# Hello\n\n<script>alert(1)</script>\n\n[bad](javascript:alert(1))',
|
|
});
|
|
expect(html).toContain('<h1>Hello</h1>');
|
|
expect(html).not.toContain('<script>');
|
|
expect(html).not.toMatch(/href="javascript:/i);
|
|
});
|
|
});
|