import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing'; import { ToastComponent } from './toast.component'; import { ToastService } from './toast.service'; import { LoadToast } from './components/load-toast/load.toast.component'; import { DropdownToast } from './components/dropdown-toast-component/dropdown.toast.component'; import { MultiButtonToast } from './components/multi-button-toast-component/multi.button.toast.component'; import { MultiDetailToast } from './components/multi-detail-toast-component/multi.detail.toast.component'; import { SingleDetailToast } from './components/single-detail-toast-component/single.detail.toast.component'; import { StatusToast } from './components/status-toast-component/status.toast.component'; import { MultiselectDropdownModule } from '../multiselect-dropdown/multiselect-dropdown.module'; import { MULTI_DETAIL_TOAST_BOTTOM, MULTI_DETAIL_TOAST_TOP } from 'projects/esp-common/src/lib/mockup'; describe('ToastComponent', () => { let component: ToastComponent; let toast: ToastService; let fixture: ComponentFixture; beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ declarations: [ ToastComponent, LoadToast, DropdownToast, MultiButtonToast, MultiDetailToast, SingleDetailToast, StatusToast, ], providers: [ToastService], imports: [MultiselectDropdownModule], }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(ToastComponent); component = fixture.componentInstance; toast = TestBed.inject(ToastService); component.toasts = { top: [], bottom: [] }; component.toastSubscription = null; fixture.detectChanges(); }); it('should call ngOnInit', () => { toast.toasts = []; component.ngOnInit(); expect(component.toasts.top).toStrictEqual([]); expect(component.toasts.bottom).toStrictEqual([]); }); it('should call getToasts', () => { toast.toasts = [MULTI_DETAIL_TOAST_BOTTOM, MULTI_DETAIL_TOAST_TOP]; component.getToasts(); expect(component.toasts.top).toStrictEqual([{ ...MULTI_DETAIL_TOAST_TOP }]); expect(component.toasts.bottom).toStrictEqual([{ ...MULTI_DETAIL_TOAST_BOTTOM }]); }); it('should call handleEvents', () => { component.getToasts = jest.fn(); // Scenario 1 const event1 = { type: 'otherEvent' }; component.handleEvents(event1); expect(component.getToasts).not.toHaveBeenCalled(); // Scenario 2 const event2 = { type: 'refreshedToasts' }; component.handleEvents(event2); expect(component.getToasts).toHaveBeenCalled(); }); it('should call ngOnDestroy', () => { component.toastSubscription.unsubscribe = jest.fn(); component.ngOnDestroy(); expect(component.toastSubscription.unsubscribe).toHaveBeenCalled(); }); it('should create', () => { expect(component).toBeTruthy(); }); });