import { newSpecPage } from "@stencil/core/testing";
import { BpSdkBackButton } from "./bp-sdk-back-button";
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-back-button></bp-sdk-back-button>',
        components: [BpSdkBackButton],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    return instance;
};
describe('bp-sdk-back-button', () => {
    it('renders', async () => {
        const page = await setupPage();
        await page.waitForChanges();
        const element = page.root.querySelector('div');
        expect(element).toBeTruthy();
        expect(page.root.querySelector('bp-sdk-external-back-button')).toBeFalsy();
        page.rootInstance.navigateBack.emit = jest.fn();
        page.root.querySelector('bp-sdk-button').click();
        expect(page.rootInstance.navigateBack.emit).toHaveBeenCalledTimes(1);
    });
    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-back-button')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
    it('does not emit click event if disabled', async () => {
        const page = await setupPage();
        await page.waitForChanges();
        page.rootInstance.buttonDisabled = true;
        page.rootInstance.navigateBack.emit = jest.fn();
        page.root.querySelector('bp-sdk-button').click();
        expect(page.rootInstance.navigateBack.emit).not.toHaveBeenCalled();
    });
});
