gristlabs_grist-core/test/common/PluginInstance.ts
Jarosław Sadziński a52d56f613 (core) Moving client and common tests to core
Summary:
- Moved /test/client and /test/common to core.
- Moved two files (CircularArray and RecentItems) from app/common to core/app/common.
- Moved resetOrg test to gen-server.
- `testrun.sh` is now invoking common and client test from core.
- Added missing packages to core's package.json (and revealed underscore as it is used in the main app).
- Removed Coord.js as it is not used anywhere.

Test Plan: Existing tests

Reviewers: paulfitz

Reviewed By: paulfitz

Subscribers: paulfitz

Differential Revision: https://phab.getgrist.com/D3590
2022-08-23 19:20:10 +02:00

34 lines
1.3 KiB
TypeScript

import {LocalPlugin} from 'app/common/plugin';
import * as clientUtil from 'test/client/clientUtil';
import * as sinon from 'sinon';
import {assert} from 'chai';
import * as browserGlobals from 'app/client/lib/browserGlobals';
const G: any = browserGlobals.get('$');
import {PluginInstance} from 'app/common/PluginInstance';
describe("PluginInstance", function() {
clientUtil.setTmpMochaGlobals();
it("can manages render target", function() {
const plugin = new PluginInstance({manifest: {contributions: {}}} as LocalPlugin, {});
assert.throws(() => plugin.getRenderTarget(2), /Unknown render target.*/);
assert.doesNotThrow(() => plugin.getRenderTarget("fullscreen"));
const renderTarget1 = sinon.spy();
const renderTarget2 = sinon.spy();
const el1 = G.$('<h1>el1</h1>');
const el2 = G.$('<h1>el2</h1>');
const handle1 = plugin.addRenderTarget(renderTarget1);
plugin.getRenderTarget(handle1)(el1, {});
sinon.assert.calledWith(renderTarget1, el1, {});
plugin.removeRenderTarget(handle1);
assert.throw(() => plugin.getRenderTarget(handle1));
const handle2 = plugin.addRenderTarget(renderTarget2);
plugin.getRenderTarget(handle2)(el2 as HTMLElement, {});
sinon.assert.calledWith(renderTarget2, el2, {});
});
});