import { newSpecPage } from "@stencil/core/testing";
import { BpSdkTakeOver } from "./bp-sdk-take-over";
describe('bp-sdk-take-over', () => {
    it('renders', async () => {
        const page = await newSpecPage({
            html: '<bp-sdk-take-over></bp-sdk-take-over>',
            components: [BpSdkTakeOver],
        });
        await page.waitForChanges();
        expect(page.root.querySelector('bp-sdk-take-over-button')).toBeFalsy();
        expect(page.root.querySelector('bp-sdk-external-take-over')).toBeFalsy();
    });
    it('renders button if conditions met', async () => {
        const page = await newSpecPage({
            html: '<bp-sdk-take-over></bp-sdk-take-over>',
            components: [BpSdkTakeOver],
        });
        const instance = page.rootInstance;
        instance.canTakeOver = true;
        instance.isCloned = false;
        instance.isLocked = false;
        instance.isOwner = false;
        instance.isFormLoaded = true;
        await page.waitForChanges();
        expect(page.root.querySelector('bp-sdk-take-over-button')).toBeTruthy();
        expect(page.root.querySelector('bp-sdk-external-take-over')).toBeFalsy();
    });
    it('does not render button if owner', async () => {
        const page = await newSpecPage({
            html: '<bp-sdk-take-over></bp-sdk-take-over>',
            components: [BpSdkTakeOver],
        });
        const instance = page.rootInstance;
        instance.canTakeOver = true;
        instance.isCloned = false;
        instance.isLocked = false;
        instance.isOwner = true;
        instance.isFormLoaded = true;
        await page.waitForChanges();
        expect(page.root.querySelector('bp-sdk-take-over-button')).toBeFalsy();
        expect(page.root.querySelector('bp-sdk-external-take-over')).toBeFalsy();
    });
    it('does not render button if form is not loaded', async () => {
        const page = await newSpecPage({
            html: '<bp-sdk-take-over></bp-sdk-take-over>',
            components: [BpSdkTakeOver],
        });
        const instance = page.rootInstance;
        instance.canTakeOver = true;
        instance.isCloned = false;
        instance.isLocked = false;
        instance.isOwner = false;
        instance.isFormLoaded = false;
        await page.waitForChanges();
        expect(page.root.querySelector('bp-sdk-take-over-button')).toBeFalsy();
        expect(page.root.querySelector('bp-sdk-external-take-over')).toBeFalsy();
    });
    it('renders external component if defined', async () => {
        const whenDefinedMock = jest.spyOn(customElements, 'whenDefined').mockResolvedValueOnce({});
        const page = await newSpecPage({
            html: '<bp-sdk-take-over></bp-sdk-take-over>',
            components: [BpSdkTakeOver],
        });
        await page.waitForChanges();
        expect(page.root.querySelector('bp-sdk-external-take-over')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
});
