CI/CD / preconditions (pull_request) Successful in 2s
Native JavaScript checks / Native launcher and release tests (pull_request) Successful in 1m17s
CI/CD / test_and_check_app (pull_request) Successful in 6m24s
CI/CD / Publish immutable image (pull_request) Skipped
macOS checks / Native Rust tests and unsigned build (pull_request) Successful in 1m27s
102 lines
3.7 KiB
JavaScript
102 lines
3.7 KiB
JavaScript
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');
|
|
assert.equal(element('#workspace-settings').hidden, true);
|
|
window.updateLauncher(
|
|
'server=https%3A%2F%2Fexample.com%2F&phase=connecting&ready=false',
|
|
);
|
|
assert.equal(element('#workspace-settings').hidden, true);
|
|
assert.equal(element('#startup-loading').hidden, false);
|
|
window.updateLauncher(
|
|
'server=https%3A%2F%2Fexample.com%2F&phase=connectionError&ready=false',
|
|
);
|
|
assert.equal(element('#workspace-settings').hidden, false);
|
|
assert.equal(element('#startup-loading').hidden, true);
|
|
assert.equal(element('.open-workspace').textContent, 'Try again');
|
|
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;
|
|
}
|
|
});
|