mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
Vue kit: a late close event no longer shuts a reopened dialog; a scene sharing dialog the browser closes closes through its owner; the opened timing test can fail
Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
ec4a5b6afe
commit
1f34210f71
4 files changed
+54
-8
No files matched your search
@@ -77,15 +77,32 @@ test('a dialog mounted open opens modal on mount; unmounting closes it', async (
|
||||
});
|
||||
|
||||
test('the open state follows the content: opened comes after it renders', async () => {
|
||||
const { wrapper } = dialog();
|
||||
// The content changes in the same update that opens the dialog, so an
|
||||
// opened emitted before that update renders would see the old words.
|
||||
const { h } = await import('vue');
|
||||
let seen;
|
||||
await wrapper.setProps({
|
||||
open: true,
|
||||
onOpened: () => {
|
||||
seen = wrapper.element.querySelector('.content')?.textContent;
|
||||
const Host = {
|
||||
props: { open: Boolean, words: String },
|
||||
setup(props) {
|
||||
return () =>
|
||||
h(
|
||||
UiDialog,
|
||||
{
|
||||
open: props.open,
|
||||
onOpened: () => {
|
||||
seen = document.querySelector('dialog .content')?.textContent;
|
||||
},
|
||||
},
|
||||
() => h('p', { class: 'content' }, props.words),
|
||||
);
|
||||
},
|
||||
};
|
||||
const wrapper = mount(Host, {
|
||||
attachTo: document.body,
|
||||
props: { open: false, words: 'Before' },
|
||||
});
|
||||
assert.equal(seen, 'Words');
|
||||
await wrapper.setProps({ open: true, words: 'After' });
|
||||
assert.equal(seen, 'After');
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
@@ -116,6 +133,17 @@ test('a close the browser made while open is reported once; the owner’s is not
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test('a late close event from an earlier close is not reported once open again', async () => {
|
||||
const { wrapper, events } = dialog({ open: true });
|
||||
await wrapper.setProps({ open: false });
|
||||
await wrapper.setProps({ open: true });
|
||||
events.length = 0;
|
||||
// The browser's queued close event from the first close lands now.
|
||||
wrapper.element.dispatchEvent(new Event('close'));
|
||||
assert.deepEqual(events, [], 'no browserClose');
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test('a backdrop click dismisses only when asked, and only on the dialog', async () => {
|
||||
const plain = dialog({ open: true });
|
||||
plain.events.length = 0;
|
||||
|
||||
@@ -54,8 +54,10 @@ function onCancel(event) {
|
||||
event.preventDefault();
|
||||
emit('dismiss');
|
||||
}
|
||||
// The browser queues its close event, so one from an earlier close can land
|
||||
// after the dialog has been opened again; only a dialog still shut reports it.
|
||||
function onClose() {
|
||||
if (!unmounting && props.open) emit('browserClose');
|
||||
if (!unmounting && props.open && !element.value?.open) emit('browserClose');
|
||||
}
|
||||
function onClick(event) {
|
||||
if (props.backdropDismiss && event.target === event.currentTarget)
|
||||
|
||||
@@ -187,6 +187,22 @@ test('Cancel and Escape close through the owner; dispose removes the dialog', as
|
||||
assert.equal(store.controls, null);
|
||||
});
|
||||
|
||||
test('a close the browser makes on its own also closes through the owner', async (t) => {
|
||||
// A repeated Escape can close a modal without a cancel the page may stop.
|
||||
const { store } = fixture(t);
|
||||
let closes = 0;
|
||||
const dialog = createSceneDialog(
|
||||
'Share selected scene',
|
||||
() => closes++,
|
||||
store,
|
||||
);
|
||||
await nextTick();
|
||||
$('dialog').close();
|
||||
assert.equal(closes, 1);
|
||||
dialog.dispose();
|
||||
await nextTick();
|
||||
});
|
||||
|
||||
test('a replaced dialog opens fresh and its late dispose leaves the new one', async (t) => {
|
||||
const { store } = fixture(t);
|
||||
opened.length = 0;
|
||||
|
||||
@@ -42,7 +42,7 @@ const chooserStyle = (focused) => ({ padding: '3px 9px', border: '1px solid #397
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UiDialog open data-director-dialog class="director-sharing-dialog" :aria-label="view.title" :style="dialogStyle" @dismiss="controls?.cancel()">
|
||||
<UiDialog open data-director-dialog class="director-sharing-dialog" :aria-label="view.title" :style="dialogStyle" @dismiss="controls?.cancel()" @browser-close="controls?.cancel()">
|
||||
<h2 style="margin-bottom: 12px">{{ view.title }}</h2>
|
||||
<div>
|
||||
<template v-for="item in bodyItems" :key="item.id">
|
||||
|
||||
Reference in new issue
Block a user