import { newSpecPage } from "@stencil/core/testing";
import { BpSdkNotificationsContainer } from "./bp-sdk-notifications-container";
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-notifications-container></bp-sdk-notifications-container>',
        components: [BpSdkNotificationsContainer],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    return instance;
};
describe('bp-sdk-notifications-container', () => {
    it('does not render if no notifications are present', async () => {
        const page = await setupPage();
        await page.waitForChanges();
        const element = page.root.querySelector('div');
        expect(element).toBeNull();
        expect(page.root.querySelector('bp-sdk-external-notifications-container')).toBeFalsy();
    });
    it('renders if notifications are present', async () => {
        const page = await setupPage();
        const instance = setupInstance(page);
        instance.notifications = [{ id: '123', notification: 'test', created_at: new Date() }];
        await page.waitForChanges();
        const element = page.root.querySelector('div');
        expect(element).toBeTruthy();
        expect(page.root.querySelector('bp-sdk-external-notifications-container')).toBeFalsy();
    });
    it('renders external component if defined', async () => {
        const whenDefinedMock = jest.spyOn(customElements, 'whenDefined').mockResolvedValueOnce({});
        const page = await setupPage();
        await page.waitForChanges();
        expect(page.root.querySelector('bp-sdk-external-notifications-container')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
});
