import { test as base, expect } from "../conf";
import { CasePage } from "../../pom/case/case.page";

const test = base.extend<{ casePage18: CasePage }>({
    casePage18: async ({ page, conf }, use) => {
        const casePage = new CasePage(page);
        await base.step("Setup: Ensure request is in original case", async () => {
            await casePage.waitForSecond(2);
            const requests = (await casePage.caseLoc.detail.requestExitInRequestTable(conf.data.request_id_exist).all());
            if (requests.length !== 1) {
                await casePage.caseLoc.detail.requestExist(conf.data.request_id_exist).first().click({ force: true });
                await casePage.caseLoc.detail.update.btnUnArchive.click();
                await casePage.dashboardLoc.buttonByText("Unarchive").click()
                await casePage.caseLoc.btnCloseModal.click();
                await casePage.dashboardLoc.btnClosePopupNotification.click();

                await casePage.caseLoc.linkToCaseID(conf.data.case).click();
            }
        });

        await use(casePage);
    }
});

export { test };
