Files
klz-cables.com/.pnpm-store/v10/files/8d/ccb3a311f028dd8593d74ed76a0fffae8dd321d7bfcf821378e274b7d4c5ee5a251642420d0aee40c5f5cab4c13dea56b8ab23ea5667217abfaf91381b25f1
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

187 lines
6.1 KiB
Plaintext

import { InvalidConfiguration } from '../../errors/InvalidConfiguration.js';
import { sanitizeCollection } from './sanitize.js';
import { describe, it, expect } from 'vitest';
describe('sanitize - collections -', ()=>{
const config = {
collections: [],
globals: []
};
describe('validate useAsTitle -', ()=>{
const defaultCollection = {
slug: 'collection-with-defaults',
fields: [
{
name: 'title',
type: 'text'
}
]
};
it('should throw on invalid field', async ()=>{
const collectionConfig = {
...defaultCollection,
admin: {
useAsTitle: 'invalidField'
}
};
await expect(async ()=>{
await sanitizeCollection(// @ts-expect-error
{
...config,
collections: [
collectionConfig
]
}, collectionConfig);
}).rejects.toThrow(InvalidConfiguration);
});
it('should not throw on valid field', async ()=>{
const collectionConfig = {
...defaultCollection,
admin: {
useAsTitle: 'title'
}
};
await expect(async ()=>{
await sanitizeCollection(// @ts-expect-error
{
...config,
collections: [
collectionConfig
]
}, collectionConfig);
}).not.toThrow();
});
it('should not throw on valid field inside tabs', async ()=>{
const collectionConfig = {
...defaultCollection,
admin: {
useAsTitle: 'title'
},
fields: [
{
type: 'tabs',
tabs: [
{
label: 'General',
fields: [
{
name: 'title',
type: 'text'
}
]
}
]
}
]
};
await expect(async ()=>{
await sanitizeCollection(// @ts-expect-error
{
...config,
collections: [
collectionConfig
]
}, collectionConfig);
}).not.toThrow();
});
it('should not throw on valid field inside collapsibles', async ()=>{
const collectionConfig = {
...defaultCollection,
admin: {
useAsTitle: 'title'
},
fields: [
{
type: 'collapsible',
label: 'Collapsible',
fields: [
{
name: 'title',
type: 'text'
}
]
}
]
};
await expect(async ()=>{
await sanitizeCollection(// @ts-expect-error
{
...config,
collections: [
collectionConfig
]
}, collectionConfig);
}).not.toThrow();
});
it('should throw on nested useAsTitle', async ()=>{
const collectionConfig = {
...defaultCollection,
admin: {
useAsTitle: 'content.title'
}
};
await expect(async ()=>{
await sanitizeCollection(// @ts-expect-error
{
...config,
collections: [
collectionConfig
]
}, collectionConfig);
}).rejects.toThrow(InvalidConfiguration);
});
it('should not throw on default field: id', async ()=>{
const collectionConfig = {
...defaultCollection,
admin: {
useAsTitle: 'id'
}
};
await expect(async ()=>{
await sanitizeCollection(// @ts-expect-error
{
...config,
collections: [
collectionConfig
]
}, collectionConfig);
}).not.toThrow();
});
it('should not throw on default field: email if auth is enabled', async ()=>{
const collectionConfig = {
...defaultCollection,
auth: true,
admin: {
useAsTitle: 'email'
}
};
await expect(async ()=>{
await sanitizeCollection(// @ts-expect-error
{
...config,
collections: [
collectionConfig
]
}, collectionConfig);
}).not.toThrow();
});
it('should throw on default field: email if auth is not enabled', async ()=>{
const collectionConfig = {
...defaultCollection,
admin: {
useAsTitle: 'email'
}
};
await expect(async ()=>{
await sanitizeCollection(// @ts-expect-error
{
...config,
collections: [
collectionConfig
]
}, collectionConfig);
}).rejects.toThrow(InvalidConfiguration);
});
});
});
//# sourceMappingURL=useAsTitle.spec.js.map