Skip to content

Commit

Permalink
test(toaster): add a test for deteting an updateable toast
Browse files Browse the repository at this point in the history
  • Loading branch information
ymouzakis committed Mar 19, 2024
1 parent 0977c2f commit 65f8abd
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/pharos/src/components/toast/pharos-toaster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ describe('pharos-toaster', () => {
document.dispatchEvent(event);
};

const fireCloseToastEvent = () => {
const event = new CustomEvent('pharos-toast-close', {
detail: {
bubbles: true,
composed: true,
id: 'my-updateable-toast',
},
});
document.dispatchEvent(event);
};

const fireUpdateToastEvent = () => {
const event = new CustomEvent('pharos-toast-update', {
detail: {
Expand Down Expand Up @@ -143,6 +154,7 @@ describe('pharos-toaster', () => {
trigger.click();
await component.updateComplete;
await nextFrame();

const triggerUpdate = document.createElement('button');
triggerUpdate.addEventListener('click', fireUpdateToastEvent);
document.body.appendChild(triggerUpdate);
Expand All @@ -160,6 +172,33 @@ describe('pharos-toaster', () => {
`);
});

it('can close an updateable toast', async () => {
const trigger = document.createElement('button');
trigger.addEventListener('click', fireOpenUpdateableToastEvent);
document.body.appendChild(trigger);
trigger.click();
await component.updateComplete;
await nextFrame();

const triggerUpdate = document.createElement('button');
triggerUpdate.addEventListener('click', fireUpdateToastEvent);
document.body.appendChild(triggerUpdate);
triggerUpdate.click();
await component.updateComplete;

const triggerClose = document.createElement('button');
triggerClose.addEventListener('click', fireCloseToastEvent);
document.body.appendChild(triggerClose);
triggerClose.click();
await component.updateComplete;
await nextFrame();

expect(component).shadowDom.to.equal(`
<div class="toaster__container">
</div>
`);
});

it('can return focus to a specific element', async () => {
let activeElement = null;
const onFocusIn = (event: Event): void => {
Expand Down

0 comments on commit 65f8abd

Please sign in to comment.