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 { ...@@ -73,9 +73,7 @@ export default class EditorInstance {
if (methodExtension) { if (methodExtension) {
const extension = extensionsStore.get(methodExtension); const extension = extensionsStore.get(methodExtension);
return (...args) => { return (...args) => extension.api[prop].call(seInstance, receiver, ...args);
return extension.api[prop].call(seInstance, ...args, receiver);
};
} }
return Reflect.get(seInstance[prop] ? seInstance : target, prop, receiver); return Reflect.get(seInstance[prop] ? seInstance : target, prop, receiver);
}, },
......
export class MyClassExtension { export class SEClassExtension {
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
provides() { provides() {
return { return {
...@@ -8,7 +8,7 @@ export class MyClassExtension { ...@@ -8,7 +8,7 @@ export class MyClassExtension {
} }
} }
export function MyFnExtension() { export function SEFnExtension() {
return { return {
fnExtMethod: () => 'fn own method', fnExtMethod: () => 'fn own method',
provides: () => { provides: () => {
...@@ -19,7 +19,7 @@ export function MyFnExtension() { ...@@ -19,7 +19,7 @@ export function MyFnExtension() {
}; };
} }
export const MyConstExt = () => { export const SEConstExt = () => {
return { return {
provides: () => { provides: () => {
return { return {
...@@ -29,6 +29,33 @@ export const MyConstExt = () => { ...@@ -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 = { export const conflictingExtensions = {
WithInstanceExt: () => { WithInstanceExt: () => {
return { return {
......
...@@ -22,15 +22,15 @@ describe('Editor Extension', () => { ...@@ -22,15 +22,15 @@ describe('Editor Extension', () => {
it.each` it.each`
definition | setupOptions | expectedName definition | setupOptions | expectedName
${helpers.MyClassExtension} | ${undefined} | ${'MyClassExtension'} ${helpers.SEClassExtension} | ${undefined} | ${'SEClassExtension'}
${helpers.MyClassExtension} | ${{}} | ${'MyClassExtension'} ${helpers.SEClassExtension} | ${{}} | ${'SEClassExtension'}
${helpers.MyClassExtension} | ${dummyObj} | ${'MyClassExtension'} ${helpers.SEClassExtension} | ${dummyObj} | ${'SEClassExtension'}
${helpers.MyFnExtension} | ${undefined} | ${'MyFnExtension'} ${helpers.SEFnExtension} | ${undefined} | ${'SEFnExtension'}
${helpers.MyFnExtension} | ${{}} | ${'MyFnExtension'} ${helpers.SEFnExtension} | ${{}} | ${'SEFnExtension'}
${helpers.MyFnExtension} | ${dummyObj} | ${'MyFnExtension'} ${helpers.SEFnExtension} | ${dummyObj} | ${'SEFnExtension'}
${helpers.MyConstExt} | ${undefined} | ${'MyConstExt'} ${helpers.SEConstExt} | ${undefined} | ${'SEConstExt'}
${helpers.MyConstExt} | ${{}} | ${'MyConstExt'} ${helpers.SEConstExt} | ${{}} | ${'SEConstExt'}
${helpers.MyConstExt} | ${dummyObj} | ${'MyConstExt'} ${helpers.SEConstExt} | ${dummyObj} | ${'SEConstExt'}
`( `(
'correctly creates extension for definition = $definition and setupOptions = $setupOptions', 'correctly creates extension for definition = $definition and setupOptions = $setupOptions',
({ definition, setupOptions, expectedName }) => { ({ definition, setupOptions, expectedName }) => {
...@@ -51,9 +51,9 @@ describe('Editor Extension', () => { ...@@ -51,9 +51,9 @@ describe('Editor Extension', () => {
describe('api', () => { describe('api', () => {
it.each` it.each`
definition | expectedKeys definition | expectedKeys
${helpers.MyClassExtension} | ${['shared', 'classExtMethod']} ${helpers.SEClassExtension} | ${['shared', 'classExtMethod']}
${helpers.MyFnExtension} | ${['fnExtMethod']} ${helpers.SEFnExtension} | ${['fnExtMethod']}
${helpers.MyConstExt} | ${['constExtMethod']} ${helpers.SEConstExt} | ${['constExtMethod']}
`('correctly returns API for $definition', ({ definition, expectedKeys }) => { `('correctly returns API for $definition', ({ definition, expectedKeys }) => {
const extension = new EditorExtension({ definition }); const extension = new EditorExtension({ definition });
const expectedApi = Object.fromEntries( 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