From b93b984f64fc1fed0e5802bb1d6816d060223323 Mon Sep 17 00:00:00 2001 From: simgar98 Date: Wed, 21 Feb 2024 17:31:58 +0100 Subject: [PATCH] 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