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

describe('eUI - <ux-tree> Component Object', async () => {
  let treePage = new TreePage();
  it('should navigate to <ux-tree> component', async () => {
    browser.addTestMeta({uuid:"34b01384-908d-11eb-a8b3-0242ac130003", zephyrKey: "CCQA-963", zephyrStep: "385407", reportGroups: ["eUI.10x.ux"]});
    await treePage.open(Routing.getUxComponentUrl('ux-tree'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(treePage.pageTitle);
    let appDocPageId = await $(treePage.appDocPageById('ux-tree'));
    let navigationList = await $(treePage.navigationList);

   await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-tree> page title is not visible on page'});
   await expect(await pgTitle.getText()).toBe('ux-tree', '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 <ux-tree> from page after specific methods', async () => {
   browser.addTestMeta({zephyrStep: "385408"});
   await expect(await $(treePage.treeFromSectionById('Default').treeList)).toBeDisplayedInViewport({message: '<Default> section -> is not visible on page'});
    let tree1 = treePage.treeByIndex(1);
   await expect(await $(tree1.treeList)). toBeDisplayedInViewport({message: 'Tree by index "1" is not visible on page'});
   await expect(await $(treePage.treeByTextContains('node').treeList)).toBeDisplayedInViewport({message:'Tree by text "node" is not visible on page'});
   await expect(await $(treePage.treeByTextContainsAndIndex('node', 1).treeList)).toBeDisplayedInViewport({message: 'Tree by text "node" and index 1 is not visible on page' });
  });
  it('should verify  <ux-tree> properties', async () => {
   browser.addTestMeta({zephyrStep: "385409"});

   let sectionId= 'Default';
   let scrollIntoSection = await $(treePage.treeFromSectionById(sectionId).treeList);
   await scrollIntoSection.scrollIntoView();

   let tree = treePage.treeFromSectionWithIdByIndex(sectionId,1);
   await expect(await $(tree.treeList)).toBeDisplayedInViewport({message:'Tree with index 1 from Default section, treeList property is not visible on page'});
   await expect(await $(tree.coUxAtoolbarFilter.currentPath)).not.
      toExist({message:'Tree with index 1 from Default section, coUxAtoolbarFilter property is existing on page'});
   await expect(await $(tree.coUxTreeNode.dataE2E)).
      toBeDisplayedInViewport({message:'Tree with index 1 from Default section, coUxTreeNode property is not visible on page'});

   sectionId= 'isMultiselect';
   scrollIntoSection = await $(treePage.treeFromSectionById(sectionId).treeList);
   await scrollIntoSection.scrollIntoView();
   tree = treePage.treeFromSectionWithIdByIndex(sectionId,1);
   await expect(await $(tree.selectAllCheckbox)).toExist({message:'Tree with index 1 from isMultiselect section, selectAllCheckbox property is not existing on page'});
   await expect(await $(tree.selectAllCheckboxLabel)).toBeDisplayedInViewport({message:'Tree with index 1 from isMultiselect section, checkboxLabel property is not visible on page'});
   await expect(await tree.isMultiselect()).toBe(true, 'isMultiselect tree should be true' );
   await expect(await tree.isIndeterminate()).toBe(false, 'isIndeterminate tree should be false' );
   await expect(await tree.isHideLines()).toBe(false, 'isHideLines tree should be false' );
   await expect(await tree.hasOneLevel()).toBe(false, 'hasOneLevel tree should be false' );
  });

  it('should verify  <ux-tree-node> properties', async () => {
    browser.addTestMeta({zephyrStep: "385410"});

   let sectionId= 'link-type';
   let scrollIntoSection = await $(treePage.treeFromSectionById(sectionId).treeList);
   await scrollIntoSection.scrollIntoView();

   let treeNode = treePage.treeFromSectionWithIdByIndex(sectionId,1).coUxTreeNode;
   await expect(await $(treeNode.treeNodeWrapper)).toBeDisplayedInViewport({message:'Tree with index 1 from link-type section, treeNodeWrapper property is not visible on page'});
   let treeNode2 = treePage.treeNodeFromSectionWithIdByIndex(sectionId,2)
   await expect(await $(treeNode2.dataE2E)).toBeDisplayedInViewport({message:'Tree node 2 from link-type section is not visible on page'});
   let treeNode6 = treePage.treeNodeFromSectionWithIdByIndex(sectionId,6)
   await expect(await treeNode2.isFirst()).toBe(true, 'isFirst treeNode2 should be true' );
   await expect(await treeNode6.isFirst()).toBe(false, 'isFirst treeNode6 should be false' );
   await expect(await treeNode6.isLast()).toBe(true, 'isLast treeNode6 should be true' );
   await expect(await treeNode2.isLast()).toBe(false, 'isLast treeNode2 should be false' );
   await expect(await treeNode.isNodeExpanded()).toBe(true, 'isNodeExpanded treeNode should be true' );
   await expect(await $(treeNode.typeLabel)).toBeDisplayedInViewport({message:'Tree with index 1 from link-type section, nodeContentType property is not visible on page'});
   await expect(await treeNode.isNodeTypeParent()).toBe(true, 'isNodeTypeParent should be true' );
   await expect(await $(treeNode.nodeLabelWrapped)).toBeDisplayedInViewport({message: 'Tree with index 1 from link-type section, nodeContentLabelWrapped property is not visible on page'});
   await expect(await $(treePage.treeFromSectionWithIdByIndex(sectionId,2).coUxTreeNode.nodeIcon)).
      toBeDisplayedInViewport({message:'Tree with index 1 from link-type section, nodeContentIcon property is not visible on page'});
   await expect(await $(treeNode.nodeLabelWrappedSpanLabel)).
      toBeDisplayedInViewport({message:'Tree with index 1 from link-type section, nodeLabelWrappedSpanLabel property is not visible on page'});
   sectionId= 'isMultiselect';
   scrollIntoSection = await $(treePage.treeFromSectionById(sectionId).treeList);
   await scrollIntoSection.scrollIntoView();
   await browser.execute("arguments[0].click();", await $(treePage.inputByValue('DIGIT A')));
   treeNode = treePage.treeNodeFromSectionWithIdByIndex(sectionId,1);
   await expect(await treeNode.isSelected()).toBe(true, 'isSelected should be true' );
   await expect(await treePage.treeFromSectionWithIdByIndex(sectionId,1).isMultiselect()).toBe(true, 'isMultiselect should be true' );
   await expect(await $(treeNode.multiselectSpan)).
      toBeDisplayedInViewport({message:'Tree node 1 from isMultiselect section, multiselectSpan property is not visible on page'});
   await expect(await $(treeNode.multiselectCheckbox)).
      toExist({message:'Tree node 1 from isMultiselect section, multiselectCheckbox property is not existing on page'});
   await expect(await $(treeNode.multiselectCheckboxLabel)).
      toBeDisplayedInViewport({message:'Tree node 1 from isMultiselect section, multiselectCheckboxLabel property is not visible on page'});
   await expect(await $(treeNode.nodeLabelSpanLabel)).
      toBeDisplayedInViewport({message:'Tree with index 1 from Default section, nodeLabelSpanLabel property is not visible on page'});
   sectionId= 'misc-options';
   scrollIntoSection = await $(treePage.treeFromSectionById(sectionId).treeList);
   await scrollIntoSection.scrollIntoView();
   let tree = await $(treePage.treeFromSectionWithIdByIndex(sectionId,4).treeList);
   await tree.scrollIntoView();
   treeNode = treePage.treeNodeFromSectionWithIdByIndex(sectionId,15);
   await expect(await $(treeNode.customContent)).
      toBeDisplayedInViewport({message:'Tree node 15 from isMultiselect section, customContent property is not visible on page'});
   await expect(await treeNode.hasCustomContent()).toBe(true, 'hasCustomContent should be true' );
   sectionId= 'panel';
   scrollIntoSection = await $(treePage.treeFromSectionById(sectionId).treeList);
   await scrollIntoSection.scrollIntoView();
   tree = await $(treePage.treeFromSectionWithIdByIndex(sectionId,2).treeList);
   await tree.scrollIntoView();
   await expect(await $(treePage.treeNodeFromSectionWithIdByIndex(sectionId,7).nodeBadgeCO.currentPath)).
      toBeDisplayedInViewport({message:'Tree node 15 from panel section, nodeContentBadge property is not visible on page'});
   await expect(await $(treePage.treeNodeFromSectionWithIdByIndex(sectionId,6).treeNodesList)).
      toBeDisplayedInViewport({message:'Tree node 15 from panel section, treeNodesList property is not visible on page'});
   await expect(await treePage.treeNodeFromSectionWithIdByIndex(sectionId,6).hasChildren()).toBe(true, 'hasChildren should be true' );
   await expect(await $(treePage.treeNodeFromSectionWithIdByIndex(sectionId,6).coUxTreeNode.dataE2E)).
      toBeDisplayedInViewport({message:'Tree node 15 from panel section, coUxTreeNode.dataE2E property is not visible on page'});
  });

  it('should verify CoUxTreeNodeBadge ', async () => {
   browser.addTestMeta({zephyrStep: "385409"});

   let sectionId= 'panel';
   let scrollIntoSection = await $(treePage.treeFromSectionById(sectionId).treeList);
   await scrollIntoSection.scrollIntoView();

   let tree = treePage.treeFromSectionWithIdByIndex(sectionId,2);
   await expect(await $(tree.treeList)).toBeDisplayedInViewport({message:'Tree with index 1 from panel section, treeList property is not visible on page'});
   await expect(await $(tree.coUxTreeNode.nodeBadgeCO.currentPath)).toExist({message:'Badge from panel section, badge is not existing on page'});
  });
});
