feat: v4.0.0 (#1016)
Co-authored-by: Denys Konovalov <kontakt@denyskon.de> Co-authored-by: Mathieu COSYNS <64072917+Mathieu-COSYNS@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
682576ffc4
commit
799c7e6936
@ -1,10 +1,20 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import type { BaseField, Collection, Field } from '@staticcms/core/interface';
|
||||
import type {
|
||||
BaseField,
|
||||
Collection,
|
||||
CollectionFile,
|
||||
CollectionFileWithDefaults,
|
||||
CollectionWithDefaults,
|
||||
Field,
|
||||
FilesCollection,
|
||||
FilesCollectionWithDefaults,
|
||||
FolderCollection,
|
||||
FolderCollectionWithDefaults,
|
||||
} from '@staticcms/core';
|
||||
|
||||
export const createMockCollection = <EF extends BaseField>(
|
||||
export const createMockFolderCollection = <EF extends BaseField>(
|
||||
extra: Partial<Collection<EF>> = {},
|
||||
...fields: Field<EF>[]
|
||||
): Collection<EF> => ({
|
||||
): FolderCollection<EF> => ({
|
||||
name: 'mock_collection',
|
||||
label: 'Mock Collections',
|
||||
label_singular: 'Mock Collection',
|
||||
@ -29,3 +39,67 @@ export const createMockCollection = <EF extends BaseField>(
|
||||
],
|
||||
...extra,
|
||||
});
|
||||
|
||||
export const createMockFolderCollectionWithDefaults = <EF extends BaseField>(
|
||||
extra: Partial<CollectionWithDefaults<EF>> = {},
|
||||
...fields: Field<EF>[]
|
||||
): FolderCollectionWithDefaults<EF> => ({
|
||||
...createMockFolderCollection(extra, ...fields),
|
||||
i18n: extra.i18n,
|
||||
});
|
||||
|
||||
export const createMockCollectionFile = <EF extends BaseField>(
|
||||
extra: Partial<CollectionFile<EF>> = {},
|
||||
...fields: Field<EF>[]
|
||||
): CollectionFile<EF> => ({
|
||||
name: 'mock_collection',
|
||||
label: 'Mock Collections',
|
||||
label_singular: 'Mock Collection',
|
||||
file: 'mock_collection.md',
|
||||
description:
|
||||
'The description is a great place for tone setting, high level information, and editing guidelines that are specific to a collection.\n',
|
||||
fields: [
|
||||
{
|
||||
label: 'Title',
|
||||
name: 'title',
|
||||
widget: 'string',
|
||||
},
|
||||
...fields,
|
||||
],
|
||||
...extra,
|
||||
});
|
||||
|
||||
export const createMockCollectionFileWithDefaults = <EF extends BaseField>(
|
||||
extra: Partial<CollectionFileWithDefaults<EF>> = {},
|
||||
...fields: Field<EF>[]
|
||||
): CollectionFileWithDefaults<EF> => ({
|
||||
...createMockCollectionFile(extra, ...fields),
|
||||
i18n: extra.i18n,
|
||||
});
|
||||
|
||||
export const createMockFilesCollection = <EF extends BaseField>(
|
||||
extra: Omit<Partial<FilesCollection<EF>>, 'files'> & Pick<FilesCollection<EF>, 'files'>,
|
||||
): FilesCollection<EF> => ({
|
||||
name: 'mock_collection',
|
||||
label: 'Mock Collections',
|
||||
label_singular: 'Mock Collection',
|
||||
description:
|
||||
'The description is a great place for tone setting, high level information, and editing guidelines that are specific to a collection.\n',
|
||||
summary: '{{title}}',
|
||||
sortable_fields: {
|
||||
fields: ['title'],
|
||||
default: {
|
||||
field: 'title',
|
||||
},
|
||||
},
|
||||
...extra,
|
||||
});
|
||||
|
||||
export const createMockFilesCollectionWithDefaults = <EF extends BaseField>(
|
||||
extra: Omit<Partial<FilesCollectionWithDefaults<EF>>, 'files'> &
|
||||
Pick<FilesCollectionWithDefaults<EF>, 'files'>,
|
||||
): FilesCollectionWithDefaults<EF> => ({
|
||||
...createMockFilesCollection(extra),
|
||||
i18n: extra.i18n,
|
||||
files: extra.files,
|
||||
});
|
||||
|
@ -1,11 +1,20 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import { applyDefaults } from '@staticcms/core/actions/config';
|
||||
|
||||
import type { BaseField, Config } from '@staticcms/core';
|
||||
import type { BaseField, Config, ConfigWithDefaults } from '@staticcms/core';
|
||||
|
||||
export const createNoDefaultsMockConfig = <EF extends BaseField>(
|
||||
options: Omit<Partial<Config<EF>>, 'collections'> & Pick<Config<EF>, 'collections'>,
|
||||
): Config<EF> => ({
|
||||
backend: {
|
||||
name: 'test-repo',
|
||||
},
|
||||
...options,
|
||||
});
|
||||
|
||||
export const createMockConfig = <EF extends BaseField>(
|
||||
options: Omit<Partial<Config<EF>>, 'collections'> & Pick<Config<EF>, 'collections'>,
|
||||
): Config<EF> =>
|
||||
): ConfigWithDefaults<EF> =>
|
||||
applyDefaults({
|
||||
backend: {
|
||||
name: 'test-repo',
|
||||
|
@ -1,5 +1,6 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import type { Entry } from '@staticcms/core';
|
||||
import { WorkflowStatus } from '@staticcms/core/constants/publishModes';
|
||||
|
||||
import type { Entry, UnpublishedEntry } from '@staticcms/core';
|
||||
|
||||
export const createMockEntry = (
|
||||
options: Omit<Partial<Entry>, 'data'> & Pick<Entry, 'data'>,
|
||||
@ -14,5 +15,38 @@ export const createMockEntry = (
|
||||
mediaFiles: [],
|
||||
author: 'Some Person',
|
||||
updatedOn: '20230-02-09T00:00:00.000Z',
|
||||
openAuthoring: false,
|
||||
...options,
|
||||
});
|
||||
|
||||
export const createMockExpandedEntry = (
|
||||
options: Omit<Partial<Entry>, 'data'> & Pick<Entry, 'data'> & { field: string },
|
||||
): Entry & { field: string } => ({
|
||||
collection: 'mock_collection',
|
||||
slug: 'slug-value',
|
||||
path: '/path/to/entry',
|
||||
partial: false,
|
||||
raw: JSON.stringify(options.data),
|
||||
label: 'Entry',
|
||||
isModification: false,
|
||||
mediaFiles: [],
|
||||
author: 'Some Person',
|
||||
updatedOn: '20230-02-09T00:00:00.000Z',
|
||||
openAuthoring: false,
|
||||
...options,
|
||||
});
|
||||
|
||||
export const createMockUnpublishedEntry = (
|
||||
options: Partial<UnpublishedEntry>,
|
||||
): UnpublishedEntry => ({
|
||||
slug: 'unpublished-entry.md',
|
||||
collection: 'posts',
|
||||
status: WorkflowStatus.DRAFT,
|
||||
diffs: [
|
||||
{ id: 'index.md', path: 'src/posts/index.md', newFile: false },
|
||||
{ id: 'netlify.png', path: 'netlify.png', newFile: true },
|
||||
],
|
||||
updatedAt: '20230-02-09T00:00:00.000Z',
|
||||
openAuthoring: false,
|
||||
...options,
|
||||
});
|
||||
|
@ -8,7 +8,8 @@ import type {
|
||||
NumberField,
|
||||
RelationField,
|
||||
SelectField,
|
||||
StringOrTextField,
|
||||
StringField,
|
||||
TextField,
|
||||
UUIDField,
|
||||
} from '@staticcms/core';
|
||||
|
||||
@ -66,7 +67,7 @@ export const mockMarkdownField: MarkdownField = {
|
||||
label: 'Body',
|
||||
name: 'body',
|
||||
widget: 'markdown',
|
||||
hint: 'Main content goes here.',
|
||||
hint: '*Main* __content__ __*goes*__ [here](https://example.com/).',
|
||||
};
|
||||
|
||||
export const mockNumberField: NumberField = {
|
||||
@ -92,13 +93,13 @@ export const mockSelectField: SelectField = {
|
||||
options: ['Option 1', 'Option 2', 'Option 3'],
|
||||
};
|
||||
|
||||
export const mockStringField: StringOrTextField = {
|
||||
export const mockStringField: StringField = {
|
||||
label: 'String',
|
||||
name: 'mock_string',
|
||||
widget: 'string',
|
||||
};
|
||||
|
||||
export const mockTextField: StringOrTextField = {
|
||||
export const mockTextField: TextField = {
|
||||
label: 'Text',
|
||||
name: 'mock_text',
|
||||
widget: 'text',
|
||||
|
@ -1,5 +1,6 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import { createMockCollection } from './collections.mock';
|
||||
import { applyDefaults } from '@staticcms/core/actions/config';
|
||||
import { createMockFolderCollection } from './collections.mock';
|
||||
import { createMockConfig } from './config.mock';
|
||||
import { createMockEntry } from './entry.mock';
|
||||
|
||||
@ -34,7 +35,7 @@ export const createMockWidgetControlProps = <T, F extends BaseField = UnknownFie
|
||||
|
||||
const value = rawValue ?? null;
|
||||
|
||||
const collection = rawCollection ?? createMockCollection({}, options.field);
|
||||
const collection = rawCollection ?? createMockFolderCollection({}, options.field);
|
||||
const config = rawConfig ?? createMockConfig({ collections: [collection] });
|
||||
const entry = rawEntry ?? createMockEntry({ data: { [options.field.name]: value } });
|
||||
|
||||
@ -44,10 +45,12 @@ export const createMockWidgetControlProps = <T, F extends BaseField = UnknownFie
|
||||
rawFieldsErrors ?? (rawErrors ? { [`${path}.${options.field.name}`]: errors } : {});
|
||||
const hasErrors = Boolean(rawErrors && rawErrors.length > 0);
|
||||
|
||||
const configWithDefaults = applyDefaults(config);
|
||||
|
||||
return {
|
||||
label: 'Mock Widget',
|
||||
config,
|
||||
collection,
|
||||
config: configWithDefaults,
|
||||
collection: configWithDefaults.collections[0],
|
||||
collectionFile: undefined,
|
||||
entry,
|
||||
value,
|
||||
@ -64,7 +67,6 @@ export const createMockWidgetControlProps = <T, F extends BaseField = UnknownFie
|
||||
i18n: undefined,
|
||||
duplicate: false,
|
||||
controlled: false,
|
||||
theme: 'light',
|
||||
onChange: jest.fn(),
|
||||
clearChildValidation: jest.fn(),
|
||||
query: jest.fn(),
|
||||
|
Reference in New Issue
Block a user