debian-mirror-gitlab/spec/frontend/editor/helpers.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-01-26 12:08:38 +05:30
/* 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';
}
2021-12-11 22:18:48 +05:30
// eslint-disable-next-line class-methods-use-this
provides() {
return {
shared: () => 'extension',
classExtMethod: () => 'class own method',
};
}
}
2022-01-26 12:08:38 +05:30
export function SEFnExtension() {
2021-12-11 22:18:48 +05:30
return {
2022-01-26 12:08:38 +05:30
extensionName: 'SEFnExtension',
2021-12-11 22:18:48 +05:30
fnExtMethod: () => 'fn own method',
provides: () => {
return {
fnExtMethod: () => 'class own method',
};
},
};
}
2022-01-26 12:08:38 +05:30
export const SEConstExt = () => {
2021-12-11 22:18:48 +05:30
return {
2022-01-26 12:08:38 +05:30
extensionName: 'SEConstExt',
2021-12-11 22:18:48 +05:30
provides: () => {
return {
constExtMethod: () => 'const own method',
};
},
};
};
2022-07-23 23:45:48 +05:30
export const SEExtWithoutAPI = () => {
return {
extensionName: 'SEExtWithoutAPI',
};
};
2022-01-26 12:08:38 +05:30
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;
},
};
}
}
2021-12-11 22:18:48 +05:30
export const conflictingExtensions = {
WithInstanceExt: () => {
return {
2022-01-26 12:08:38 +05:30
extensionName: 'WithInstanceExt',
2021-12-11 22:18:48 +05:30
provides: () => {
return {
use: () => 'A conflict with instance',
ownMethod: () => 'Non-conflicting method',
};
},
};
},
WithAnotherExt: () => {
return {
2022-01-26 12:08:38 +05:30
extensionName: 'WithAnotherExt',
2021-12-11 22:18:48 +05:30
provides: () => {
return {
shared: () => 'A conflict with extension',
ownMethod: () => 'Non-conflicting method',
};
},
};
},
};