Skip to content

Commit

Permalink
chore: testss
Browse files Browse the repository at this point in the history
  • Loading branch information
Caele committed May 16, 2023
1 parent e67cd56 commit 99d2c67
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
43 changes: 42 additions & 1 deletion apis/nucleus/src/__tests__/viz.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('viz', () => {
let setSnPlugins;
let takeSnapshot;
let exportImage;
let getImperativeHandle;
let convertToMock;

beforeAll(() => {
Expand All @@ -29,13 +30,17 @@ describe('viz', () => {
setSnPlugins = jest.fn();
takeSnapshot = jest.fn();
exportImage = jest.fn();
getImperativeHandle = jest.fn(async () => ({
api: 'api',
}));
cellRef = {
current: {
setSnOptions,
setSnContext,
setSnPlugins,
takeSnapshot,
exportImage,
getImperativeHandle,
},
};
glue = jest.fn().mockReturnValue([unmountMock, cellRef]);
Expand Down Expand Up @@ -101,11 +106,14 @@ describe('viz', () => {
test('should throw if already mounted', async () => {
try {
mounted = api.__DO_NOT_USE__.mount('element');
/*
// This code never runs, as these tests are meant to run together, don't want to mess more with it
const { onMount } = glue.mock.lastCall[0];
onMount();
await mounted;
const result = await api.__DO_NOT_USE__.mount.bind('element2');
await result();
*/
} catch (error) {
expect(error.message).toBe('Already mounted');
}
Expand Down Expand Up @@ -150,7 +158,28 @@ describe('viz', () => {
const opts = {};
api.__DO_NOT_USE__.options(opts);
await mounted;
expect(cellRef.current.setSnOptions).toHaveBeenCalledWith(opts);
const args = cellRef.current.setSnOptions.mock.lastCall[0];
expect(args.onInitialRender).toBeInstanceOf(Function);
expect(Object.keys(args).length).toEqual(1);
});

test('should set extended sn options', async () => {
const opts = { myops: 'myopts' };
api.__DO_NOT_USE__.options(opts);
await mounted;
const args = cellRef.current.setSnOptions.mock.lastCall[0];
expect(args.onInitialRender).toBeInstanceOf(Function);
expect(args.myops).toEqual('myopts');
expect(Object.keys(args).length).toEqual(2);
});

test('should override and call onIntialRender', async () => {
const opts = { myops: 'myopts', onInitialRender: jest.fn() };
api.__DO_NOT_USE__.options(opts);
await mounted;
const args = cellRef.current.setSnOptions.mock.lastCall[0];
args.onInitialRender();
expect(opts.onInitialRender).toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -199,4 +228,16 @@ describe('viz', () => {
expect(props).toBe('props');
});
});

describe('getImperativeHandle', () => {
test('should await the rendering and then call cell', async () => {
const opts = { myops: 'myopts', onInitialRender: jest.fn() };
api.__DO_NOT_USE__.options(opts);
await mounted;
const args = cellRef.current.setSnOptions.mock.lastCall[0];
args.onInitialRender();
const handle = await api.getImperativeHandle();
expect(handle.api).toEqual('api');
});
});
});
2 changes: 1 addition & 1 deletion apis/nucleus/src/viz.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function viz({ model, halo, initialError, onDestroy = async () =>
});

const createOnInitialRender = (override) => () => {
override();
override && override();
onRender();
};

Expand Down

0 comments on commit 99d2c67

Please sign in to comment.