import Routing from '../../../../pages/eui/10x/routing-10x.js'
import EuiBlockContentPage from '../../../../pages/eui/10x/eui/eui-block-content-10x.po.js'
import EuiButtonPage from '../../../../pages/eui/10x/eui/eui-button-10x.po.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'

describe('eUI - <eui-block-content> Component Object ', async () => {
  let page = new EuiBlockContentPage();
  let euiButtonPage = new EuiButtonPage();
  let testFolder = './/eui-block-content//'
  it('should navigate to <eui-block-content> demo page ', async () => {
    browser.addTestMeta({uuid:"834685c8-cf44-11eb-b8bc-0242ac130003", zephyrKey: "CCQA-1109", zephyrStep: "407905", reportGroups: ["eUI.10x.eui"]});
    await page.open(Routing.getEUIComponentUrl('eui-block-content'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).toBeDisplayedInViewport({message:'<eui-block-content> page title is not displayed on page'});
    await expect(await $(page.appDocPageById('eui-block-content'))).toExist({message:'Page Id is not existing on page'});
    await expect(pgTitle).toHaveText('eui-block-content', {wait:1000,message:'Page title text is not as expected'});
    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-content> on page ', async () => {
    browser.addTestMeta({zephyrStep: "407906"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let index = 1;
    let blockContentByIndex1 = await page.blockContentByIndex(index).element();
    await expect(await $(page.sectionById(sectionId))).toBeDisplayed({message:'<'+sectionId+'> section -> is not displayed on page'});
    await expect(blockContentByIndex1).toBeDisplayed({message:'Block content by index '+ index +' is not displayed on page'});
    await chaiExpect(await page.blockContentByIndex(index).defaultComponentsCount()).equal(1, 'There should be 1 <eui-block-content> components on the page.');
    if(browser.config.useWdioImageComparison) {
      await blockContentByIndex1.scrollIntoView();
      await chaiExpect(await browser.checkElement(blockContentByIndex1, testFolder+'img_blockContentByIndex1', {hideElements: [await $('//eui-app-toolbar')]})).equal(0, 'Image comparison failed for blockContentByIndex1');
    }
    });
  it('should verify the methods wrapper and isBlocked ', async () => {
    browser.addTestMeta({zephyrStep: "407907"});
    let sectionId = 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let index = 1;
    let blockContent = page.blockContentByIndex(index);
    await chaiExpect(await blockContent.isBlocked()).equal(false, 'isBlocked is not false');
    await (await $(euiButtonPage.buttonByTextContains('Block Content').currentPath)).click();
    await browser.deductedWait(500);
    let blockContentWrapper = await $(blockContent.wrapper);
    await expect(blockContentWrapper).toBeDisplayed({message:'Block content wrapper is not displayed on page'});
    if(browser.config.useWdioImageComparison) {
      await blockContentWrapper.scrollIntoView();
      await chaiExpect(await browser.checkElement(blockContentWrapper, testFolder+'img_blockContentWrapper', {hideElements: [await $('//eui-app-toolbar')]})).within(0, 0.8 , 'Image comparison failed for blockContentWrapper');
      }
    await chaiExpect(await blockContent.isBlocked()).equal(true, 'isBlocked is not true');
    await (await $(euiButtonPage.buttonByTextContains('Unblock Content').currentPath)).click();

  });
});
