release: v0.20.0
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { validateSettingValues } from '../config/settingValues';
|
||||
import { resolveTheme } from '../config/theme';
|
||||
import { resolveContact, sanitizeNavLinks } from '../config';
|
||||
import { normaliseSiteUrl } from '../siteUrl';
|
||||
|
||||
const fields = (input: unknown) => validateSettingValues(input).map((e) => e.field);
|
||||
@@ -50,4 +51,48 @@ describe('validateSettingValues', () => {
|
||||
expect(fields({ grid: { columns: 1, gap: 0 } })).toEqual([]);
|
||||
expect(fields({ grid: { columns: 6, gap: 48 } })).toEqual([]);
|
||||
});
|
||||
|
||||
it('refuses a corner radius resolveTheme would clamp, and only that', () => {
|
||||
for (const radius of [-1, 65, 200, Number.NaN]) {
|
||||
expect(fields({ theme: { radius } })).toEqual(['theme.radius']);
|
||||
expect(resolveTheme({ preset: 'minimal', radius }).radius).not.toBe(radius);
|
||||
}
|
||||
for (const radius of [0, 8, 1.5, 64]) {
|
||||
expect(fields({ theme: { radius } })).toEqual([]);
|
||||
expect(resolveTheme({ preset: 'minimal', radius }).radius).toBe(radius);
|
||||
}
|
||||
});
|
||||
|
||||
it('refuses a retention resolveContact would round or clamp, and only that', () => {
|
||||
for (const retentionDays of [0, -3, 366, 30.5]) {
|
||||
expect(fields({ contact: { retentionDays } })).toEqual(['contact.retentionDays']);
|
||||
expect(resolveContact({ retentionDays }).retentionDays).not.toBe(retentionDays);
|
||||
}
|
||||
for (const retentionDays of [1, 90, 365]) {
|
||||
expect(fields({ contact: { retentionDays } })).toEqual([]);
|
||||
expect(resolveContact({ retentionDays }).retentionDays).toBe(retentionDays);
|
||||
}
|
||||
expect(fields({ contact: { enabled: true } })).toEqual([]);
|
||||
});
|
||||
|
||||
it('refuses exactly the header links sanitizeNavLinks drops, per input', () => {
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
const links = [
|
||||
{ label: 'Shop', url: 'https://shop.example' },
|
||||
{ label: 'Blog', url: 'blog.example' },
|
||||
{ label: ' ', url: 'http://ok.example' },
|
||||
{ label: 'Evil', url: 'javascript:alert(1)' },
|
||||
{ label: '', url: '' },
|
||||
];
|
||||
expect(fields({ navLinks: links })).toEqual([
|
||||
'navLinks.1.url',
|
||||
'navLinks.2.label',
|
||||
'navLinks.3.url',
|
||||
'navLinks.4.label',
|
||||
'navLinks.4.url',
|
||||
]);
|
||||
// The resolver keeps exactly the entries with no error.
|
||||
expect(sanitizeNavLinks(links)).toEqual([{ label: 'Shop', url: 'https://shop.example' }]);
|
||||
warn.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user