feat(KAN-53): add Android app and platform integration

This commit is contained in:
2026-09-17 14:39:32 +02:00
parent 1be2d06ff4
commit 508c39dd2d
35 changed files with 1829 additions and 460 deletions
+89
View File
@@ -0,0 +1,89 @@
import assert from 'node:assert/strict';
import test from 'node:test';
class Element {
constructor() {
this.events = {};
this.attributes = {};
this.dataset = {};
this.hidden = true;
this.value = '';
}
addEventListener(name, callback) {
this.events[name] = callback;
}
setAttribute(name, value) {
this.attributes[name] = value;
}
removeAttribute(name) {
delete this.attributes[name];
}
focus() {}
fire(name) {
this.events[name]({ preventDefault() {}, target: this });
}
}
test('Android launcher sends only explicit local actions and preserves switch confirmation', async () => {
const elements = new Map();
const element = (selector) => {
if (!elements.has(selector)) {
elements.set(selector, new Element());
}
return elements.get(selector);
};
const messages = [];
globalThis.document = {
querySelectorAll: () => [],
querySelector: element,
documentElement: new Element(),
};
globalThis.window = {
nativeLauncher: {
postMessage: (value) => messages.push(new URL(value)),
},
};
globalThis.location = { href: 'https://tauri.localhost/index.html' };
try {
await import('../ui/main.js');
assert.equal(messages.shift().pathname, '/action/ready');
window.updateLauncher(
'server=https%3A%2F%2Fexample.com%2F&phase=idle&ready=false&platform=android',
);
assert.equal(element('#server-url').value, 'https://example.com/');
element('#server-url').value = 'http://example.com';
element('#server-form').fire('submit');
assert.equal(messages.length, 0);
assert.equal(element('#server-url').attributes['aria-invalid'], 'true');
element('#server-url').value = 'https://example.com/';
element('#server-form').fire('submit');
assert.equal(messages[0].pathname, '/action/open');
assert.equal(
messages.shift().searchParams.get('server'),
'https://example.com/',
);
window.updateLauncher(
'server=https%3A%2F%2Fexample.com%2F&phase=connected&ready=true&platform=android',
);
assert.match(
element('#connection-status').textContent,
/Use Server settings/,
);
element('#resume').fire('click');
assert.equal(messages.shift().pathname, '/action/resume');
element('#server-url').value = 'https://other.example.com/';
element('#server-form').fire('submit');
assert.equal(messages.length, 0);
assert.equal(element('#switch-confirmation').hidden, false);
element('#confirm-switch').fire('click');
assert.equal(
messages.shift().searchParams.get('server'),
'https://other.example.com/',
);
assert.equal(location.href, 'https://tauri.localhost/index.html');
} finally {
delete globalThis.window;
delete globalThis.document;
delete globalThis.location;
}
});