.github
.husky
.vscode
packages
app
core
dev-test
src
test
data
collections.mock.ts
config.mock.ts
entry.mock.ts
fields.mock.ts
widgets.mock.ts
harnesses
fileTransformer.js
globalSetup.js
mockFetch.ts
mockLocalStorage.ts
setupEnv.js
test-utils.tsx
tsconfig.json
.editorconfig
.eslintignore
.eslintrc.js
.gitignore
.prettierignore
.prettierrc
babel.config.js
jest.config.integration.js
jest.config.js
package.json
postcss.config.js
tailwind.config.js
tsconfig.base.json
tsconfig.dev.json
tsconfig.json
webpack.config.js
demo
docs
.all-contributorsrc
.eslintignore
.gitattributes
.gitignore
.nvmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.md
lerna.json
netlify.toml
nx.json
package.json
renovate.json
static-cms-icon.png
static-cms-logo.png
tailwind.base.config.js
yarn.lock
81 lines
1.9 KiB
TypeScript
81 lines
1.9 KiB
TypeScript
/* eslint-disable import/prefer-default-export */
|
|
import { createMockCollection } from './collections.mock';
|
|
import { createMockConfig } from './config.mock';
|
|
import { createMockEntry } from './entry.mock';
|
|
|
|
import type {
|
|
BaseField,
|
|
UnknownField,
|
|
ValueOrNestedValue,
|
|
WidgetControlProps,
|
|
} from '@staticcms/core';
|
|
|
|
jest.mock('@staticcms/core/backend');
|
|
|
|
export const createMockWidgetControlProps = <
|
|
T extends ValueOrNestedValue,
|
|
F extends BaseField = UnknownField,
|
|
>(
|
|
options: Omit<
|
|
Partial<WidgetControlProps<T, F>>,
|
|
| 'field'
|
|
| 'data'
|
|
| 'hasErrors'
|
|
| 'onChange'
|
|
| 'openMediaLibrary'
|
|
| 'removeInsertedMedia'
|
|
| 'query'
|
|
| 't'
|
|
> &
|
|
Pick<WidgetControlProps<T, F>, 'field'>,
|
|
): WidgetControlProps<T, F> => {
|
|
const {
|
|
value: rawValue,
|
|
path: rawPath,
|
|
errors: rawErrors,
|
|
fieldsErrors: rawFieldsErrors,
|
|
collection: rawCollection,
|
|
config: rawConfig,
|
|
entry: rawEntry,
|
|
...extra
|
|
} = options;
|
|
|
|
const value = rawValue ?? null;
|
|
|
|
const collection = rawCollection ?? createMockCollection({}, options.field);
|
|
const config = rawConfig ?? createMockConfig({ collections: [collection] });
|
|
const entry = rawEntry ?? createMockEntry({ data: { [options.field.name]: value } });
|
|
|
|
const path = rawPath ?? '';
|
|
const errors = rawErrors ?? [];
|
|
const fieldsErrors =
|
|
rawFieldsErrors ?? (rawErrors ? { [`${path}.${options.field.name}`]: errors } : {});
|
|
const hasErrors = Boolean(rawErrors && rawErrors.length > 0);
|
|
|
|
return {
|
|
label: 'Mock Widget',
|
|
config,
|
|
collection,
|
|
collectionFile: undefined,
|
|
entry,
|
|
value,
|
|
path,
|
|
fieldsErrors,
|
|
errors,
|
|
hasErrors,
|
|
submitted: false,
|
|
forList: false,
|
|
forSingleList: false,
|
|
disabled: false,
|
|
locale: undefined,
|
|
i18n: undefined,
|
|
duplicate: false,
|
|
controlled: false,
|
|
theme: 'light',
|
|
onChange: jest.fn(),
|
|
query: jest.fn(),
|
|
t: jest.fn(),
|
|
...extra,
|
|
};
|
|
};
|