import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import ActionBoxPage from '../../../../pages/eui/10x/ux/ux-action-box-10x.po.js'

describe('eUI - <ux-action-box> Component Object', async() => {
  let actionPage = new ActionBoxPage();
  it('should navigate to <ux-action-box> component ', async() => {
    browser.addTestMeta({uuid:"019f1028-7d99-11eb-9439-0242ac130002", zephyrKey: "CCQA-705", zephyrStep: "354187", reportGroups: ["eUI.10x.ux"]});
    await actionPage.open(Routing.getUxComponentUrl('ux-action-box'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(actionPage.pageTitle);
    let appDocPageId = await $(actionPage.appDocPageById('ux-action-box'));
    let navigationList = await $(actionPage.navigationList);
    await pgTitle.scrollIntoView();
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-action-box> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-action-box', {wait: 1000, message: 'Page title text is not as expected'});
    await expect(appDocPageId).toExist({wait:1000, message:'Page Id is not present in page'});
    await expect(navigationList).toBeDisplayed({wait:1000, message:'Navigation List -> is not visible on page'});
  });
  it('should verify the presence of the Component Object on the page ', async() => {
    browser.addTestMeta({zephyrStep: "354188"});
    await expect(await $(actionPage.actionBoxFromSectionById('Default').dataE2E)).
      toBeDisplayedInViewport({message:'<Default> section -> is not visible on page'});
    await expect(await $(actionPage.actionBoxByIndex(1).dataE2E)).
      toBeDisplayedInViewport({message: 'Action box by index "1" is not visible on page' });
    await expect(await $(actionPage.actionBoxByTextContains('Action box').dataE2E)).
      toBeDisplayedInViewport({message:'Action box by text "Action box" is not visible on page' });
    await expect(await $(actionPage.actionBoxByTextEqualsAndIndex('Action box', 1).dataE2E)).
      toBeDisplayedInViewport({message:'Action box by text "Action box" and index 1 is not visible on page' });
    await chaiExpect(await actionPage.actionBoxByIndex(1).defaultComponentsCount()).equal(4, 'There should be 4 <ux-action-box> components on the page.')
  });
  it('should verify the presence of the main elements of the Component Object on the page ', async() => {
    browser.addTestMeta({zephyrStep: "354189"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(actionPage.actionBoxFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();

    let page1 = actionPage.actionBoxFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(page1.boxContent)).
      toBeDisplayedInViewport({message:'Action box with index 1 from Default section boxContent property is not visible on page'});
    await expect(await $(page1.boxActions)).
      toBeDisplayedInViewport({message:'Action box with index 1 from Default section boxActions property is not visible on page'});
    await expect(await $(page1.panelCO.dataE2E)).
      toBeDisplayedInViewport({message:'Action box with index 1 from Default section panelCO.dataE2E is not visible on page'});
    await expect(await $(page1.actionBoxIconToggle)).
      toBeDisplayedInViewport({message:'Action box with index 1 from Default section actionBoxIconToggle property is not visible on page'});
    await expect(await $(page1.listItemsCO.currentPath)).
      toBeDisplayedInViewport({message:'Action box with index 1 from Default section listItems property is not visible on page'});
    await expect(await $(page1.listItemsCO.currentPath)).toHaveTextContaining('ACTION BLOCK TITLE', {wait: 1000, message: 'List items component does not have the expected containg text'});

    sectionId= 'isLeftPositioned';
    scrollIntoSection = await $(actionPage.actionBoxFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();

    page1 = actionPage.actionBoxFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(page1.panelCO.panelHeaderPlaceholder)).toBeDisplayedInViewport({
      message:'Action box with index 1 from isLeftPositioned section panelHeaderPlaceholder property is not visible on page'});
  });
  it('should verify the Action Box List Item labels', async() => {
    browser.addTestMeta({zephyrStep: "354190"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(actionPage.actionBoxFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    let page1 = actionPage.actionBoxFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(page1.listItemsCO.currentPath)).
      toBeDisplayedInViewport({message:'Action box with index 1 from Default section, listItems property is not visible on page'});
    await expect(await $(page1.listItemsCO.listItemCO.listLabel.labelContentLabel)).toHaveTextContaining('label', {wait: 1000, message: 'List Label Content label is not as expected'});
    await expect(await $(page1.listItemsCO.listItemCO.listLabel.subLabel)).toHaveTextContaining('label', {wait: 1000, message: 'List Label Sub label is not as expected'});
  });
  it('should verify if the first action box is expanded CO', async() => {
    browser.addTestMeta({zephyrStep: "354191"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(actionPage.actionBoxFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    let page1 = actionPage.actionBoxFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(page1.boxActions)).
      toBeDisplayedInViewport({message:'Action box with index 1 from Default section, boxActions property is not visible on page'});
    await expect(await page1.isExpanded()).toBe(true, 'isExpanded should be true');
  });
  it('should verify the action box position relative to container CO', async() => {
    browser.addTestMeta({zephyrStep: "354192"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(actionPage.actionBoxFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    let page1 = actionPage.actionBoxFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(page1.boxActions)).toBeDisplayedInViewport({
      message:'Action box with index 1 from isLeftPositioned section, boxActions property is not visible on page'});
    await expect(await page1.isLeftPositioned()).toBe(false, 'isLeftPositioned should be false');

    sectionId= 'isLeftPositioned';
    scrollIntoSection = await $(actionPage.actionBoxFromSectionById(sectionId).dataE2E);
    await scrollIntoSection.scrollIntoView();
    page1 = actionPage.actionBoxFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(page1.boxActions)).toBeDisplayedInViewport({
      message:'Action box with index 1 from isLeftPositioned section, isLeftPositioned property is not visible on page'});
    await expect(await page1.isLeftPositioned()).toBe(true, 'isLeftPositioned should be true');
  });
});
