preact-components/tests/buttons/confirm-button.test.ts

43 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-03-16 14:40:06 +00:00
import {GlobalRegistrator} from '@happy-dom/global-registrator';
import test from 'ava';
import {html} from 'htm/preact';
import {render} from 'preact';
2022-09-29 10:39:55 +00:00
import {ConfirmButton, ConfirmButtonProps} from '../../source/index.js';
import {sleep} from '../utilities.js';
2022-03-16 14:40:06 +00:00
test.before(() => {
GlobalRegistrator.register();
});
test('ConfirmButton', async (t) => {
t.plan(3);
const props: ConfirmButtonProps = {
2022-03-17 10:34:05 +00:00
attributes: {
id: 'confirm-button',
},
2022-03-16 14:40:06 +00:00
class: 'button',
click: (event) => t.true(event !== undefined),
confirmClass: 'confirm',
confirmText: 'Confirm Button',
preventDefault: true,
text: 'Button',
timeout: 1000,
};
render(html`<${ConfirmButton} ...${props} />`, document);
const buttonElement =
document.querySelector<HTMLButtonElement>('#confirm-button')!;
t.snapshot(buttonElement.outerHTML, 'Default state');
buttonElement.click();
// Wait for Preact to do its stuff.
await sleep();
t.snapshot(buttonElement.outerHTML, 'Confirm state');
buttonElement.click();
});