import { ApplicationFormProcessJobType, ApplicationFormProcessState } from "@boldpenguin/sdk-types";
import { newSpecPage } from "@stencil/core/testing";
import { BpSdkPendingProcess } from "./bp-sdk-pending-process";
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-pending-process></bp-sdk-pending-process>',
        components: [BpSdkPendingProcess],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    instance.pendingProcesses = [
        { job_type: ApplicationFormProcessJobType.JornayaAudit, state: ApplicationFormProcessState.Completed },
    ];
    return instance;
};
describe('bp-sdk-pending-process', () => {
    it('renders', async () => {
        const page = await setupPage();
        setupInstance(page);
        await page.waitForChanges();
        const element = page.root.querySelector('div');
        expect(element).toBeTruthy();
        expect(page.root.querySelector('bp-sdk-external-pending-process')).toBeFalsy();
        const processItemElement = page.body.querySelector('.bp-sdk-pending-process-item__completed');
        expect(processItemElement).toBeTruthy();
    });
    it('does not render if there are no processes', async () => {
        const page = await setupPage();
        const instance = page.rootInstance;
        instance.pendingProcesses = [];
        await page.waitForChanges();
        const element = page.root.querySelector('div');
        expect(element).toBeNull();
    });
    it('renders external component if defined', async () => {
        jest.spyOn(customElements, 'whenDefined').mockReturnValueOnce(Promise.resolve());
        const page = await setupPage();
        await page.waitForChanges();
        expect(page.root.querySelector('bp-sdk-external-pending-process')).toBeTruthy();
    });
});
