import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import EuiMaxLengthPage from '../../../../pages/eui/10x/eui/eui-maxlength-10x.po.js'

describe('eUI - <eui-maxlength> Component Object ', async () => {
  let page = new EuiMaxLengthPage();
  let testFolder = './/eui-maxlength//';
  it('should navigate to <eui-maxlength> demo page', async () => {
    browser.addTestMeta({uuid:"0d33b530-d773-11ec-9d64-0242ac120002", zephyrKey: "CCQA-2078", zephyrStep: "488083", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUIDirectivesUrl('eui-max-length'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayedInViewport({wait:1000, message:'<euiMaxLength> page title is not displayed on page'});
    await expect(await $(page.appDocPageById('euiMaxLength'))).toExist({wait:1000, message: 'Page Id is not existing on page'});
    await chaiExpect(await pgTitle.getText()).equal('euiMaxLength', 'Page title text is not as expected');
    await expect(await $(page.navigationList)).toBeDisplayedInViewport({wait:1000, message:'Navigation List -> is not displayed on page'});
  });
 it('should verify the presence and number of component objects <eui-maxlength> on page ', async () => {
  browser.addTestMeta({zephyrStep: "488084"});
    let sectionId= 'Default';
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + sectionId + '> section -> does not exist on page');
    await sectionElement.scrollIntoView();
    await expect(sectionElement).toBeDisplayed({message:'<' + sectionId + '> section -> is not displayed on page'});
    let index = 1;
    let maxlengthByIndex1 = await (await page.maxlengthByIndex(index).element());
    expect(maxlengthByIndex1).toBeDisplayed({wait:1000, message:'maxlength by index '+ index +' is not displayed on page'});
    await chaiExpect(await page.maxlengthByIndex(index).defaultComponentsCount()).equal(2, 'There should be 2 <eui-maxlength> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await maxlengthByIndex1.scrollIntoView();
      await chaiExpect(await browser.checkElement(maxlengthByIndex1, testFolder+'img_maxlengthByIndex1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for maxlengthByIndex1');
    }
  });
});
