mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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
This commit is contained in:
43
test/fixtures/sites/config/index.html
vendored
Normal file
43
test/fixtures/sites/config/index.html
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<script src="/grist-plugin-api.js"></script>
|
||||
<script src="page.js"></script>
|
||||
</head>
|
||||
<body style="background: white;">
|
||||
<div id="ready"></div>
|
||||
<div id="access"></div>
|
||||
<div id="readonly"></div>
|
||||
|
||||
<div>onOptions event data:</div>
|
||||
<pre id="onOptions"></pre>
|
||||
|
||||
<div>onRecord event data:</div>
|
||||
<pre id="onRecord"></pre>
|
||||
|
||||
<div>onRecord mapping data:</div>
|
||||
<pre id="onRecordMappings"></pre>
|
||||
|
||||
<div>onRecords event data:</div>
|
||||
<pre id="onRecords"></pre>
|
||||
|
||||
<div>onRecord mappings data:</div>
|
||||
<pre id="onRecordsMappings"></pre>
|
||||
|
||||
<div>configure handler:</div>
|
||||
<pre id="configure"></pre>
|
||||
|
||||
<div>Method input json:</div>
|
||||
<input type="text" id="input" value="" />
|
||||
<div>Method output json:</div>
|
||||
<div id="output"></div>
|
||||
<div>Methods:</div>
|
||||
<button onclick="getOptions()">getOptions</button>
|
||||
<button onclick="setOptions()">setOptions</button>
|
||||
<button onclick="getOption()">getOption</button>
|
||||
<button onclick="setOption()">setOption</button>
|
||||
<button onclick="mappings()">mappings</button>
|
||||
<button onclick="configure()">configure</button>
|
||||
<button onclick="clearOptions()">clearOptions</button>
|
||||
</body>
|
||||
</html>
|
||||
72
test/fixtures/sites/config/page.js
vendored
Normal file
72
test/fixtures/sites/config/page.js
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/* 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');
|
||||
};
|
||||
Reference in New Issue
Block a user