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) => {
|
2022-03-17 23:03:46 +00:00
|
|
|
t.plan(7);
|
2022-03-16 22:47:04 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2022-03-17 23:03:46 +00:00
|
|
|
const noFeedbackProps: FeedbackButtonProps = {
|
|
|
|
...props,
|
|
|
|
attributes: {
|
|
|
|
id: 'no-feedback-button',
|
|
|
|
},
|
|
|
|
click(event) {
|
|
|
|
props.click(event);
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
render(
|
|
|
|
html`
|
|
|
|
<${FeedbackButton} ...${props} />
|
|
|
|
<${FeedbackButton} ...${noFeedbackProps} />
|
|
|
|
`,
|
|
|
|
document,
|
|
|
|
);
|
|
|
|
|
|
|
|
const noFeedbackButton = document.querySelector<HTMLButtonElement>(
|
|
|
|
'#no-feedback-button',
|
|
|
|
)!;
|
|
|
|
|
|
|
|
noFeedbackButton.click();
|
|
|
|
await sleep();
|
|
|
|
t.false(noFeedbackButton.outerHTML.includes(props.feedbackText));
|
2022-03-16 22:47:04 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
});
|