import { test, expect } from '../../fixtures';
import { LoginPage } from '../../pom/login.page';
import { ReqPage } from '../../pom/request.page';

test.describe('Verify feature Search', () => {
    let loginPage: LoginPage;
    let reqPage: ReqPage;

    test.beforeEach(async ({ page, conf }) => {
        loginPage = new LoginPage(page);
        reqPage = new ReqPage(page);

        await loginPage.open();
        await loginPage.login(conf.data.username, conf.data.password);
        await expect(loginPage.baseLoc.dashboardContainer).toBeVisible();

        await reqPage.open();
        await expect(reqPage.reqLoc.pageTitle).toBeVisible();
    });

    test('REQ_004 - Verify when change entries per page', {
        tag: ['@REQ_004', '@request', '@ui']
    }, async () => {
        const totalRequests = await reqPage.getTotalEntries("requests")

        await test.step('Select 1 entries per page and verify pagination', async () => {
            await reqPage.selectEntriesPerPage(1);
            await expect(reqPage.reqLoc.pagingSummary).toContainText(`Showing 1 to 1 of ${totalRequests} entries`);
        });

        await test.step('Select 2 entries per page and verify pagination', async () => {
            await reqPage.selectEntriesPerPage(2);
            await expect(reqPage.reqLoc.pagingSummary).toContainText(`Showing 1 to 2 of ${totalRequests} entries`);
        });
    });
});
