import type { NestableContent, SharedSliceContent, } from "@prismicio/types-internal/lib/content" import type { WidgetContent } from "@prismicio/types-internal/lib/content" import type { DynamicWidget, FieldType, } from "@prismicio/types-internal/lib/customtypes" import type { DiffChange, NestableWidgetDiff, SliceDiff, } from "@prismicio/types-internal/lib/customtypes/diff" import type { SharedSlice, SlicesTypes, } from "@prismicio/types-internal/lib/customtypes/widgets/slices" import type { StaticSlice } from "@prismicio/types-internal/lib/customtypes/widgets/slices/Slice" import type { DynamicSlices } from "@prismicio/types-internal/lib/customtypes/widgets/slices/Slices" import type { MockConfig } from "./MockConfig" import type { NestableWidgetMockConfig } from "./widgets" export type Patch = { diff: NestableWidgetDiff content?: NestableContent | undefined config?: NestableWidgetMockConfig | undefined } export interface WidgetMockWithDiff< D extends DynamicWidget, W extends WidgetContent, C extends | MockConfig< Exclude | "Repeatable", unknown > | undefined = undefined, > { generate(def: D, config?: C): W patch( diff: DiffChange, content?: W, config?: C, ): W | undefined } export interface NestableMock< D extends DynamicWidget, W extends WidgetContent, C extends | MockConfig< Exclude | "Repeatable", unknown > | undefined = undefined, > extends WidgetMockWithDiff { generate(def: D, config?: C): W patch( diff: DiffChange, content?: W, config?: C, ): W | undefined applyPatch(patch: Patch): | { result: W | undefined } | undefined } /** * We support the diff only for shared slice for now we have a dedicated * interface without the patch for now */ export interface WidgetMock< D extends DynamicWidget, W extends WidgetContent, C extends | MockConfig< Exclude | "Repeatable", unknown > | undefined = undefined, > { generate(def: D, config?: C): W } export interface SlicesMock< D extends DynamicWidget, W extends WidgetContent, C extends MockConfig | undefined = undefined, > { generate( def: D, sharedSlices: Partial>, config?: C, ): W } export interface SliceMock< D extends StaticSlice, S extends SharedSliceContent, C extends MockConfig | undefined = undefined, > { generate(def: D, config?: C): S patch( diff: SliceDiff, content?: S, config?: C, ): { ok: true; result: S | undefined } | { ok: false; error: Error } }