import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import DropdownTreePage from '../../../../pages/eui/10x/ux/ux-dropdown-tree-10x.po.js';

describe('should navigate to  <ux-dropdown-tree> Component Object ', async () => {
  let page = new DropdownTreePage();
  it('should navigate to <ux-dropdown-tree> component', async () => {
    browser.addTestMeta({uuid:"b5233044-9224-11eb-a8b3-0242ac130003", zephyrKey: "CCQA-523", zephyrStep: "318742", reportGroups: ["eUI.10x.ux"]});
    await page.open(Routing.getUxComponentUrl('ux-dropdown-tree'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    let appDocPageId = await $(page.appDocPageById('ux-dropdown-tree'));
    let navigationList = await $(page.navigationList);
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-dropdown-tree> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-dropdown-tree', {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 identify <dropdown-tree-button> by index and text and open the first one ', async () => {
    browser.addTestMeta({zephyrStep: "318743"});
    await expect(await $(page.sectionById('Default'))).toBeDisplayedInViewport({message:'<Default> section -> is not visible on page'});
    await expect(await $(page.dropdownTreeByIndex(1).currentPath)).
      toBeDisplayedInViewport({message:'Dropdown tree by index "1" is not visible on page'});
    await expect(await $(page.dropdownTreeByTextContains('Select...').currentPath)).
     toBeDisplayedInViewport({message:'Dropdown tree by text "Select..." is not visible on page'});
    await expect(await $(page.dropdownTreeByTextEqualsAndIndex('Select...', 1).currentPath)).
     toBeDisplayedInViewport({message:'Dropdown tree by text "Select..." and index 1 is not visible on page'});
    await expect(await $$(page.dropdownTreeByIndex(1).byDefault().currentPath)).toBeElementsArrayOfSize(29);
    await expect(await $(page.dropdownTreeByIndex(1).dropdownButtonCO.currentPath)).
     toBeDisplayedInViewport({message:'Dropdown buttom is not visible on page'});
    await expect(await $(page.dropdownTreeByIndex(1).dropdownButtonCO.byIndex(1).buttonCO.button)).
     toBeDisplayedInViewport({message:'Dropdown buttom by index "1" is not visible on page'});
    await expect(await $(page.dropdownTreeByIndex(1).dropdownButtonCO.byTextContains('Select...').buttonCO.button)).
      toBeDisplayedInViewport({message:'Dropdown buttom by text "Select..." is not visible on page'});
    await expect(await $(page.dropdownTreeByIndex(1).dropdownButtonCO.byTextContainsAndIndex('Select...', 1).buttonCO.button)).
      toBeDisplayedInViewport({message:'Dropdown buttom by text "Select..." and index 1 is not visible on page'});
    await expect(await $$(page.dropdownTreeByIndex(1).dropdownButtonCO.byDefault().currentPath)).toBeElementsArrayOfSize(1);

  });
  it('should click on the first <dropdown-tree-button> button and verify the resulted -> <dropdown-tree> component ', async () => {
    browser.addTestMeta({zephyrStep: "318744"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    let tree = page.dropdownTreeFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(tree.currentPath)).toBeDisplayedInViewport({message:'Dropdown tree from Deafault section is not visible on page'});

    let button = tree.dropdownButtonCO.byIndex(1).buttonCO.button;
    await expect(await $(button)).toBeDisplayedInViewport({message:'button from Default section is not visible on page'});
    await (await $(button)).click();
    let treeContainer = page.dropdownTreeByIndex(1);
    await expect(await $(treeContainer.dropdownTreeContainer)).toBeDisplayedInViewport({message:'dropdownTreeContainer is not visible on page'});
    await expect(await $(treeContainer.treeCO.treeList)).toBeDisplayedInViewport({message:'treeCO treeList is not visible on page'});
    let treeNodeLabel = await $(treeContainer.treeCO.coUxTreeNode.nodeLabelSpanLabel);
    await expect(treeNodeLabel).toBeDisplayedInViewport({message:'treeNodeLabel is not visible on page'});
    await expect(treeNodeLabel).toHaveText('node 1');
  });
});
