2023-04-10 00:11:31 +02:00
|
|
|
import { test, expect } from '@playwright/experimental-ct-react17';
|
2023-01-14 03:15:33 +01:00
|
|
|
import Button from '@/components/Button';
|
|
|
|
|
import DefaultChildren from '@/components/DefaultChildren';
|
|
|
|
|
|
|
|
|
|
test('execute callback when the button is clicked', async ({ mount }) => {
|
|
|
|
|
const messages: string[] = [];
|
|
|
|
|
const component = await mount(
|
|
|
|
|
<Button
|
|
|
|
|
title="Submit"
|
|
|
|
|
onClick={(data) => {
|
|
|
|
|
messages.push(data);
|
|
|
|
|
}}
|
|
|
|
|
></Button>
|
|
|
|
|
);
|
|
|
|
|
await component.click();
|
|
|
|
|
expect(messages).toEqual(['hello']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('execute callback when a child node is clicked', async ({ mount }) => {
|
|
|
|
|
let clickFired = false;
|
|
|
|
|
const component = await mount(
|
|
|
|
|
<DefaultChildren>
|
|
|
|
|
<span onClick={() => (clickFired = true)}>Main Content</span>
|
|
|
|
|
</DefaultChildren>
|
|
|
|
|
);
|
2023-03-24 23:55:32 +01:00
|
|
|
await component.getByText('Main Content').click();
|
2023-01-14 03:15:33 +01:00
|
|
|
expect(clickFired).toBeTruthy();
|
|
|
|
|
});
|