2021-12-15 10:15:54 -05:00
|
|
|
/* 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
|
2021-11-23 16:10:02 -05:00
|
|
|
export class SEClassExtension {
|
2021-12-15 10:15:54 -05:00
|
|
|
static get extensionName() {
|
|
|
|
return 'SEClassExtension';
|
|
|
|
}
|
|
|
|
|
2021-11-16 10:13:28 -05:00
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
provides() {
|
|
|
|
return {
|
|
|
|
shared: () => 'extension',
|
|
|
|
classExtMethod: () => 'class own method',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:10:02 -05:00
|
|
|
export function SEFnExtension() {
|
2021-11-16 10:13:28 -05:00
|
|
|
return {
|
2021-12-15 10:15:54 -05:00
|
|
|
extensionName: 'SEFnExtension',
|
2021-11-16 10:13:28 -05:00
|
|
|
fnExtMethod: () => 'fn own method',
|
|
|
|
provides: () => {
|
|
|
|
return {
|
|
|
|
fnExtMethod: () => 'class own method',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:10:02 -05:00
|
|
|
export const SEConstExt = () => {
|
2021-11-16 10:13:28 -05:00
|
|
|
return {
|
2021-12-15 10:15:54 -05:00
|
|
|
extensionName: 'SEConstExt',
|
2021-11-16 10:13:28 -05:00
|
|
|
provides: () => {
|
|
|
|
return {
|
|
|
|
constExtMethod: () => 'const own method',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-05-25 05:08:47 -04:00
|
|
|
export const SEExtWithoutAPI = () => {
|
|
|
|
return {
|
|
|
|
extensionName: 'SEExtWithoutAPI',
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-12-15 10:15:54 -05:00
|
|
|
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,
|
2021-11-23 16:10:02 -05:00
|
|
|
});
|
2021-12-15 10:15:54 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
provides() {
|
|
|
|
return {
|
|
|
|
returnInstanceAndProps: (instance, stringProp, objProp = {}) => {
|
|
|
|
return [stringProp, objProp, instance];
|
|
|
|
},
|
|
|
|
returnInstance: (instance) => {
|
|
|
|
return instance;
|
|
|
|
},
|
|
|
|
giveMeContext: () => {
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2021-11-23 16:10:02 -05:00
|
|
|
}
|
|
|
|
|
2021-11-16 10:13:28 -05:00
|
|
|
export const conflictingExtensions = {
|
|
|
|
WithInstanceExt: () => {
|
|
|
|
return {
|
2021-12-15 10:15:54 -05:00
|
|
|
extensionName: 'WithInstanceExt',
|
2021-11-16 10:13:28 -05:00
|
|
|
provides: () => {
|
|
|
|
return {
|
|
|
|
use: () => 'A conflict with instance',
|
|
|
|
ownMethod: () => 'Non-conflicting method',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
WithAnotherExt: () => {
|
|
|
|
return {
|
2021-12-15 10:15:54 -05:00
|
|
|
extensionName: 'WithAnotherExt',
|
2021-11-16 10:13:28 -05:00
|
|
|
provides: () => {
|
|
|
|
return {
|
|
|
|
shared: () => 'A conflict with extension',
|
|
|
|
ownMethod: () => 'Non-conflicting method',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|