From 59c1aca734f399a4a4e0ad60fcccda7666a7b068 Mon Sep 17 00:00:00 2001 From: Clara Castillo Date: Mon, 3 Jun 2024 10:43:07 +0200 Subject: [PATCH] fix: allow to render custom icons for toasts fixes #10 --- libs/ngx-sonner/src/lib/toaster.component.ts | 22 +++++++++++++------ .../src/tests/toaster-test.component.ts | 19 +++++++++++++++- libs/ngx-sonner/src/tests/toaster.spec.ts | 12 ++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/libs/ngx-sonner/src/lib/toaster.component.ts b/libs/ngx-sonner/src/lib/toaster.component.ts index 781f757..fb036d1 100644 --- a/libs/ngx-sonner/src/lib/toaster.component.ts +++ b/libs/ngx-sonner/src/lib/toaster.component.ts @@ -79,13 +79,21 @@ import { Position, Theme, ToasterProps } from './types'; [classes]="toastOptions().classes ?? {}" [duration]="toastOptions().duration ?? duration()" [unstyled]="toastOptions().unstyled ?? false"> - - - - - + + + + + + + + + + + + + + + } diff --git a/libs/ngx-sonner/src/tests/toaster-test.component.ts b/libs/ngx-sonner/src/tests/toaster-test.component.ts index 5a6b1d4..ebdcda3 100644 --- a/libs/ngx-sonner/src/tests/toaster-test.component.ts +++ b/libs/ngx-sonner/src/tests/toaster-test.component.ts @@ -18,7 +18,24 @@ export type ToastTestInputs = { + [closeButton]="closeButton()"> + + + + + `, changeDetection: ChangeDetectionStrategy.OnPush, diff --git a/libs/ngx-sonner/src/tests/toaster.spec.ts b/libs/ngx-sonner/src/tests/toaster.spec.ts index effac62..5cb7efb 100644 --- a/libs/ngx-sonner/src/tests/toaster.spec.ts +++ b/libs/ngx-sonner/src/tests/toaster.spec.ts @@ -284,4 +284,16 @@ describe('Toaster', () => { const closeButton = container.querySelector('[data-close-button]'); expect(closeButton).not.toBeNull(); }); + + it('should render the custom icon when provided', async () => { + const { user, trigger, container } = await setup({ + callback: toast => toast.success('Hello world'), + }); + await user.click(trigger); + const icon = container.querySelector('[data-icon]'); + expect(icon).not.toBeNull(); + expect(icon).toContainHTML( + '' + ); + }); });