import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import DropdownButton from '../../../../pages/eui/10x/ux/ux-dropdown-button-10x.po.js'

describe('eUI - <ux-dropdown-button> Component Object', async () => {
  let dropdownButtonPage = new DropdownButton();
  it('should navigate to <ux-dropdown-button> component', async () => {
    browser.addTestMeta({uuid:"4277b9f8-8189-11eb-8dcd-0242ac130003", zephyrKey: "CCQA-553", zephyrStep: "318735", reportGroups: ["eUI.10x.ux"]});
    await dropdownButtonPage.open(Routing.getUxComponentUrl('ux-dropdown-button'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(dropdownButtonPage.pageTitle);
    let appDocPageId = await $(dropdownButtonPage.appDocPageById('ux-dropdown-button'));
    let navigationList = await $(dropdownButtonPage.navigationList);
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-dropdown-button> page title is not displayed on page'});
    await expect(pgTitle).toHaveText('ux-dropdown-button', {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 displayed on page'});
  });
  it('should identify <ux-dropdown-button> from page after specific methods', async () => {
    browser.addTestMeta({zephyrStep: "318736"});
    let button1 = await $(dropdownButtonPage.dropdownButtonFromSectionById('Default').currentPath);
    let button2 = await $(dropdownButtonPage.dropdownButtonByIndex(1).buttonCO.currentPath);
    let button3 = await $(dropdownButtonPage.dropdownButtonByTextContains('label').buttonCO.currentPath);
    let button4 = await $(dropdownButtonPage.dropdownButtonByTextEqualsAndIndex('label', 1).buttonCO.currentPath);
    await expect(button1).toBeDisplayed({wait: 3000, message:'<Default> section -> is not displayed on page'});
    await expect(button2).toBeDisplayed({wait: 3000, message:'Dropdown button by index "1" is not displayed on page'});
    await expect(button3).toBeDisplayed({wait: 3000, message:'Dropdown button by text "label" is not displayed on page'});
    await expect(button4).toBeDisplayed({wait: 3000, message:'Dropdown button by text "label" and index 1 is not displayed on page'});
    await expect(await (await $$(dropdownButtonPage.dropdownButtonByIndex(1).byDefault().currentPath)).length).toBe(33);

    let sectionId= 'label';
    let buttonData = await $(dropdownButtonPage.dropdownButtonFromSectionById(sectionId).buttonCO.currentPath);
    await buttonData.scrollIntoView();
    let dropdownButton = dropdownButtonPage.dropdownButtonByTextContains('label');
    await expect(await $(dropdownButton.buttonCO.currentPath)).toBeDisplayed({wait: 3000, message:
      'Dropdown button by text "label" is not displayed on page'});
    await expect(await $(dropdownButton.buttonCO.currentPath)).toHaveTextContaining('label', {wait: 1000, message: 'Button text is not as expected'});
    await expect(await dropdownButton.buttonCO.isDisabled()).toBe(false,'isDisabled should be false');

    sectionId= 'disabled';
    dropdownButton = dropdownButtonPage.dropdownButtonFromSectionWithIdByIndex(sectionId,1);
    await expect(await $(dropdownButton.buttonCO.currentPath)).toBeDisplayed({wait: 3000, message:
      'Dropdown button by index "1" and section disabled is not displayed on page'});
    await expect(await dropdownButton.buttonCO.isDisabled()).toBe(true,'isDisabled should be true');
  });
  it('should click a button component and verify the button list', async () => {
    browser.addTestMeta({zephyrStep: "318737"});
    let sectionId= 'label';
    let section = await $(dropdownButtonPage.sectionById(sectionId));
    await section.scrollIntoView();

    let dropdownButton = dropdownButtonPage.dropdownButtonFromSectionById(sectionId).buttonCO.byTextContains('label');
    await expect(await $(dropdownButton.currentPath)).toBeDisplayedInViewport({wait: 3000, message:
      'Dropdown button with label "link 2" from label section is not displayed on page'});
    await (await $(dropdownButton.currentPath)).click();

    let buttonItem = dropdownButtonPage.dropdownButtonFromSectionById(sectionId).dropdownButtonItemCO;
    await expect(await $(buttonItem.byIndex(1).currentPath)).toBeDisplayed({wait: 3000, message:
      'Dropdown button with label "link 1" from label section Matmenu, dropdownButtonItem is not present on page'});
    await expect(await $(await buttonItem.byIndex(1).buttonCO.span())).toHaveTextContaining('link 1', {wait: 1000, message: 'Button text is not as expected'});
    await expect(await buttonItem.byIndex(3).isDisabled()).toBe('true','isDisabled should be true');

    let dropdownButtonItem1 = dropdownButtonPage.dropdownButtonFromSectionById(sectionId).dropdownButtonItemCO.byTextContains('link 1');
    await expect(await $(dropdownButtonItem1.currentPath)).toBeDisplayed({wait: 3000, message:
      'Dropdown button with label "link 1" from label section Matmenu, dropdownButtonItem is not displayed on page'});
    await (await $(dropdownButtonItem1.buttonCO.currentPath)).click();
  });
  it('should verify the presence of <mat-menu> in a button', async () => {
    browser.addTestMeta({zephyrStep: "3187378"});
    let sectionId= 'isDropDownRightAligned';
    let section = await $(dropdownButtonPage.sectionById(sectionId));
    await section.scrollIntoView();

    let dropdownButton = dropdownButtonPage.dropdownButtonFromSectionById(sectionId);
    await (await $(dropdownButton.buttonCO.byIndex(1).currentPath)).click();
    await (await $(dropdownButton.matMenuCO.currentPath)).isExisting({timeout:3000, timeoutMsg:
      'Dropdown button, dropdownMatmenu is not existing on page', interval:100});

    let dropdownButtonItem = dropdownButton.dropdownButtonItemCO.dataE2E;
    await expect(await $(dropdownButtonItem)).toExist({timeout: 3000, message:
      'Dropdown button dataE2E from section: isDropDownRightAligned is not existing on page'});
    let dropdownButtonItem1 = dropdownButton.dropdownButtonItemCO.byTextContains('link 1').buttonCO.currentPath;
    await (await $(dropdownButtonItem1)).click();
  });
  it('should verify the presence of mat-menu in a item from a list', async () => {
    browser.addTestMeta({zephyrStep: "3187379"});
    let sectionId = 'typeClass';
    let section = await $(dropdownButtonPage.sectionById(sectionId));
    await section.scrollIntoView();

    let dropdownButton = dropdownButtonPage.dropdownButtonFromSectionById(sectionId);
    await expect(await $(dropdownButton.buttonCO.byTextContains('info').currentPath)).toBeDisplayed({wait: 3000, message:
      'Dropdown button with label "info"  is not displayed on page'});
    await expect(await dropdownButton.isShowDropdownToggle()).toBe(false,'isShowDropdownToggle should be false');
    await expect(await dropdownButton.isLinkToggle()).toBe(false,'isLinkToggle should be false');
    await (await $(dropdownButton.buttonCO.currentPath)).click();
    await (await $(dropdownButton.matMenuCO.currentPath)).isExisting({timeout:1000, timeoutMsg:
      'Dropdown button with label "info" , matMenuCO is not existing on page', interval:100});
    let dropdownButtonItem1 = dropdownButton.dropdownButtonItemCO.byTextContains('link 1');
    await (await $(dropdownButtonItem1.matMenuCO.currentPath)).isExisting({timeout:1000, timeoutMsg:
      'Dropdown button with label "link 1" from typeClass section Matmenu, dropdownButtonItem is not displayed on page', interval:100});
    await (await $(dropdownButtonItem1.dataE2E)).click();

    sectionId= 'isLinkToggle';
    section = await $(dropdownButtonPage.sectionById(sectionId));
    await section.scrollIntoView();

    let linkToggle = dropdownButtonPage.dropdownButtonFromSectionById(sectionId);
    await expect(await $(linkToggle.showDropdownToggle)).toBeDisplayed({wait: 3000, message:
      'Link toggle  from isLinkToggle section,  showDropdownToggle is not displayed on page'});
    await (await $(linkToggle.dropdownToggleIconButton)).isExisting({timeout:1000, timeoutMsg:
        'Link toggle from isLinkToggle section,  dropdownToggleIconButton is not displayed on page', interval:100});
    await expect(await linkToggle.isShowDropdownToggle()).toBe(true,'isShowDropdownToggle should be true');
    await expect(await linkToggle.isLinkToggle()).toBe(true,'isLinkToggle should be true');
    await expect(await $(linkToggle.dropdownToggleButtonIconLabel)).toHaveTextContaining('label', {wait: 1000, message: 'Button icon label is not as expected'});
  });
});
