import { newSpecPage } from "@stencil/core/testing";
import { BpSdkBusinessClassificationSelectorNudge } from "./bp-sdk-business-classification-selector-nudge";
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-business-classification-selector-nudge></bp-sdk-business-classification-selector-nudge>',
        components: [BpSdkBusinessClassificationSelectorNudge],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    instance.refilter = {};
    instance.handleYesClick = jest.fn();
    instance.handleNoClick = jest.fn();
    return instance;
};
describe('bp-sdk-business-classification-selector-nudge', () => {
    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-business-classification-selector-nudge')).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-business-classification-selector-nudge')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
    describe('.onYesClick', () => {
        it('calls handleYesClick prop function', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.onYesClick(new MouseEvent('click'));
            expect(instance.handleYesClick).toHaveBeenCalledTimes(1);
        });
    });
    describe('.onNoClick', () => {
        it('calls handleYesClick prop function', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.onNoClick(new MouseEvent('click'));
            expect(instance.handleNoClick).toHaveBeenCalledTimes(1);
        });
    });
    describe('click yes button', () => {
        it('calls onYesClick function', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.onYesClick = jest.fn();
            await page.waitForChanges();
            const yesBtn = page.body.querySelector('.bp-sdk-business-classification-selector-nudge__btn--yes');
            await yesBtn.click();
            expect(instance.onYesClick).toHaveBeenCalledTimes(1);
        });
    });
    describe('click no button', () => {
        it('calls onNoClick function', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.onNoClick = jest.fn();
            await page.waitForChanges();
            const noBtn = page.body.querySelector('.bp-sdk-business-classification-selector-nudge__btn--no');
            await noBtn.click();
            expect(instance.onNoClick).toHaveBeenCalledTimes(1);
        });
    });
});
