mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2025-12-19 17:58:43 -05:00
feat(VNA-409): check chart own handler (#1847)
* feat(VNA-409): check chart own handler
This commit is contained in:
committed by
GitHub
parent
85e869821a
commit
7f03c1cd13
@@ -26,6 +26,9 @@ describe('viz', () => {
|
||||
let convertToMock;
|
||||
let createSessionObjectMock;
|
||||
let destroySessionObjectMock;
|
||||
let mockCustomHandler;
|
||||
let mockCustomDataHandler;
|
||||
let mockGetHypercubePath;
|
||||
|
||||
let mockElement;
|
||||
|
||||
@@ -43,6 +46,9 @@ describe('viz', () => {
|
||||
getImperativeHandle = jest.fn(async () => ({
|
||||
api: 'api',
|
||||
}));
|
||||
mockCustomHandler = { customMethod: jest.fn() };
|
||||
mockCustomDataHandler = jest.fn().mockReturnValue(mockCustomHandler);
|
||||
mockGetHypercubePath = jest.fn().mockReturnValue('customPath');
|
||||
cellRef = {
|
||||
current: {
|
||||
setSnOptions,
|
||||
@@ -53,6 +59,7 @@ describe('viz', () => {
|
||||
takeSnapshot,
|
||||
exportImage,
|
||||
getImperativeHandle,
|
||||
getHypercubePath: mockGetHypercubePath,
|
||||
},
|
||||
};
|
||||
glue = jest.fn().mockReturnValue([unmountMock, cellRef]);
|
||||
@@ -311,4 +318,104 @@ describe('viz', () => {
|
||||
expect(panelDef.name).toEqual('old');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getHypercubePropertyHandler', () => {
|
||||
test('should return default HyperCubeHandler when no custom dataHandler exists', async () => {
|
||||
const opts = { onInitialRender: jest.fn() };
|
||||
api.__DO_NOT_USE__.options(opts);
|
||||
await mounted;
|
||||
|
||||
cellRef.current.getExtensionDefinition = jest.fn().mockReturnValue({
|
||||
data: {
|
||||
dimensions: { min: 1, max: 10 },
|
||||
measures: { min: 1, max: 10 },
|
||||
},
|
||||
definition: {},
|
||||
});
|
||||
|
||||
const args = cellRef.current.setSnOptions.mock.lastCall[0];
|
||||
args.onInitialRender();
|
||||
|
||||
const handler = await api.getHypercubePropertyHandler();
|
||||
|
||||
expect(handler.constructor.name).toBe('HyperCubeHandler');
|
||||
expect(cellRef.current.getExtensionDefinition).toHaveBeenCalled();
|
||||
expect(model.getEffectiveProperties).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('should return custom handler when dataHandler exists in extension definition', async () => {
|
||||
const opts = { onInitialRender: jest.fn() };
|
||||
api.__DO_NOT_USE__.options(opts);
|
||||
await mounted;
|
||||
|
||||
cellRef.current.getExtensionDefinition = jest.fn().mockReturnValue({
|
||||
data: {
|
||||
dimensions: { min: 1, max: 10 },
|
||||
measures: { min: 1, max: 10 },
|
||||
},
|
||||
definition: {
|
||||
dataHandler: mockCustomDataHandler,
|
||||
},
|
||||
});
|
||||
|
||||
const args = cellRef.current.setSnOptions.mock.lastCall[0];
|
||||
args.onInitialRender();
|
||||
|
||||
const handler = await api.getHypercubePropertyHandler();
|
||||
|
||||
expect(handler).toBe(mockCustomHandler);
|
||||
expect(mockCustomDataHandler).toHaveBeenCalledWith({
|
||||
app: model.app,
|
||||
dimensionDefinition: { min: 1, max: 10 },
|
||||
measureDefinition: { min: 1, max: 10 },
|
||||
dimensionProperties: expect.any(Object),
|
||||
measureProperties: expect.any(Object),
|
||||
globalChangeListeners: undefined,
|
||||
path: 'customPath',
|
||||
});
|
||||
expect(cellRef.current.getHypercubePath).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('should return undefined when no data definition exists', async () => {
|
||||
const opts = { onInitialRender: jest.fn() };
|
||||
api.__DO_NOT_USE__.options(opts);
|
||||
await mounted;
|
||||
|
||||
cellRef.current.getExtensionDefinition = jest.fn().mockReturnValue({
|
||||
definition: {
|
||||
dataHandler: mockCustomDataHandler,
|
||||
},
|
||||
});
|
||||
|
||||
const args = cellRef.current.setSnOptions.mock.lastCall[0];
|
||||
args.onInitialRender();
|
||||
|
||||
const handler = await api.getHypercubePropertyHandler();
|
||||
|
||||
expect(handler).toBeUndefined();
|
||||
expect(mockCustomDataHandler).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('should handle invalid dataHandler', async () => {
|
||||
const opts = { onInitialRender: jest.fn() };
|
||||
api.__DO_NOT_USE__.options(opts);
|
||||
await mounted;
|
||||
|
||||
cellRef.current.getExtensionDefinition = jest.fn().mockReturnValue({
|
||||
data: {
|
||||
dimensions: { min: 1, max: 10 },
|
||||
measures: { min: 1, max: 10 },
|
||||
},
|
||||
definition: {
|
||||
dataHandler: 'not-a-function',
|
||||
},
|
||||
});
|
||||
|
||||
const args = cellRef.current.setSnOptions.mock.lastCall[0];
|
||||
args.onInitialRender();
|
||||
|
||||
const handler = await api.getHypercubePropertyHandler();
|
||||
expect(handler.constructor.name).toBe('HyperCubeHandler');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -121,7 +121,8 @@ export default function viz({
|
||||
async getHypercubePropertyHandler() {
|
||||
await rendered;
|
||||
|
||||
const dataDefinition = cellRef.current.getExtensionDefinition().data;
|
||||
const extensionDefinition = cellRef.current.getExtensionDefinition();
|
||||
const dataDefinition = extensionDefinition.data;
|
||||
const properties = await model.getEffectiveProperties();
|
||||
|
||||
if (dataDefinition) {
|
||||
@@ -135,6 +136,10 @@ export default function viz({
|
||||
path: cellRef.current.getHypercubePath(),
|
||||
};
|
||||
|
||||
if (typeof extensionDefinition.definition.dataHandler === 'function') {
|
||||
return extensionDefinition.definition.dataHandler(options);
|
||||
}
|
||||
|
||||
return new HyperCubeHandler(options);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ export default function generatorFn(UserSN, galaxy) {
|
||||
},
|
||||
definition: galaxy.flags.isEnabled('NEBULA_DATA_HANDLERS')
|
||||
? {
|
||||
dataHandler: (opts) => new HyperCubeHandler(opts),
|
||||
dataHandler: sn?.dataHandler ?? ((opts) => new HyperCubeHandler(opts)),
|
||||
}
|
||||
: {},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user