Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Contrib: Fix issue when closing all toasts if no toasts have been opened. #21

Merged
merged 3 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/public/modules/toast/toast.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export class SkyToastService implements OnDestroy {
* Closes all active toast components.
*/
public closeAll(): void {
if (!this.host) {
return;
}

this.host.instance.closeAll();
}

Expand Down
22 changes: 22 additions & 0 deletions src/app/public/modules/toast/toaster.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import {
SkyToastService
} from './toast.service';

import {
SkyToasterComponent
} from './toaster.component';

describe('Toast component', () => {
let fixture: ComponentFixture<SkyToasterTestComponent>;
let toastService: SkyToastService;
Expand Down Expand Up @@ -152,6 +156,7 @@ describe('Toast component', () => {
}));

it('should close all toasts', fakeAsync(() => {
const cloaseAllSpy = spyOn(SkyToasterComponent.prototype, 'closeAll').and.callThrough();
openMessage();
openMessage();
openMessage();
Expand All @@ -167,6 +172,23 @@ describe('Toast component', () => {

toasts = getToastElements();
expect(toasts.length).toEqual(0);
expect(cloaseAllSpy).toHaveBeenCalled();
}));

it('should close all toasts', fakeAsync(() => {
const cloaseAllSpy = spyOn(SkyToasterComponent.prototype, 'closeAll').and.callThrough();
let toasts = getToastElements();
expect(toasts.length).toEqual(0);

toastService.closeAll();
fixture.detectChanges();
tick();
fixture.detectChanges();
tick();

toasts = getToastElements();
expect(toasts.length).toEqual(0);
expect(cloaseAllSpy).not.toHaveBeenCalled();
}));

it('should prevent click events from bubbling beyond toast components', fakeAsync(() => {
Expand Down
7 changes: 7 additions & 0 deletions src/app/visual/toast/toast-visual.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
>
Open custom toasts
</button>
<button
class="sky-btn sky-btn-secondary"
type="button"
(click)="closeAll()"
>
Close all
</button>
</div>
4 changes: 4 additions & 0 deletions src/app/visual/toast/toast-visual.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ export class ToastVisualComponent implements OnDestroy {
this.toastService.openComponent(ToastDemoComponent, { type: SkyToastType.Warning });
this.toastService.openComponent(ToastDemoComponent, { type: SkyToastType.Danger });
}

public closeAll(): void {
this.toastService.closeAll();
}
}