import Routing from '../../../pages/eui/14x/routing.js'
import EuiSideBarMenu from '../../../pages/eui/14x/eui-sidebar-menu.po.js'
import * as CookieBannerActions from '../../../actions/cookieBanner.js';
import BaseActions from '../../../actions/V14/base-actions.js';

describe('eUI - <eui-sidebar-menu> Component Object ', async () => {
  let menu = new EuiSideBarMenu();
  let pageName = 'eui-sidebar-menu'
  it('should navigate to <eui-sidebar-menu> demo page', async () => {
    browser.addTestMeta({uuid:"1a146aa8-f5ea-11eb-9a03-0242ac130003", zephyrKey: "CCQA-1529", zephyrStep: "418204", reportGroups: ["eUI.14x.eui"]});
    menu.open(Routing.getEUILayoutComponentUrl('eui-sidebar-menu'));
    await CookieBannerActions.cookieBanner(true);
    await BaseActions.verifyPageTitle(pageName);
    await expect(await $(menu.navigationList)).toBeDisplayedInViewport({wait:3000,message:'Navigation List -> is not displayed on page'});
  });
  it('should verify the presence and number of component objects <eui-sidebar-menu> on page ', async () => {
    browser.addTestMeta({zephyrStep: "418205"});
    let sidebarMenu = menu.sidebarMenuCO.byIndex(1);
    let sidebarMenu1 = await $(sidebarMenu.currentPath);
    await sidebarMenu1.scrollIntoView();
    await expect(sidebarMenu1).toBeDisplayedInViewport({wait:3000,message:'Sidebar menu by index "1" is not displayed on page'});
    await expect(await $(menu.sidebarMenuCO.byTextContains('Module 1').currentPath)).
      toBeDisplayedInViewport({wait:3000,message:'Sidebar menu by text "Module 1" is not displayed on page'});
    await expect(await $(menu.sidebarMenuCO.byTextEqualsAndIndex('Module 1', 1).currentPath)).
      toBeDisplayedInViewport({wait:3000,message:'Sidebar menu by text "Module 1" and index 1 is not displayed on page'});
    await expect(await sidebarMenu.defaultComponentsCount()).toBe(4,'There should be 5 <eui-sidebar-menu> components on the page.');
  });
  it('should verify the methods: container, isCollapsed, content, euiMenuCO, hasFilter ', async () => {
    browser.addTestMeta({zephyrStep: "418206"});
    let sectionId = 'Default';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(menu.sidebarMenuFromSectionById(sectionId).currentPath)).
      toBeDisplayedInViewport({message:'Section ' + sectionId + ' -> is not displayed on page'});
    let sidebarMenu = menu.sidebarMenuFromSectionById(sectionId).byIndex(1);
    await expect(await $(sidebarMenu.container)).toBeDisplayedInViewport({wait:3000,message:'container is not displayed on page'});
    await expect(await sidebarMenu.isCollapsed()).toBe(false);
    await expect(await $(sidebarMenu.content)).toBeDisplayedInViewport({wait:3000,message:'content is not displayed on page'});
    await expect(await $(sidebarMenu.euiMenuCO.currentPath)).toBeDisplayedInViewport({wait:3000,message:'euiMenuCO currentPath is not displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.hasFilter()).toBe(false);
  });
  it('should verify the CoEuiMenu methods: filter, hasFilter, wrapper, filterInput, searchIcon, clearWrapper, hasInputValue ', async () => {
    browser.addTestMeta({zephyrStep: "418207"});
    let sectionId= 'responsive';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(menu.sidebarMenuFromSectionById(sectionId).currentPath)).
      toBeDisplayedInViewport({message:'Section ' + sectionId + ' -> is not displayed on page'});
    let sidebarMenu = menu.sidebarMenuFromSectionById(sectionId).byIndex(1);
    await expect(sidebarMenu.euiMenuCO.filter).not.toBeDisplayedInViewport({wait:3000,message:'filter is displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.hasFilter()).toBe(true);
    await (await $("//label[@for='size-2']")).click();
    await browser.deductedWait(3000);
    await (await $("//label[@for='size-3']")).click();
    await browser.deductedWait(3000);
    await expect(await sidebarMenu.euiMenuCO.hasFilter()).toBe(true);
    await expect(await $(sidebarMenu.euiMenuCO.wrapper)).toBeDisplayedInViewport({wait:3000,message:'wrapper is not displayed on page'});
    await expect(await $(sidebarMenu.euiMenuCO.filterInputCO.currentPath)).toBeDisplayedInViewport({wait:3000,message:'filterInput is not displayed on page'});
    await expect(await $(sidebarMenu.euiMenuCO.searchIconCO.currentPath)).toBeDisplayedInViewport({wait:3000,message:'searchIcon is not displayed on page'});
  });
  it('should verify the CoEuiMenu methods: list, noItems, hasItem, euiMenuItemCO ', async () => {
    browser.addTestMeta({zephyrStep: "418208"});
    let sectionId= 'has-icons';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(menu.sidebarMenuFromSectionById(sectionId).currentPath)).toBeDisplayedInViewport({message:'Section ' + sectionId + ' -> is not displayed on page'});
    let sidebarMenu = menu.sidebarMenuFromSectionById(sectionId).byIndex(1);
    await expect(await $(sidebarMenu.euiMenuCO.listCO.currentPath)).toBeDisplayedInViewport({wait:3000,message:'list is not displayed on page'});
    await expect(await $(sidebarMenu.euiMenuCO.noItems)).not.toBeDisplayedInViewport({wait:3000,message:'noItems is displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.hasItem()).toBe(true);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.currentPath)).toBeDisplayedInViewport({wait:3000,message:'euiMenuItemCO currentPath is not displayed on page'});
  });
  it('should verify the euiMenuItemCO methods: categoryList, isDisabledCategoryList, categoryIcon, hasCategoryIconDefault, hasCategoryIconNone, categoryLabel, categoryItemLabel ', async () => {
    browser.addTestMeta({zephyrStep: "423098"});
    let sectionId = 'responsive';
    await BaseActions.verifySection(sectionId, pageName);
    await (await $("//label[@for='size-1']")).click();
    await browser.deductedWait(5000);
    await expect(await $(menu.sidebarMenuFromSectionById(sectionId).currentPath)).toBeDisplayedInViewport({message:'Section ' + sectionId + ' -> is not displayed on page'});
    let sidebarMenu = menu.sidebarMenuFromSectionById(sectionId).byIndex(1);
    await (await $(sidebarMenu.euiMenuCO.euiMenuItemCO.categoryListItemCO.currentPath)).scrollIntoView();
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.categoryListItemCO.currentPath)).toBeDisplayedInViewport({wait:3000,message:'categoryList is not displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.isDisabledCategoryList()).toBe(false);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.categoryIcon)).not.toBeDisplayedInViewport({wait:3000,message:'categoryIcon is displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.hasCategoryIconDefault()).toBe(false);
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.hasCategoryIconNone()).toBe(true);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.categoryLabel)).toBeDisplayedInViewport({wait:3000,message:'categoryLabel is not displayed on page'});
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.categoryItemLabel)).
    toBeDisplayedInViewport({wait:3000,message:'categoryItemLabel is not displayed on page'});
  });
  it('should verify the euiMenuItemCO methods: list, isExpandedList, link, isLinkDisabled, isLinkActive, linkIcon, hasLinkIconDefault, hasLinkIconNone ', async () => {
    browser.addTestMeta({zephyrStep: "418210"});
    let sectionId= 'responsive';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(menu.sidebarMenuFromSectionById(sectionId).currentPath)).toBeDisplayedInViewport({message:'Section ' + sectionId + ' -> is not displayed on page'});
    let sidebarMenu = menu.sidebarMenuFromSectionById(sectionId).byIndex(1);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.listItem)).toBeDisplayedInViewport({wait:3000,message:'list is not displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.isExpandedList()).toBe(false);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.link)).toBeDisplayedInViewport({wait:3000,message:'link is not displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.isLinkDisabled()).toBe(false);
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.isLinkActive()).toBe(false);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.linkIcon)).toBeDisplayedInViewport({wait:3000,message:'linkIcon is not displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.hasLinkIconDefault()).toBe(false);
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.hasLinkIconNone()).toBe(false);
  });
  it('should verify the euiMenuItemCO methods: linkMarker, hasMarker, linkLabel, isDisabledLinkLabel,  externalLabel, hasUrlExternal ', async () => {
    browser.addTestMeta({zephyrStep: "418211"});
    let sectionId = 'responsive';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(menu.sidebarMenuFromSectionById(sectionId).currentPath)).toBeDisplayedInViewport({message:'Section ' + sectionId + ' -> is not displayed on page'});
    let sidebarMenu = menu.sidebarMenuFromSectionById(sectionId).byIndex(1);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.linkMarker)).not.toBeDisplayedInViewport({wait:3000,message:'linkMarker is displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.hasMarker()).toBe(false);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.linkLabel)).toBeDisplayedInViewport({wait:3000,message:'linkLabel is not displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.isDisabledLinkLabel()).toBe(false);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.itemLabel)).toBeDisplayedInViewport({wait:3000,message:'itemLabel is not displayed on page'});
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.externalLabel)).not.toBeDisplayedInViewport({wait:3000,message:'externalLabel is displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.hasUrlExternal()).toBe(false);

  });
  it('should verify the euiMenuItemCO methods: linkRightContent, euiChipCO, hasTagLabel, tagLabel, hasChildren', async () => {
    browser.addTestMeta({zephyrStep: "418212"});
    let sectionId= 'responsive';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(menu.sidebarMenuFromSectionById(sectionId).currentPath)).toBeDisplayedInViewport({message:'Section ' + sectionId + ' -> is not displayed on page'});
    let sidebarMenu = menu.sidebarMenuFromSectionById(sectionId).byIndex(1);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.linkRightContent)).not.toBeDisplayedInViewport({wait:3000,message:'linkRightContent is displayed on page'});
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.byTextContains('Programming').linkRightContent)).
      toBeDisplayedInViewport({wait:3000,message:'linkRightContent is not displayed on page'});
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.byTextContains('Programming').euiChipCO.currentPath)).not.
      toBeDisplayedInViewport({wait:3000,message:'euiChipCO currentPath is displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.hasTagLabel()).toBe(false);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.byTextContains('Programming').tagLabel)).not.
      toBeDisplayedInViewport({wait:3000,message:'tagLabel is displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.hasChildren()).toBe(true);
  });
  it('should verify the euiMenuItemCO methods: euiButtonToggleCO, icon, isExpandedIcon, angleDownIcon, angleUpIcon ', async () => {
    browser.addTestMeta({zephyrStep: "418213"});
   let sectionId= 'responsive';
   await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(menu.sidebarMenuFromSectionById(sectionId).currentPath)).
      toBeDisplayedInViewport({message:'Section ' + sectionId + ' -> is not displayed on page'});
    let sidebarMenu = menu.sidebarMenuFromSectionById(sectionId).byIndex(1);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.byTextContains('Programming').euiButtonToggleCO.currentPath)).
      toBeDisplayedInViewport({wait:3000,message:'euiButtonToggleCO currentPath is not displayed on page'});
   await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.byTextContains('Programming').icon)).
      toBeDisplayedInViewport({wait:3000,message:'icon is not displayed on page'});
   await expect(await sidebarMenu.euiMenuCO.euiMenuItemCO.isExpandedIcon()).toBe(true);
   await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.byTextContains('Programming').angleDownIcon)).not.
      toBeDisplayedInViewport({wait:3000,message:'angleDownIcon is not displayed on page'});
   await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.byTextContains('Programming').angleUpIcon)).
      toBeDisplayedInViewport({wait:3000,message:'angleUpIcon is displayed on page'});
  });

  it('should verify the CoEuiMenu methods: euiMenuItemCO, isCollapsedMenuItem, hasIconsMenuItem, euiMenuItemSubCO, isCollapsedMenuItemSubmenu, hasIconsMenuItemSubmenu ', async () => {
    browser.addTestMeta({zephyrStep: "418214"});
    let sectionId = 'responsive';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(menu.sidebarMenuFromSectionById(sectionId).currentPath)).
      toBeDisplayedInViewport({message:'Section ' + sectionId + ' -> is not displayed on page'});
    let sidebarMenu = menu.sidebarMenuFromSectionById(sectionId).byIndex(1);
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemCO.currentPath)).toBeDisplayedInViewport({wait:3000,message:'euiMenuItemCO currentPath is not displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.isCollapsedMenuItem()).toBe(false);
    await expect(await sidebarMenu.euiMenuCO.hasIconsMenuItem()).toBe(true);
    await expect(await $(sidebarMenu.euiMenuCO.submenu)).toBeDisplayedInViewport({wait:3000,message:'submenu is not displayed on page'});
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemSubCO.currentPath)).
      toBeDisplayedInViewport({wait:3000,message:'euiMenuItemSubCO currentPath is not displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.isCollapsedMenuItemSubmenu()).toBe(false);
    await expect(await sidebarMenu.euiMenuCO.hasIconsMenuItemSubmenu()).toBe(true);
  });
  it('should verify the CoEuiMenu methods: subSubmenu,  euiMenuItemSubSubCO, hasItem, isCollapsed, hasIcons ', async () => {
    browser.addTestMeta({zephyrStep: "418215"});
    let sectionId = 'responsive';
    await BaseActions.verifySection(sectionId, pageName);
    await expect(await $(menu.sidebarMenuFromSectionById(sectionId).currentPath)).
      toBeDisplayedInViewport({message:'Section ' + sectionId + ' -> is not displayed on page'});
    let sidebarMenu = menu.sidebarMenuFromSectionById(sectionId).byIndex(1);
    await expect(await $(sidebarMenu.euiMenuCO.subSubmenu)).not.toBeDisplayedInViewport({wait:3000,message:'subSubmenu is displayed on page'});
    await expect(await $(sidebarMenu.euiMenuCO.euiMenuItemSubSubCO.currentPath)).not.toBeDisplayedInViewport({wait:3000,message:'euiMenuItemSubCO currentPath is displayed on page'});
    await expect(await sidebarMenu.euiMenuCO.hasItem()).toBe(true);
    await expect(await sidebarMenu.euiMenuCO.isCollapsed()).toBe(false);
    await expect(await sidebarMenu.euiMenuCO.hasIcons()).toBe(true);
  });
})
