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

const test = base.extend<{ casePage16: CasePage }>({
    casePage16: async ({ page, conf }, use) => {
        const casePage = new CasePage(page);
        
        await base.step("Setup: Checkcase already unarchive", async () => {
            await casePage.waitForSecond(2);
            const caseFind = (await casePage.dashboardLoc.table.itemInRow(conf.data.case).all()).length;
            if (caseFind === 0) {
                await casePage.dashboardLoc.search.filter.btn.click();
                await casePage.caseLoc.inputArchive.fill("Yes");
                await casePage.caseLoc.boxSelectArchive.click();
                await casePage.dashboardLoc.search.filter.popup.btnApply.click();
                await casePage.dashboardLoc.table.itemInRow(conf.data.case).click();
                await casePage.caseLoc.detail.update.btnUnArchive.click();
                await casePage.dashboardLoc.btnClosePopupNotification.click();
                await expect(casePage.caseLoc.detail.update.btnUnArchive).not.toBeVisible();
            } else {
                await casePage.dashboardLoc.table.itemInRow(conf.data.case).click();
            }
        });

        await use(casePage);
    }
});

export { test };
