fix(ct): vue3 fallthrough events & callbacks (#23649)
closes: https://github.com/microsoft/playwright/issues/23526#issuecomment-1583074280 closes: https://github.com/microsoft/playwright/issues/23435
This commit is contained in:
parent
380209af37
commit
9d3edb0aa3
|
|
@ -52,7 +52,7 @@ function isComponent(component) {
|
||||||
*/
|
*/
|
||||||
async function __pwResolveComponent(component) {
|
async function __pwResolveComponent(component) {
|
||||||
if (!isComponent(component))
|
if (!isComponent(component))
|
||||||
return
|
return;
|
||||||
|
|
||||||
let componentFactory = __pwLoaderRegistry.get(component.type);
|
let componentFactory = __pwLoaderRegistry.get(component.type);
|
||||||
if (!componentFactory) {
|
if (!componentFactory) {
|
||||||
|
|
@ -68,11 +68,11 @@ async function __pwResolveComponent(component) {
|
||||||
if (!componentFactory && component.type[0].toUpperCase() === component.type[0])
|
if (!componentFactory && component.type[0].toUpperCase() === component.type[0])
|
||||||
throw new Error(`Unregistered component: ${component.type}. Following components are registered: ${[...__pwRegistry.keys()]}`);
|
throw new Error(`Unregistered component: ${component.type}. Following components are registered: ${[...__pwRegistry.keys()]}`);
|
||||||
|
|
||||||
if(componentFactory)
|
if (componentFactory)
|
||||||
__pwRegistry.set(component.type, await componentFactory())
|
__pwRegistry.set(component.type, await componentFactory());
|
||||||
|
|
||||||
if ('children' in component)
|
if ('children' in component)
|
||||||
await Promise.all(component.children.map(child => __pwResolveComponent(child)))
|
await Promise.all(component.children.map(child => __pwResolveComponent(child)));
|
||||||
}
|
}
|
||||||
|
|
||||||
const __pwAllListeners = new Map();
|
const __pwAllListeners = new Map();
|
||||||
|
|
@ -217,7 +217,7 @@ function __pwWrapFunctions(slots) {
|
||||||
function __pwCreateWrapper(component) {
|
function __pwCreateWrapper(component) {
|
||||||
const { Component, props, slots, listeners } = __pwCreateComponent(component);
|
const { Component, props, slots, listeners } = __pwCreateComponent(component);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const wrapper = __pwH(Component, props, slots);
|
const wrapper = __pwH(Component, { ...props, ...listeners }, slots);
|
||||||
__pwAllListeners.set(wrapper, listeners);
|
__pwAllListeners.set(wrapper, listeners);
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
defineProps({
|
import { useAttrs } from 'vue';
|
||||||
title: {
|
defineProps<{ title: string }>();
|
||||||
type: String,
|
const attrs = useAttrs();
|
||||||
required: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<button @click="$emit('submit', 'hello')">{{ title }}</button>
|
<button
|
||||||
|
@click="$emit('submit', 'hello')"
|
||||||
|
@dblclick="() => attrs.dbclick('fallthroughEvent')"
|
||||||
|
>
|
||||||
|
{{ title }}
|
||||||
|
</button>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -14,3 +14,17 @@ test('emit an submit event when the button is clicked', async ({ mount }) => {
|
||||||
await component.click();
|
await component.click();
|
||||||
expect(messages).toEqual(['hello']);
|
expect(messages).toEqual(['hello']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('emit a falltrough event when the button is double clicked', async ({ mount }) => {
|
||||||
|
const messages: string[] = [];
|
||||||
|
const component = await mount(Button, {
|
||||||
|
props: {
|
||||||
|
title: 'Submit',
|
||||||
|
},
|
||||||
|
on: {
|
||||||
|
dbclick: (message: string) => messages.push(message),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await component.dblclick();
|
||||||
|
expect(messages).toEqual(['fallthroughEvent']);
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,20 @@ test('emit an submit event when the button is clicked', async ({ mount }) => {
|
||||||
expect(messages).toEqual(['hello']);
|
expect(messages).toEqual(['hello']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('emit a falltrough event when the button is double clicked', async ({ mount }) => {
|
||||||
|
const messages: string[] = [];
|
||||||
|
const component = await mount(
|
||||||
|
<Button
|
||||||
|
title="Submit"
|
||||||
|
v-on:dbclick={(message: string) => {
|
||||||
|
messages.push(message)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
await component.dblclick();
|
||||||
|
expect(messages).toEqual(['fallthroughEvent']);
|
||||||
|
});
|
||||||
|
|
||||||
test('emit a event when a slot is clicked', async ({ mount }) => {
|
test('emit a event when a slot is clicked', async ({ mount }) => {
|
||||||
let clickFired = false;
|
let clickFired = false;
|
||||||
const component = await mount(
|
const component = await mount(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,14 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
defineProps<{ title: string }>()
|
import { useAttrs } from 'vue';
|
||||||
|
defineProps<{ title: string }>();
|
||||||
|
const attrs: Record<string, any> = useAttrs();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<button @click="$emit('submit', 'hello')">{{ title }}</button>
|
<button
|
||||||
|
@click="$emit('submit', 'hello')"
|
||||||
|
@dblclick="() => attrs.dbclick('fallthroughEvent')"
|
||||||
|
>
|
||||||
|
{{ title }}
|
||||||
|
</button>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,23 @@ test('emit a submit event when the button is clicked', async ({ mount }) => {
|
||||||
title: 'Submit',
|
title: 'Submit',
|
||||||
},
|
},
|
||||||
on: {
|
on: {
|
||||||
submit: (data) => messages.push(data),
|
submit: (message) => messages.push(message),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await component.click();
|
await component.click();
|
||||||
expect(messages).toEqual(['hello']);
|
expect(messages).toEqual(['hello']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('emit a falltrough event when the button is double clicked', async ({ mount }) => {
|
||||||
|
const messages = [];
|
||||||
|
const component = await mount(Button, {
|
||||||
|
props: {
|
||||||
|
title: 'Submit',
|
||||||
|
},
|
||||||
|
on: {
|
||||||
|
dbclick: (message) => messages.push(message),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await component.dblclick();
|
||||||
|
expect(messages).toEqual(['fallthroughEvent']);
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,23 @@ test('emit a submit event when the button is clicked', async ({ mount }) => {
|
||||||
title: 'Submit',
|
title: 'Submit',
|
||||||
},
|
},
|
||||||
on: {
|
on: {
|
||||||
submit: (data: string) => messages.push(data),
|
submit: (message: string) => messages.push(message),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await component.click();
|
await component.click();
|
||||||
expect(messages).toEqual(['hello']);
|
expect(messages).toEqual(['hello']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('emit a falltrough event when the button is double clicked', async ({ mount }) => {
|
||||||
|
const messages: string[] = [];
|
||||||
|
const component = await mount(Button, {
|
||||||
|
props: {
|
||||||
|
title: 'Submit',
|
||||||
|
},
|
||||||
|
on: {
|
||||||
|
dbclick: (message: string) => messages.push(message),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await component.dblclick();
|
||||||
|
expect(messages).toEqual(['fallthroughEvent']);
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ test('emit a submit event when the button is clicked', async ({ mount }) => {
|
||||||
const component = await mount(
|
const component = await mount(
|
||||||
<Button
|
<Button
|
||||||
title="Submit"
|
title="Submit"
|
||||||
v-on:submit={(data: string) => {
|
v-on:submit={(message: string) => {
|
||||||
messages.push(data);
|
messages.push(message);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
@ -16,6 +16,20 @@ test('emit a submit event when the button is clicked', async ({ mount }) => {
|
||||||
expect(messages).toEqual(['hello']);
|
expect(messages).toEqual(['hello']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('emit a falltrough event when the button is double clicked', async ({ mount }) => {
|
||||||
|
const messages: string[] = [];
|
||||||
|
const component = await mount(
|
||||||
|
<Button
|
||||||
|
title="Submit"
|
||||||
|
v-on:dbclick={(message: string) => {
|
||||||
|
messages.push(message)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
await component.dblclick();
|
||||||
|
expect(messages).toEqual(['fallthroughEvent']);
|
||||||
|
});
|
||||||
|
|
||||||
test('emit a event when a slot is clicked', async ({ mount }) => {
|
test('emit a event when a slot is clicked', async ({ mount }) => {
|
||||||
let clickFired = false;
|
let clickFired = false;
|
||||||
const component = await mount(
|
const component = await mount(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue