feat: Landing Page and Login/Register Modal

This commit is contained in:
OpenVelo Agent
2026-07-21 18:34:42 +00:00
parent 09856ccf8e
commit 0126f6ad39
37 changed files with 1791 additions and 210 deletions
+27
View File
@@ -0,0 +1,27 @@
import { decideLandingGuard } from '../../frontend/src/app/core/guards/landing.guard.decision';
describe('decideLandingGuard', () => {
const router = {
createUrlTree: jest.fn((commands: string[]) => ({ kind: 'UrlTree', commands })),
};
beforeEach(() => {
(router.createUrlTree as jest.Mock).mockClear();
});
it('redirects to /bootstrap when not initialized', () => {
const r = decideLandingGuard({ initialized: false, isAuthenticated: false }, router as any);
expect(router.createUrlTree).toHaveBeenCalledWith(['/bootstrap']);
expect((r as any).commands).toEqual(['/bootstrap']);
});
it('redirects to / when initialized and authenticated', () => {
const r = decideLandingGuard({ initialized: true, isAuthenticated: true }, router as any);
expect(router.createUrlTree).toHaveBeenCalledWith(['/']);
expect((r as any).commands).toEqual(['/']);
});
it('allows when initialized and not authenticated', () => {
expect(decideLandingGuard({ initialized: true, isAuthenticated: false }, router as any)).toBe(true);
});
});
+34
View File
@@ -0,0 +1,34 @@
import { renderMarkdownToHtml } from '../../frontend/src/app/core/services/markdown.pure';
describe('renderMarkdownToHtml', () => {
it('renders headings', () => {
expect(renderMarkdownToHtml('# Hello')).toContain('<h1>Hello</h1>');
});
it('renders bold and italic', () => {
const out = renderMarkdownToHtml('**bold** and *italic*');
expect(out).toContain('<strong>bold</strong>');
expect(out).toContain('<em>italic</em>');
});
it('renders safe links', () => {
expect(renderMarkdownToHtml('[a](https://example.com)')).toContain('href="https://example.com"');
});
it('strips <script> tags', () => {
const out = renderMarkdownToHtml('<script>alert(1)</script>safe');
expect(out).not.toContain('<script>');
expect(out).toContain('safe');
});
it('strips javascript: hrefs', () => {
const out = renderMarkdownToHtml('[click](javascript:alert(1))');
expect(out).not.toMatch(/href="javascript:/i);
});
it('handles empty/null/undefined input', () => {
expect(renderMarkdownToHtml('')).toBeDefined();
expect(renderMarkdownToHtml(null as unknown as string)).toBeDefined();
expect(renderMarkdownToHtml(undefined as unknown as string)).toBeDefined();
});
});
+53
View File
@@ -0,0 +1,53 @@
import { buildLoginFailureMessage } from '../../frontend/src/app/features/landing/login-modal.service';
describe('buildLoginFailureMessage', () => {
it.each([
[
'INVALID_CREDENTIALS',
'Invalid credentials',
{ text: 'Invalid username or password.', retryAfterSeconds: undefined },
],
[
'USERNAME_TAKEN',
'Username already taken',
{ text: 'Username already exists.', retryAfterSeconds: undefined },
],
[
'REGISTRATIONS_DISABLED',
'Registrations are currently disabled',
{ text: 'Registrations are currently disabled.', retryAfterSeconds: undefined },
],
[
'CSRF_INVALID',
'CSRF token missing or invalid',
{ text: 'Session expired. Please reload the page and try again.', retryAfterSeconds: undefined },
],
[
'WEAK_PASSWORD',
'Password must be at least 12 characters',
{ text: 'Password does not meet the security policy.', retryAfterSeconds: undefined },
],
[
'VALIDATION_FAILED',
'passwordConfirm: must match',
{ text: 'Please check the form fields and try again.', retryAfterSeconds: undefined },
],
[
'RATE_LIMITED',
'Too many failed attempts. Try again in 7s.',
{ text: 'Please wait 7 seconds before trying again.', retryAfterSeconds: 7 },
],
[
'RATE_LIMITED',
'Too many registration attempts; please wait a minute before trying again.',
{ text: 'Too many attempts. Please wait a moment before trying again.', retryAfterSeconds: undefined },
],
])('maps code=%s to expected message', (code, message, expected) => {
expect(buildLoginFailureMessage({ code, message })).toEqual(expected);
});
it('falls back to raw message for unknown codes', () => {
expect(buildLoginFailureMessage({ code: 'EXOTIC', message: 'Quux' }).text).toBe('Quux');
expect(buildLoginFailureMessage({ code: 'EXOTIC', message: '' }).text).toBe('Something went wrong. Please try again.');
});
});