refactor: deslop — remove dead botanica preset, extract shared helpers
- Remove dead theme preset (no CSS, not in DevToolbar) - Extract from closure → module-level export in lib/config/index.ts - Extract helper in app/[...path]/page.tsx to deduplicate password gate check - Extract inner component in app/page.tsx (was 4× inline in minimal/fullbleed/mosaic/split) - Add 8 unit tests for buildSubpageGrid covering undefined, subset fields, layout fallback, and all fields
This commit is contained in:
@@ -12,7 +12,7 @@ vi.mock('@/lib/env', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
import { slugify } from '@/lib/config';
|
||||
import { slugify, buildSubpageGrid } from '@/lib/config';
|
||||
|
||||
describe('slugify', () => {
|
||||
it('converts a simple name to lowercase with hyphens', () => {
|
||||
@@ -51,3 +51,50 @@ describe('slugify', () => {
|
||||
expect(slugify('Album 2024')).toBe('album-2024');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildSubpageGrid', () => {
|
||||
it('returns empty object when called without arguments', () => {
|
||||
expect(buildSubpageGrid()).toEqual({});
|
||||
});
|
||||
|
||||
it('returns empty object when called with undefined', () => {
|
||||
expect(buildSubpageGrid(undefined)).toEqual({});
|
||||
});
|
||||
|
||||
it('maps columns and gap correctly', () => {
|
||||
expect(buildSubpageGrid({ columns: 4, gap: 8 })).toEqual({
|
||||
grid: { columns: 4, gap: 8 },
|
||||
});
|
||||
});
|
||||
|
||||
it('maps aspectRatio correctly', () => {
|
||||
expect(buildSubpageGrid({ aspectRatio: '16/9' })).toEqual({
|
||||
grid: { aspectRatio: '16/9' },
|
||||
});
|
||||
});
|
||||
|
||||
it('preserves a valid layout value', () => {
|
||||
expect(buildSubpageGrid({ layout: 'uniform' })).toEqual({
|
||||
grid: { layout: 'uniform' },
|
||||
});
|
||||
});
|
||||
|
||||
it('falls back to masonry for an unknown layout', () => {
|
||||
expect(buildSubpageGrid({ layout: 'unknown-layout' })).toEqual({
|
||||
grid: { layout: 'masonry' },
|
||||
});
|
||||
});
|
||||
|
||||
it('omits fields that are not supplied', () => {
|
||||
const result = buildSubpageGrid({ columns: 2 });
|
||||
expect(result).toEqual({ grid: { columns: 2 } });
|
||||
expect((result as { grid: object }).grid).not.toHaveProperty('gap');
|
||||
expect((result as { grid: object }).grid).not.toHaveProperty('layout');
|
||||
});
|
||||
|
||||
it('handles all fields together', () => {
|
||||
expect(
|
||||
buildSubpageGrid({ columns: 3, gap: 16, aspectRatio: '1', layout: 'masonry' }),
|
||||
).toEqual({ grid: { columns: 3, gap: 16, aspectRatio: '1', layout: 'masonry' } });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user