|
|
|
|
@ -47,8 +47,17 @@ class Node {
|
|
|
|
|
this.listeners.get(name).push(listener);
|
|
|
|
|
}
|
|
|
|
|
async fire(name) {
|
|
|
|
|
await Promise.all((this.listeners.get(name) || []).map(fn => fn({ target: this, preventDefault() {} })));
|
|
|
|
|
const event = {
|
|
|
|
|
target: this,
|
|
|
|
|
defaultPrevented: false,
|
|
|
|
|
preventDefault() { this.defaultPrevented = true; },
|
|
|
|
|
};
|
|
|
|
|
await Promise.all((this.listeners.get(name) || []).map(fn => fn(event)));
|
|
|
|
|
await tick();
|
|
|
|
|
if (name === 'click' && !event.defaultPrevented && this.tagName === 'A' && this.href) {
|
|
|
|
|
await this.document.navigate(this.href);
|
|
|
|
|
}
|
|
|
|
|
return event;
|
|
|
|
|
}
|
|
|
|
|
focus() { this.document.activeElement = this; }
|
|
|
|
|
scrollIntoView() {}
|
|
|
|
|
@ -96,6 +105,20 @@ async function setup(hash = '#/', payload = fixtures()) {
|
|
|
|
|
const location = new URL(`https://panel.example.test/user/cloud/vpcs${hash}`);
|
|
|
|
|
const window = { location, VenixDialog: { confirm: async () => true },
|
|
|
|
|
addEventListener: (name, listener) => events.set(name, listener) };
|
|
|
|
|
let fullPageNavigations = 0;
|
|
|
|
|
document.navigate = async target => {
|
|
|
|
|
const next = new URL(target, location.href);
|
|
|
|
|
if (next.origin === location.origin && next.pathname === location.pathname
|
|
|
|
|
&& next.search === location.search) {
|
|
|
|
|
if (next.hash !== location.hash) {
|
|
|
|
|
location.hash = next.hash;
|
|
|
|
|
events.get('hashchange')?.();
|
|
|
|
|
await tick();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fullPageNavigations += 1;
|
|
|
|
|
};
|
|
|
|
|
let data = structuredClone(payload);
|
|
|
|
|
let respond = async (url, options) => {
|
|
|
|
|
if (!options.method) return structuredClone(data);
|
|
|
|
|
@ -127,6 +150,7 @@ async function setup(hash = '#/', payload = fixtures()) {
|
|
|
|
|
await context.page.initialize();
|
|
|
|
|
return {
|
|
|
|
|
nodes, calls, observations, storage, location, data: () => data,
|
|
|
|
|
fullPageNavigations: () => fullPageNavigations,
|
|
|
|
|
update: next => { data = structuredClone(next); context.page.apply(structuredClone(next)); },
|
|
|
|
|
respond: fn => { respond = fn; },
|
|
|
|
|
event: (name, event = {}) => events.get(name)?.(event),
|
|
|
|
|
@ -185,6 +209,20 @@ for (const [query, page, joining] of [
|
|
|
|
|
assert.equal(t.nodes.get('cloud-vpcs-home').hidden, false);
|
|
|
|
|
assert.equal(mutations(t).length, 0, 'Navigation must never mutate a VPC');
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
const t = await setup(`?vpc=${A}`);
|
|
|
|
|
await t.nodes.get('cloud-vpc-join-link').fire('click');
|
|
|
|
|
assert.equal(t.fullPageNavigations(), 0,
|
|
|
|
|
'Switching to joinable instances must not trigger a full-page navigation');
|
|
|
|
|
assert.equal(t.nodes.get('cloud-vpc-instance-manager').querySelector('section')
|
|
|
|
|
.classList.contains('joining'), true);
|
|
|
|
|
await t.nodes.get('cloud-vpc-members-link').fire('click');
|
|
|
|
|
assert.equal(t.fullPageNavigations(), 0,
|
|
|
|
|
'Switching to attached instances must not trigger a full-page navigation');
|
|
|
|
|
assert.equal(t.nodes.get('cloud-vpc-instance-manager').querySelector('section')
|
|
|
|
|
.classList.contains('joining'), false);
|
|
|
|
|
assert.equal(mutations(t).length, 0, 'Tab switching must not mutate a VPC');
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
const t = await setup(`${href(A)}/join`);
|
|
|
|
|
const search = control(t, 'instance-search');
|
|
|
|
|
|