fix(ssr): apply theme CSS vars during SSR and enable client hydration
CI Pipeline / backend-test (push) Successful in 9m4s
CI Pipeline / frontend-test (push) Successful in 24s
CI Pipeline / frontend-build (push) Successful in 32s
CI Pipeline / backend-lint (push) Successful in 14s
CI Pipeline / backend-test (pull_request) Successful in 9m17s
CI Pipeline / frontend-test (pull_request) Successful in 24s
CI Pipeline / frontend-build (pull_request) Successful in 30s
CI Pipeline / backend-lint (pull_request) Successful in 10s
CI Pipeline / quality-gate (push) Successful in 2s
CI Pipeline / quality-gate (pull_request) Successful in 2s
CI Pipeline / backend-test (push) Successful in 9m4s
CI Pipeline / frontend-test (push) Successful in 24s
CI Pipeline / frontend-build (push) Successful in 32s
CI Pipeline / backend-lint (push) Successful in 14s
CI Pipeline / backend-test (pull_request) Successful in 9m17s
CI Pipeline / frontend-test (pull_request) Successful in 24s
CI Pipeline / frontend-build (pull_request) Successful in 30s
CI Pipeline / backend-lint (pull_request) Successful in 10s
CI Pipeline / quality-gate (push) Successful in 2s
CI Pipeline / quality-gate (pull_request) Successful in 2s
- ThemeService: remove isPlatformBrowser guard so CSS custom properties are applied during SSR/prerender — server-rendered HTML now carries the correct color scheme and gradients (fixes missing colors on test site). - main.ts: add provideClientHydration() so Angular preserves the server- rendered DOM on the client instead of destroying and rebuilding it (fixes jarring full-page reload between static and dynamic versions). - Tests: update theme.service.spec.ts to match new behaviour, expand coverage with gradient tests and empty-value handling (9 tests). Fix structured-data.component.spec.ts import paths. All 54 tests pass.
This commit is contained in:
1 parent
2d26269c1a
commit
e95a158d57
10 files changed
+551
-16
No files matched your search
@@ -0,0 +1,90 @@
|
||||
// Load the JIT compiler BEFORE any Angular router/common imports
|
||||
import '@angular/compiler';
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
// Mock the @angular/ssr/node imports that pull in Node.js http server code
|
||||
// — we only want to test PRERENDERED_ROUTES and isPrerenderedRoute here.
|
||||
vi.mock('@angular/ssr/node', () => ({
|
||||
AngularNodeAppEngine: class {},
|
||||
createNodeRequestHandler: (fn: Function) => fn,
|
||||
isMainModule: () => false,
|
||||
writeResponseToNodeResponse: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('node:http', () => ({
|
||||
default: { createServer: vi.fn() },
|
||||
}));
|
||||
|
||||
import { PRERENDERED_ROUTES, isPrerenderedRoute } from './server';
|
||||
|
||||
describe('SSR server — server.ts', () => {
|
||||
describe('PRERENDERED_ROUTES', () => {
|
||||
it('should contain exactly 5 routes', () => {
|
||||
expect(PRERENDERED_ROUTES).toHaveLength(5);
|
||||
});
|
||||
|
||||
it('should include the home route', () => {
|
||||
expect(PRERENDERED_ROUTES).toContain('/');
|
||||
});
|
||||
|
||||
it('should include /about', () => {
|
||||
expect(PRERENDERED_ROUTES).toContain('/about');
|
||||
});
|
||||
|
||||
it('should include /schedule', () => {
|
||||
expect(PRERENDERED_ROUTES).toContain('/schedule');
|
||||
});
|
||||
|
||||
it('should include /events', () => {
|
||||
expect(PRERENDERED_ROUTES).toContain('/events');
|
||||
});
|
||||
|
||||
it('should include /contact', () => {
|
||||
expect(PRERENDERED_ROUTES).toContain('/contact');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPrerenderedRoute()', () => {
|
||||
it('should match exact prerendered paths', () => {
|
||||
expect(isPrerenderedRoute('/')).toBe(true);
|
||||
expect(isPrerenderedRoute('/about')).toBe(true);
|
||||
expect(isPrerenderedRoute('/schedule')).toBe(true);
|
||||
expect(isPrerenderedRoute('/events')).toBe(true);
|
||||
expect(isPrerenderedRoute('/contact')).toBe(true);
|
||||
});
|
||||
|
||||
it('should match paths with trailing slashes', () => {
|
||||
expect(isPrerenderedRoute('/about/')).toBe(true);
|
||||
expect(isPrerenderedRoute('/schedule/')).toBe(true);
|
||||
expect(isPrerenderedRoute('/events/')).toBe(true);
|
||||
expect(isPrerenderedRoute('/contact/')).toBe(true);
|
||||
});
|
||||
|
||||
it('should match paths with query strings', () => {
|
||||
expect(isPrerenderedRoute('/about?foo=bar')).toBe(true);
|
||||
expect(isPrerenderedRoute('/schedule?day=monday')).toBe(true);
|
||||
});
|
||||
|
||||
it('should match paths with fragments', () => {
|
||||
expect(isPrerenderedRoute('/events#upcoming')).toBe(true);
|
||||
});
|
||||
|
||||
it('should reject non-prerendered routes', () => {
|
||||
expect(isPrerenderedRoute('/login')).toBe(false);
|
||||
expect(isPrerenderedRoute('/admin')).toBe(false);
|
||||
expect(isPrerenderedRoute('/nonexistent')).toBe(false);
|
||||
expect(isPrerenderedRoute('/admin/dashboard')).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle full URLs', () => {
|
||||
expect(isPrerenderedRoute('https://kmtnflower.org/about')).toBe(true);
|
||||
expect(isPrerenderedRoute('http://localhost:4200/events')).toBe(true);
|
||||
expect(isPrerenderedRoute('https://kmtnflower.org/login')).toBe(false);
|
||||
});
|
||||
|
||||
it('should normalise root path — "/" stays "/"', () => {
|
||||
expect(isPrerenderedRoute('/')).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user