CI/CD / preconditions (pull_request) Successful in 1s
Native JavaScript checks / Native launcher and release tests (pull_request) Successful in 1m2s
macOS checks / Native Rust tests and unsigned build (pull_request) Successful in 1m38s
CI/CD / test_and_check_app (pull_request) Successful in 6m47s
CI/CD / Publish immutable image (pull_request) Skipped
76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import vm from 'node:vm';
|
|
import test from 'node:test';
|
|
|
|
const script = readFileSync(
|
|
new URL('../ui/workspace-settings.js', import.meta.url),
|
|
'utf8',
|
|
);
|
|
function context(platform = 'apple', frame = false, protocol = 'https:') {
|
|
const calls = [];
|
|
const window = { dispatchEvent() {} };
|
|
window.top = frame ? {} : window;
|
|
if (platform === 'apple') {
|
|
window.webkit = {
|
|
messageHandlers: {
|
|
kanbanSettings: {
|
|
postMessage: async (body) => {
|
|
const request = JSON.parse(body);
|
|
calls.push(request);
|
|
return JSON.stringify({
|
|
id: request.id,
|
|
result: { workspace: 'https://example.test/' },
|
|
});
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|
|
vm.runInNewContext(script, {
|
|
window,
|
|
location: { protocol },
|
|
Event,
|
|
setTimeout,
|
|
clearTimeout,
|
|
});
|
|
return { window, calls };
|
|
}
|
|
test('Apple WebViews expose a versioned request/reply API without Tauri', async () => {
|
|
const { window, calls } = context('apple');
|
|
assert.equal(window.kanbanNative.version, 1);
|
|
assert.equal(
|
|
(await window.kanbanNative.request('getState')).workspace,
|
|
'https://example.test/',
|
|
);
|
|
assert.deepEqual(calls[0], {
|
|
version: 1,
|
|
id: 1,
|
|
action: 'getState',
|
|
payload: {},
|
|
});
|
|
await assert.rejects(
|
|
window.kanbanNative.request('shell'),
|
|
/unsupportedAction/,
|
|
);
|
|
assert.equal(calls.length, 1);
|
|
assert.equal(window.__TAURI_INTERNALS__, undefined);
|
|
assert.equal(context('apple', true).window.kanbanNative, undefined);
|
|
assert.equal(
|
|
context('apple', false, 'http:').window.kanbanNative,
|
|
undefined,
|
|
);
|
|
});
|
|
test('normal browsers receive no native settings API', () => {
|
|
assert.equal(context('browser').window.kanbanNative, undefined);
|
|
});
|
|
test('native errors reject the caller without losing future requests', async () => {
|
|
const { window } = context();
|
|
window.webkit.messageHandlers.kanbanSettings.postMessage = async () =>
|
|
JSON.stringify({ error: 'invalidServer' });
|
|
await assert.rejects(
|
|
window.kanbanNative.request('setWorkspace', { server: 'bad' }),
|
|
/invalidServer/,
|
|
);
|
|
});
|