Files
klz-cables.com/.pnpm-store/v10/files/3a/2a62fe85df76bcc3dcb6ca0d7efd2df0eaf97733aa260532c27ab35bafc779b57f7f1e3493fd48148d9216c410086b476adb5f8a13c1734454a6fe99817d1e
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

67 lines
1.6 KiB
Plaintext

import { describe, it, expect } from 'vitest';
import { fieldSchemasToFormState } from './index.js';
describe('Form - fieldSchemasToFormState', () => {
const defaultValue = 'Default';
it('populates default value - normal fields', async () => {
const fieldSchema = [{
name: 'text',
type: 'text',
defaultValue,
label: 'Text'
}];
const state = await fieldSchemasToFormState({
req: {},
fields: fieldSchema
});
expect(state.text.value).toBe(defaultValue);
});
it('field value overrides defaultValue - normal fields', async () => {
const value = 'value';
const data = {
text: value
};
const fieldSchema = [{
name: 'text',
type: 'text',
defaultValue,
label: 'Text'
}];
const state = await fieldSchemasToFormState({
req: {},
data,
fields: fieldSchema
});
expect(state.text.value).toBe(value);
});
it('populates default value from a function - normal fields', async () => {
const user = {
email: 'user@example.com'
};
const locale = 'en';
const fieldSchema = [{
name: 'text',
type: 'text',
defaultValue: args => {
if (!args.locale) {
return 'missing locale';
}
if (!args.user) {
return 'missing user';
}
return 'Default';
},
label: 'Text'
}];
const state = await fieldSchemasToFormState({
req: {
locale: 'en',
user: {}
},
fields: fieldSchema,
locale,
user
});
expect(state.text.value).toBe(defaultValue);
});
});
//# sourceMappingURL=fieldSchemasToFormState.spec.js.map