import { test as base } from "../conf";
import { RequestPage } from "../../pom/request/request.page";

const test = base.extend<{ requestPage31: RequestPage }>({
    requestPage31: async ({ page, conf }, use) => {
        const requestPage = new RequestPage(page);
        await base.step("Setup: Unarchived the old case before move request", async () => {
            await requestPage.search(conf.data.case);
            await requestPage.waitForSecond(3)
            const dataFound = (await requestPage.dashboardLoc.table.itemInRow(conf.data.case).all()).length;
            if (dataFound > 0) {
                await requestPage.getDetailCase(conf.data.case);
            } else {
                await requestPage.getDetailCase(conf.data.case, conf.data.archive);
                await requestPage.dashboardLoc.buttonLinkByText("unarchiving.").click();
                await requestPage.dashboardLoc.buttonByText("Unarchive").click();
                await requestPage.open();
                await requestPage.getDetailCase(conf.data.case);
            }   
        });

        await use(requestPage);
    }
});

export { test };
