Commit bbf96ce6 authored by Peter Hegman's avatar Peter Hegman

Merge branch '292943-test-coverage' into 'master'

Extended tests coverage for SE instance

See merge request gitlab-org/gitlab!74907
parents 4c6abd99 b3394407
......@@ -73,9 +73,7 @@ export default class EditorInstance {
if (methodExtension) {
const extension = extensionsStore.get(methodExtension);
return (...args) => {
return extension.api[prop].call(seInstance, ...args, receiver);
};
return (...args) => extension.api[prop].call(seInstance, receiver, ...args);
}
return Reflect.get(seInstance[prop] ? seInstance : target, prop, receiver);
},
......
export class MyClassExtension {
export class SEClassExtension {
// eslint-disable-next-line class-methods-use-this
provides() {
return {
......@@ -8,7 +8,7 @@ export class MyClassExtension {
}
}
export function MyFnExtension() {
export function SEFnExtension() {
return {
fnExtMethod: () => 'fn own method',
provides: () => {
......@@ -19,7 +19,7 @@ export function MyFnExtension() {
};
}
export const MyConstExt = () => {
export const SEConstExt = () => {
return {
provides: () => {
return {
......@@ -29,6 +29,33 @@ export const MyConstExt = () => {
};
};
export function SEWithSetupExt() {
return {
onSetup: (setupOptions = {}, instance) => {
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 {
......
......@@ -22,15 +22,15 @@ describe('Editor Extension', () => {
it.each`
definition | setupOptions | expectedName
${helpers.MyClassExtension} | ${undefined} | ${'MyClassExtension'}
${helpers.MyClassExtension} | ${{}} | ${'MyClassExtension'}
${helpers.MyClassExtension} | ${dummyObj} | ${'MyClassExtension'}
${helpers.MyFnExtension} | ${undefined} | ${'MyFnExtension'}
${helpers.MyFnExtension} | ${{}} | ${'MyFnExtension'}
${helpers.MyFnExtension} | ${dummyObj} | ${'MyFnExtension'}
${helpers.MyConstExt} | ${undefined} | ${'MyConstExt'}
${helpers.MyConstExt} | ${{}} | ${'MyConstExt'}
${helpers.MyConstExt} | ${dummyObj} | ${'MyConstExt'}
${helpers.SEClassExtension} | ${undefined} | ${'SEClassExtension'}
${helpers.SEClassExtension} | ${{}} | ${'SEClassExtension'}
${helpers.SEClassExtension} | ${dummyObj} | ${'SEClassExtension'}
${helpers.SEFnExtension} | ${undefined} | ${'SEFnExtension'}
${helpers.SEFnExtension} | ${{}} | ${'SEFnExtension'}
${helpers.SEFnExtension} | ${dummyObj} | ${'SEFnExtension'}
${helpers.SEConstExt} | ${undefined} | ${'SEConstExt'}
${helpers.SEConstExt} | ${{}} | ${'SEConstExt'}
${helpers.SEConstExt} | ${dummyObj} | ${'SEConstExt'}
`(
'correctly creates extension for definition = $definition and setupOptions = $setupOptions',
({ definition, setupOptions, expectedName }) => {
......@@ -51,9 +51,9 @@ describe('Editor Extension', () => {
describe('api', () => {
it.each`
definition | expectedKeys
${helpers.MyClassExtension} | ${['shared', 'classExtMethod']}
${helpers.MyFnExtension} | ${['fnExtMethod']}
${helpers.MyConstExt} | ${['constExtMethod']}
${helpers.SEClassExtension} | ${['shared', 'classExtMethod']}
${helpers.SEFnExtension} | ${['fnExtMethod']}
${helpers.SEConstExt} | ${['constExtMethod']}
`('correctly returns API for $definition', ({ definition, expectedKeys }) => {
const extension = new EditorExtension({ definition });
const expectedApi = Object.fromEntries(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment