diff options
Diffstat (limited to 'spec/frontend/editor/helpers.js')
-rw-r--r-- | spec/frontend/editor/helpers.js | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/spec/frontend/editor/helpers.js b/spec/frontend/editor/helpers.js index 6f7cdf6efb3..252d783ad6d 100644 --- a/spec/frontend/editor/helpers.js +++ b/spec/frontend/editor/helpers.js @@ -1,4 +1,22 @@ -export class MyClassExtension { +/* eslint-disable max-classes-per-file */ + +// Helpers +export const spyOnApi = (extension, spiesObj = {}) => { + const origApi = extension.api; + if (extension?.obj) { + jest.spyOn(extension.obj, 'provides').mockReturnValue({ + ...origApi, + ...spiesObj, + }); + } +}; + +// Dummy Extensions +export class SEClassExtension { + static get extensionName() { + return 'SEClassExtension'; + } + // eslint-disable-next-line class-methods-use-this provides() { return { @@ -8,8 +26,9 @@ export class MyClassExtension { } } -export function MyFnExtension() { +export function SEFnExtension() { return { + extensionName: 'SEFnExtension', fnExtMethod: () => 'fn own method', provides: () => { return { @@ -19,8 +38,9 @@ export function MyFnExtension() { }; } -export const MyConstExt = () => { +export const SEConstExt = () => { return { + extensionName: 'SEConstExt', provides: () => { return { constExtMethod: () => 'const own method', @@ -29,9 +49,39 @@ export const MyConstExt = () => { }; }; +export class SEWithSetupExt { + static get extensionName() { + return 'SEWithSetupExt'; + } + // eslint-disable-next-line class-methods-use-this + onSetup(instance, setupOptions = {}) { + if (setupOptions && !Array.isArray(setupOptions)) { + Object.entries(setupOptions).forEach(([key, value]) => { + Object.assign(instance, { + [key]: value, + }); + }); + } + } + provides() { + return { + returnInstanceAndProps: (instance, stringProp, objProp = {}) => { + return [stringProp, objProp, instance]; + }, + returnInstance: (instance) => { + return instance; + }, + giveMeContext: () => { + return this; + }, + }; + } +} + export const conflictingExtensions = { WithInstanceExt: () => { return { + extensionName: 'WithInstanceExt', provides: () => { return { use: () => 'A conflict with instance', @@ -42,6 +92,7 @@ export const conflictingExtensions = { }, WithAnotherExt: () => { return { + extensionName: 'WithAnotherExt', provides: () => { return { shared: () => 'A conflict with extension', |