From b93b984f64fc1fed0e5802bb1d6816d060223323 Mon Sep 17 00:00:00 2001 From: simgar98 Date: Wed, 21 Feb 2024 17:31:58 +0100 Subject: [PATCH 1/2] Fix: Dismiss all toasts in a single container Fix: Dismiss all toasts in a single container (re-apply) --- src/core/store.ts | 10 ++++++---- src/core/toast.cy.tsx | 45 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/core/store.ts b/src/core/store.ts index a55122e8..75e3066c 100644 --- a/src/core/store.ts +++ b/src/core/store.ts @@ -67,10 +67,12 @@ export function removeToast(params?: Id | RemoveParams) { c.removeToast(params as Id); }); } else if (params && ('containerId' in params || 'id' in params)) { - containers.get(params.containerId)?.removeToast(params.id) || - containers.forEach(c => { - c.removeToast(params.id); - }); + const container = containers.get(params.containerId); + container + ? container.removeToast(params.id) + : containers.forEach(c => { + c.removeToast(params.id); + }); } } diff --git a/src/core/toast.cy.tsx b/src/core/toast.cy.tsx index b344d2b1..36b1afae 100644 --- a/src/core/toast.cy.tsx +++ b/src/core/toast.cy.tsx @@ -334,7 +334,8 @@ describe('with container', () => { describe('with multi containers', () => { const Containers = { First: 'first', - Second: 'second' + Second: 'second', + Third: 'third' }; beforeEach(() => { @@ -354,6 +355,13 @@ describe('with multi containers', () => { containerId={Containers.Second} closeOnClick /> + ); }); @@ -409,6 +417,41 @@ describe('with multi containers', () => { }); }); + it('remove all toasts for a given container', () => { + const toastId = '123'; + + toast('first container', { + toastId, + containerId: Containers.First + }); + toast('third container', { + toastId, + containerId: Containers.Third + }); + toast('third container second toast', { + containerId: Containers.Third + }); + + cy.resolveEntranceAnimation(); + + cy.findByText('first container').should('exist'); + cy.findByText('third container second toast').should('exist'); + cy.findByText('third container') + .should('exist') + .then(() => { + toast.dismiss({ + containerId: Containers.Third + }); + + cy.resolveEntranceAnimation(); + + cy.findByText('first container').should('exist'); + cy.findByText('third container').should('not.exist'); + cy.findByText('third container second toast').should('not.exist'); + cy.findByText('first container').should('exist'); + }); + }); + it('clear waiting queue for a given container', () => { toast('msg1-c1', { containerId: Containers.First From 1c25533d840c5eb3595b4ca7194b2dfb19bf6700 Mon Sep 17 00:00:00 2001 From: simgar98 Date: Fri, 23 Feb 2024 10:07:29 +0100 Subject: [PATCH 2/2] Add test to fix coverage Run yarn prettier --- src/core/toast.cy.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/toast.cy.tsx b/src/core/toast.cy.tsx index 36b1afae..45ee1d91 100644 --- a/src/core/toast.cy.tsx +++ b/src/core/toast.cy.tsx @@ -448,7 +448,14 @@ describe('with multi containers', () => { cy.findByText('first container').should('exist'); cy.findByText('third container').should('not.exist'); cy.findByText('third container second toast').should('not.exist'); - cy.findByText('first container').should('exist'); + cy.findByText('first container') + .should('exist') + .then(() => { + toast.dismiss({ containerId: 'Non-Existing Container Id' }); + + cy.findByText('first container').should('not.exist'); + cy.findByText('third container').should('not.exist'); + }); }); });