import { newSpecPage } from "@stencil/core/testing";
import { BpSdkMessage } from "./bp-sdk-message";
const mockMessage = {
    id: 'message-id',
    tenant_id: 'message-tenant-id',
    owner_id: 'message-owner-id',
    target: 'Your application is taken over by an operator',
    application_form_id: 'message-app-form-id',
    active: true,
};
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-message></bp-sdk-message>',
        components: [BpSdkMessage],
    });
};
const setupInstance = (page, message = mockMessage) => {
    const instance = page.rootInstance;
    instance.message = message;
    return instance;
};
describe('bp-sdk-message', () => {
    describe('renders', () => {
        it('external', async () => {
            const whenDefinedMock = jest.spyOn(customElements, 'whenDefined').mockResolvedValueOnce({});
            const page = await setupPage();
            setupInstance(page);
            await page.waitForChanges();
            expect(page.body.querySelectorAll('.bp-sdk-message__container').length).toBe(0);
            whenDefinedMock.mockRestore();
        });
        it('successfully renders', async () => {
            const page = await setupPage();
            setupInstance(page);
            await page.waitForChanges();
            expect(page.body.querySelectorAll('.bp-sdk-message__container').length).toBe(1);
        });
        it('successfully renders without message', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.message = {};
            await page.waitForChanges();
            expect(page.body.querySelectorAll('.bp-sdk-message__container').length).toBe(1);
        });
        it('renders text from the message', async () => {
            const page = await setupPage();
            setupInstance(page);
            await page.waitForChanges();
            expect(page.body.querySelector('.bp-sdk-message__container').innerHTML).toEqual(mockMessage.target);
        });
    });
});
