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

describe('eUI  <ux-tree-list-item> Component Object ', async () => {
  let page = new TreeListItem();
  it('should navigate to <ux-tree-list-item> component', async () => {
    browser.addTestMeta({uuid:"6ae53c46-9136-11eb-a8b3-0242ac130003", zephyrKey: "CCQA-564", zephyrStep: "319855", reportGroups: ["eUI.10x.ux"]});
    await page.open(Routing.getUxComponentUrl('ux-tree-list'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    let appDocPageId = await $(page.appDocPageById('ux-tree-list'));
    let navigationList = await $(page.navigationList);
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-tree-list> page title is not visible on page'});
    await expect(await pgTitle.getText()).toBe('ux-tree-list', '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 tree-list-item under tree-item CO ', async () => {
    browser.addTestMeta({zephyrStep: "319893"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    await (await $(page.sectionById(sectionId))).waitForDisplayed({ timeout: 5000, timeoutMsg: '<Default> section -> is not visible on page', interval: 100});
    let treeListItem = page.treeListItemByIndex(1);
    await expect(await $(treeListItem.dataE2E)).toBeDisplayedInViewport({message:'Tree-list-item by index "1" is not visible on page'});
    await expect(await $(page.treeListItemByTextContains('Item 1 - with children').dataE2E)).
      toBeDisplayedInViewport({message:'Tree-list-item by text "Item 1 - with children" is not visible on page'});
    await expect(await $(page.treeListItemByTextEqualsAndIndex('Item 1 - with children', 1).dataE2E)).
      toBeDisplayedInViewport({message: 'Tree-list-item by text "Item 1 - with children" and index 1 is not visible on page'});
    await expect(await treeListItem.defaultComponentsCount()).toBe(59,'There should be 59 <ux-tree-list-item> components on the page.');
    await expect(await (await $(treeListItem.alabelCO.labelContentLabel)).getText()).toBe('Item 1 - with children');
    await expect(await treeListItem.isExpanded()).toBe(false,'isExpanded should be false');
    await expect(await $(treeListItem.headerContentExpandToggleWrapper)).
      toBeDisplayedInViewport({message:'Tree-list-item headerContentExpandToggleWrapper is not visible on page' });
    await expect(await $(treeListItem.headerContentExpandToggle)).toBeDisplayedInViewport({message:'Tree-list-item headerContentExpandToggle is not visible on page'});
    await (await $(treeListItem.expandToggleIcon)).click()
    await expect(await treeListItem.isExpanded()).toBe(true,'isExpanded should be true');
    await expect(await treeListItem.isHeaderContentExpanded()).toBe(true,'isHeaderContentExpanded should be true');
    await (await $(treeListItem.expandToggleIcon)).click()
    let treeListItem2 = page.treeListItemByIndex(2);
    await expect(await $(treeListItem2.rightContentPlaceholder)).
      toExist({message:'Tree-list-item headerContentrightContentPlaceholder is not existing on page'});
  });
  it('should verify the <tree-list-item> CO elements', async () => {
    browser.addTestMeta({zephyrStep: "354196"});
    let sectionId = 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    let treeListItem = page.treeListItemByIndex(1);
    await expect(await $(treeListItem.header)).toBeDisplayedInViewport({message:'Tree-list-item header is not visible on page'});
    await expect(await $(treeListItem.headerContent)).toBeDisplayedInViewport({message:'Tree-list-item headerContent is not visible on page'});
    await expect(await $(treeListItem.headerContent)).toBeDisplayedInViewport({message:'Tree-list-item headerContent is not visible on page'});
    await expect(await $(treeListItem.headerContentRightContent)).toBeDisplayedInViewport({message:'Tree-list-item headerContentRightContentPlaceholder is not visible on page'});
  });
  it('should navigate to <Extra content> section to verify customContentPlaceholder, rightContentPlaceholder, customDetailContentPlaceholder', async () => {
    browser.addTestMeta({zephyrStep: "319856"});
    let sectionId= 'extra-content-simple';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    let treeListItem = page.treeListItemFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(treeListItem.customContentPlaceholder)).toBeDisplayedInViewport({message:'Tree-list-item customContentPlaceholder is not visible on page'});
    await expect(await $(treeListItem.rightContentPlaceholder)).toBeDisplayedInViewport({message:'Tree-list-item rightContentPlaceholder is not visible on page'});
    await expect(await treeListItem.hasCustomContent()).toBe(true,'hasCustomContent should be true');

    sectionId= 'extra-content-advanced';
    scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    treeListItem = page.treeListItemFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(treeListItem.customDetailContentPlaceholder)).
      toBeDisplayedInViewport({message:'Tree-list-item customDetailContentPlaceholder is not visible on page'});
  });
  it('should check headerContentExpandToggle and isHeaderContentExpanded methods', async () => {
    browser.addTestMeta({zephyrStep: "389466"});
    let sectionId= 'Default';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    let treeListItem = page.treeListItemByIndex(1);
    await expect(await $(treeListItem.headerContentExpandToggleWrapper)).
      toBeDisplayedInViewport({message:'Tree-list-item headerContentExpandToggleWrapper is not visible on page' });
    await expect(await $(treeListItem.headerContentExpandToggle)).
    toBeDisplayedInViewport({message:'Tree-list-item headerContentExpandToggle is not visible on page'});
    await expect(await treeListItem.isHeaderContentExpanded()).toBe(false,'isHeaderContentExpanded should be false');
    await (await $(treeListItem.expandToggleIcon)).click()
    await expect(await treeListItem.isHeaderContentExpanded()).toBe(true,'isHeaderContentExpanded should be true');
  });
  it('should check hasCustomDetailContent, hasCustomSubContainerContentPlaceholder, isHidden  methods', async () => {
    browser.addTestMeta({zephyrStep: "389467"});
    let sectionId= 'extra-content-advanced';
    let scrollIntoSection = await $(page.sectionById(sectionId));
    await scrollIntoSection.scrollIntoView();

    let treeListItem = page.treeListItemFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(treeListItem.customDetailContentPlaceholder)).
      toBeDisplayedInViewport({message:'Tree-list-item customDetailContentPlaceholder is not visible on page' });
    await expect(await treeListItem.hasCustomDetailContent()).toBe(true,'hasCustomDetailContent should be true');
    await expect(await treeListItem.hasCustomSubContainerContentPlaceholder()).toBe(false,'hasCustomSubContainerContentPlaceholder should be false');
    await expect(await treeListItem.isHidden()).toBe(false,'isHidden should be false');
    await expect(await treeListItem.hasCustomSubLabel()).toBe(true,'hasCustomSubLabel should be true');
  });
});


