gristlabs_grist-core/test/fixtures/sites/config/page.js
Jarosław Sadziński 2438a63255 (core) Moving widget tests to core
Summary:
- Custom widget tests are now in grist-core
- Adding buildtools for grist-plugin-api.js

Test Plan: Existing tests

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3617
2022-09-06 17:17:14 +02:00

73 lines
2.4 KiB
JavaScript

/* global document, grist, window */
// Ready message can be configured from url
const urlParams = new URLSearchParams(window.location.search);
const ready = urlParams.get('ready') ? JSON.parse(urlParams.get('ready')) : undefined;
if (ready && ready.onEditOptions) {
ready.onEditOptions = () => {
document.getElementById('configure').innerHTML = 'called';
};
}
grist.ready(ready);
grist.onOptions(data => {
document.getElementById('onOptions').innerHTML = JSON.stringify(data);
});
grist.onRecord((data, mappings) => {
document.getElementById('onRecord').innerHTML = JSON.stringify(data);
document.getElementById('onRecordMappings').innerHTML = JSON.stringify(mappings);
});
grist.onRecords((data, mappings) => {
document.getElementById('onRecords').innerHTML = JSON.stringify(data);
document.getElementById('onRecordsMappings').innerHTML = JSON.stringify(mappings);
});
async function run(handler) {
try {
document.getElementById('output').innerText = 'waiting...';
const result = await handler(JSON.parse(document.getElementById('input').value || '[]'));
document.getElementById('output').innerText = result === undefined ? 'undefined' : JSON.stringify(result);
} catch (err) {
document.getElementById('output').innerText = JSON.stringify({error: err.message || String(err)});
}
}
// eslint-disable-next-line no-unused-vars
async function getOptions() {
return run(() => grist.widgetApi.getOptions());
}
// eslint-disable-next-line no-unused-vars
async function setOptions() {
return run(options => grist.widgetApi.setOptions(...options));
}
// eslint-disable-next-line no-unused-vars
async function setOption() {
return run(options => grist.widgetApi.setOption(...options));
}
// eslint-disable-next-line no-unused-vars
async function getOption() {
return run(options => grist.widgetApi.getOption(...options));
}
// eslint-disable-next-line no-unused-vars
async function clearOptions() {
return run(() => grist.widgetApi.clearOptions());
}
// eslint-disable-next-line no-unused-vars
async function mappings() {
return run(() => grist.sectionApi.mappings());
}
// eslint-disable-next-line no-unused-vars
async function configure() {
return run((options) => grist.sectionApi.configure(...options));
}
window.onload = () => {
document.getElementById('ready').innerText = 'ready';
document.getElementById('access').innerHTML = urlParams.get('access');
document.getElementById('readonly').innerHTML = urlParams.get('readonly');
};