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

describe('eUI  <ux-tree-list> Component Object ', async () => {
  let page = new TreeList();
  it('should navigate to <ux-tree-list> component', async () => {
    browser.addTestMeta({uuid:"78b6e68c-91fc-11eb-a8b3-0242ac130003", zephyrKey: "CCQA-563", zephyrStep: "319851", reportGroups: ["eUI.10x.ux"]});
    await page.open(Routing.getUxComponentUrl('ux-tree-list'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    await pgTitle.scrollIntoView();
    await expect(await $(pgTitle)).
      toBeDisplayedInViewport({message:'<ux-tree-list> page title is not visible on page'});
    await expect(await $(page.appDocPageById('ux-tree-list'))).toExist({message:'Page Id is not present in page'});
    await expect(await pgTitle.getText()).toBe('ux-tree-list');
    await expect(await $(page.navigationList)).toBeDisplayedInViewport({message:'Navigation List -> is not visible on page'});
  });
  it('should verify the section title of the component object page ', async () => {
    browser.addTestMeta({zephyrStep: "319852"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    let treeList = page.treeListByIndex(1);
    await expect(await $(page.sectionById(sectionId))).toBeDisplayedInViewport({message:'<Default> section -> is not visible on page'});
    await expect(await $(page.treeListByIndex(1).dataE2E)).toBeDisplayedInViewport({message:'Tree list by index "1" is not visible on page'});
    await expect(await $(page.treeListByTextContains('Item 1 - with children').dataE2E)).
      toBeDisplayedInViewport({message:'Tree list by text "Item 1 - with children" is not visible on page'});
    await expect(await $(page.treeListByTextEqualsAndIndex('Item 1 - with children', 1).dataE2E)).
      toBeDisplayedInViewport({message:'Tree list by text "Item 1 - with children" and index 1 is not visible on page'});

    await expect(await treeList.defaultComponentsCount()).toBe(20,
      'There should be 20 <ux-tree-list> components on the page.');

    await expect(await $(page.sectionById('isExpanded'))).
      toBeDisplayedInViewport({message:'isExpanded section -> is not visible on page'});
    sectionId = 'extra-content-simple';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await $(page.sectionById(sectionId))).toBeDisplayedInViewport({message:'extra-content-simple section -> is not visible on page'});
    await expect(await $(page.sectionById('extra-content-advanced'))).toBeDisplayedInViewport({message:'extra-content-advanced section -> is not visible on page'});

    sectionId= 'subTreeLinks';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    await expect(await $(page.sectionById(sectionId))).toBeDisplayedInViewport({message:'subTreeLinks section -> is not visible on page'});
    await expect(await $(page.sectionById('toolbar'))).toBeDisplayedInViewport({message:'toolbar section -> is not visible on page'});
  });
  it('should verify the presence of the Component Object on the page ', async () => {
    browser.addTestMeta({zephyrStep: "319853"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    let treeListItem = page.treeListByIndex(1).treeListItemCO;
    await expect(await $(treeListItem.dataE2E)).toBeDisplayedInViewport({message:'Tree list item is not visible on page'});

    await expect(await treeListItem.defaultComponentsCount()).toBe(3,'There should be 3 <ux-tree-list-item> components in first tree list on the page.');
    let treeList = page.treeListByIndex(1);
    await expect(await treeList.hasLeftIndent()).toBe(true,'hasLeftIndent should be true');
    sectionId = 'extra-content-simple';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();
    treeList = page.treeListFromSectionById(sectionId);
    await expect(await treeList.hasItemsBullet()).toBe(true,'hasItemsBullet should be true');

  });
  it('should verify the presence tree-list-item under tree-item CO ', async () => {
    browser.addTestMeta({zephyrStep: "319854"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    let treeListItem = page.treeListByIndex(1).treeListItemCO;
    await expect(await $(treeListItem.dataE2E)).toBeDisplayedInViewport({message:'Tree list item is not visible on page'});

    await expect(await $(treeListItem.byIndex(1).currentPath)).toBeDisplayedInViewport({message:'Tree list item by index 1 is not visible on page'});
    await expect(await $(treeListItem.byTextContains("Item 2").currentPath)).
      toBeDisplayedInViewport({message:'Tree list item by text "Item 2" is not visible on page'});
    await expect(await (await $(treeListItem.alabelCO.labelContentLabel)).getText()).toBe('Item 2');
  });

  it('should navigate to <ux-tree-list> <Toolbar> section to verify the Tree List Item presence ', async () => {
    browser.addTestMeta({zephyrStep: "354194"});
    let sectionId= 'toolbar';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    let treeListItem = page.treeListFromSectionById(sectionId).treeListItemCO;
    await expect(await $(treeListItem.dataE2E)).toBeDisplayedInViewport({message:'Tree list item is not visible on page'});
    await expect(await treeListItem.defaultComponentsCount()).toBe(12,'There should be 12 <ux-tree-list-item> components in toolbar section on the page.');
  });

  it('should verify the filter functionality  ', async () => {
    browser.addTestMeta({zephyrStep: "354195"});
    let sectionId= 'toolbar';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    let toolbarFilter = page.treeListFromSectionWithIdByIndex(sectionId,1).toolbarFilterCO;
    await expect(await $(toolbarFilter.dataE2E)).toBeDisplayedInViewport({message:'Toolbar filter is not visible on page'});
    await expect(await toolbarFilter.defaultComponentsCount()).toBe(1,
      'There should be 1 <ux-a-toolbar-filter> components in toolbar section in first tree list on the page.');
    await expect(await $(toolbarFilter.inputGroupFilterInput)).
      toBeDisplayedInViewport({message:'Toolbar filter  inputGroupFilterInput property is not visible on page'});
    await (await $(toolbarFilter.inputGroupFilterInput)).setValue('Item 3');
    await expect(await $(page.treeListFromSectionWithIdByIndex(sectionId,1).treeListItemCO.byTextContains("Item 3").currentPath)).
      toBeDisplayedInViewport({message:'Tree list item by text "Item 3" is not visible on page'});
  });
});

