gristlabs_grist-core/test/client/lib/ImportSourceElement.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

56 lines
1.8 KiB
TypeScript

import { ImportSourceElement } from 'app/client/lib/ImportSourceElement';
import { createRpcLogger, PluginInstance } from 'app/common/PluginInstance';
import { FileListItem } from 'app/plugin/grist-plugin-api';
import { assert } from 'chai';
import { Rpc } from 'grain-rpc';
// assign console to logger to show logs
const logger = {};
describe("ImportSourceElement.importSourceStub#getImportSource()", function() {
it("should accept buffer for FileContent.content", async function() {
const plugin = createImportSourcePlugin({
getImportSource: () => (Promise.resolve({
item: {
kind: "fileList",
files: [{
content: new Uint8Array([1, 2]),
name: "MyFile"
}]
}
}))
});
const importSourceStub = ImportSourceElement.fromArray([plugin])[0].importSourceStub;
const res = await importSourceStub.getImportSource(0);
assert.equal((res!.item as FileListItem).files[0].name, "MyFile");
assert.deepEqual((res!.item as FileListItem).files[0].content, new Uint8Array([1, 2]));
});
});
// Helper that creates a plugin which contributes importSource.
function createImportSourcePlugin(importSource: any): PluginInstance {
const plugin = new PluginInstance({
id: "",
path: "",
manifest: {
components: {
safeBrowser: "index.html"
},
contributions: {
importSources: [{
label: "Importer",
importSource: {
component: "safeBrowser",
name: "importer"
}
}]
}
},
}, createRpcLogger(logger, "plugin instance"));
const rpc = new Rpc({logger: createRpcLogger(logger, 'rpc')});
rpc.setSendMessage((mssg: any) => rpc.receiveMessage(mssg));
rpc.registerImpl("importer", importSource);
plugin.rpc.registerForwarder("index.html", rpc);
return plugin;
}