import Routing from '../../../pages/eui/14x/routing.js'
import EuiBlockDocumentPage from '../../../pages/eui/14x/eui-block-document.po.js'
import * as CookieBannerActions from '../../../actions/cookieBanner.js';
import BaseActions from '../../../actions/V14/base-actions.js';

describe('eUI - <eui-block-document> Component Object', async () => {
  let page = new EuiBlockDocumentPage();
  let testFolder = './/v14x//eui-block-document//'
  let pageName = 'eui-block-document';
  it('should navigate to <eui-block-document> demo page ', async () => {
    browser.addTestMeta({uuid:"984ed6d8-ee24-11eb-9a03-0242ac130003", zephyrKey: "CCQA-1110", zephyrStep: "407965", reportGroups: ["eUI.14x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-block-document'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    await expect(await $(page.navigationList)).toBeDisplayed({message:'Navigation List -> is not displayed on page'});
  });

  it('should verify the presence and number of component objects <eui-block-document> on page ', async () => {
    browser.addTestMeta({zephyrStep: "407966"});
    let sectionId= 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let index = 1;
    let blockDocumentByIndex1 = await page.blockDocumentByIndex(index).element();
    await (await $(page.euiButtonCOfromSectionWithIdByIndex(sectionId,2).currentPath)).click();
    await expect(await $(page.sectionById(sectionId))).toBeDisplayed({message:'<'+ sectionId +'> section -> is not displayed on page'});
    await expect(blockDocumentByIndex1).toBeDisplayed({message:'Block document by index '+ index +' is not displayed on page'});
    await chaiExpect(await page.blockDocumentByIndex(index).defaultComponentsCount()).equal(1, 'There should be 1 <eui-block-document> components on the page.');
    });
  it('should verify the methods loader and isBlocked ', async () => {
    browser.addTestMeta({zephyrStep: "407967"});
    let sectionId= 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    let index = 1;
    let blockDocument = page.blockDocumentByIndex(index);
    let blockDocumentLoader = await $(blockDocument.loader);
    await expect(blockDocumentLoader).not.toBeDisplayed({message:'Block document loader is displayed on page'});
    await chaiExpect(await blockDocument.isBlocked()).equal(false, 'isBlocked is not false');
    await (await $(page.euiButtonCOfromSectionWithIdByIndex(sectionId,2).currentPath)).click();
    await expect(await $(blockDocument.loader)).toBeDisplayed({message:'Block document loader is not displayed on page'});
    await chaiExpect(await blockDocument.isBlocked()).equal(true, 'isBlocked is not true');
    await (await $(page.euiButtonCOfromSectionWithIdByIndex(sectionId,2).currentPath)).click();
    if(browser.config.useWdioImageComparison) {
      await blockDocumentLoader.scrollIntoView();
      await chaiExpect(await browser.checkElement(blockDocumentLoader, testFolder+'img_blockDocumentLoader', {hideElements: [await $('//eui-app-toolbar')]})).within(0, 0.7 , 'Image comparison failed for blockDocumentLoader');
  }
  });
});
