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

44 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-03-16 22:47:04 +00:00
import {GlobalRegistrator} from '@happy-dom/global-registrator';
import test from 'ava';
import {html} from 'htm/preact';
import {render} from 'preact';
import {FeedbackButton, FeedbackButtonProps} from '../../source/gram.js';
import {sleep} from '../utilities.js';
test.before(() => {
GlobalRegistrator.register();
});
test('FeedbackButton', async (t) => {
t.plan(5);
const props: FeedbackButtonProps = {
2022-03-17 10:34:05 +00:00
attributes: {
2022-03-16 22:47:04 +00:00
id: 'feedback-button',
},
2022-03-17 10:34:05 +00:00
click: (event) => t.true(event !== undefined),
2022-03-16 22:47:04 +00:00
feedbackText: 'Feedback Example',
text: 'Example',
timeout: 1000,
};
render(html`<${FeedbackButton} ...${props} />`, document);
const buttonElement =
document.querySelector<HTMLButtonElement>('#feedback-button')!;
t.snapshot(buttonElement.outerHTML, 'Default state');
buttonElement.click();
// Wait for Preact to do its stuff.
await sleep();
t.snapshot(buttonElement.outerHTML, 'Feedback state');
buttonElement.click();
2022-03-17 22:48:17 +00:00
await sleep(props.timeout * 1.25);
2022-03-16 22:47:04 +00:00
t.snapshot(buttonElement.outerHTML, 'Back to default state');
});