import { newSpecPage } from "@stencil/core/testing";
import { BpSdkOfflineQuote } from "./bp-sdk-offline-quote";
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-offline-quote></bp-sdk-offline-quote>',
        components: [BpSdkOfflineQuote],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    instance.carrier = {
        name: 'carrier_name',
        logo_url: 'http://asd.io/',
    };
    instance.product = {
        name: 'product name',
    };
    instance.showLogo = true;
    instance.showCustomLogo = false;
    return instance;
};
describe('bp-sdk-offline-quote', () => {
    describe('render', () => {
        it('vanilla', async () => {
            const page = await setupPage();
            setupInstance(page);
            await page.waitForChanges();
            expect(page.body.querySelector('.bp-sdk-offline-quote__container')).toBeTruthy();
            expect(page.body.querySelector('.bp-sdk-offline-quote__send-to-exchange')).toBeFalsy();
            expect(page.body.querySelector('bp-sdk-send-to-exchange-container')).toBeFalsy();
        });
        it('logo-url', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            await page.waitForChanges();
            expect(page.body.querySelector('img.bp-sdk-offline-quote__carrier-logo').src).toEqual(instance.carrier.logo_url);
        });
        it('custom url', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.showCustomLogo = true;
            instance.customLogoBaseUrl = 'http://img.com/';
            instance.showLogo = true;
            await page.waitForChanges();
            expect(page.body.querySelector('img.bp-sdk-offline-quote__carrier-logo').src).toEqual(`${instance.customLogoBaseUrl}${instance.carrier.name.toLowerCase()}.png`);
        });
        it('product', async () => {
            const page = await setupPage();
            setupInstance(page);
            await page.waitForChanges();
            expect(page.body.querySelector('.bp-sdk-offline-quote__product')).toBeTruthy();
        });
        it('renders external component if defined', async () => {
            const whenDefinedMock = jest.spyOn(customElements, 'whenDefined').mockResolvedValueOnce({});
            const page = await setupPage();
            setupInstance(page);
            await page.waitForChanges();
            expect(page.body.querySelector('.bp-sdk-offline-quote__container')).toBeFalsy();
            whenDefinedMock.mockRestore();
        });
    });
});
