From 65f8abd60c4057c8721b5809e30e54d66b6e85b6 Mon Sep 17 00:00:00 2001 From: Yanni Mouzakis Date: Tue, 19 Mar 2024 09:25:56 -0400 Subject: [PATCH] test(toaster): add a test for deteting an updateable toast --- .../components/toast/pharos-toaster.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/pharos/src/components/toast/pharos-toaster.test.ts b/packages/pharos/src/components/toast/pharos-toaster.test.ts index 476e64809..e61fb1a27 100644 --- a/packages/pharos/src/components/toast/pharos-toaster.test.ts +++ b/packages/pharos/src/components/toast/pharos-toaster.test.ts @@ -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: { @@ -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); @@ -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(` +
+
+ `); + }); + it('can return focus to a specific element', async () => { let activeElement = null; const onFocusIn = (event: Event): void => {