import Routing from '../../../../pages/eui/10x/routing-10x.js';
import CookieBannerActions from '../../../../actions/cookieBanner.js';
import UxSplitButtonPage from '../../../../pages/eui/10x/ux/ux-split-button-10x.po.js';

describe('eUI - <ux-split-button> Component Object', async () => {
  let page = new UxSplitButtonPage();
  it('should navigate to <ux-split-button> component', async () => {
    browser.addTestMeta({uuid:"890e0931-9d91-471d-bfc7-db4931849047", zephyrKey: "CCQA-1068", zephyrStep: "400606", reportGroups: ["eUI.10x.ux"]});
    await page.open(Routing.getUxComponentUrl('ux-split-button'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(page.pageTitle);
    let appDocPageId = await $(page.appDocPageById('ux-split-button'));
    let navigationList = await $(page.navigationList);
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-split-button> page title is not visible on page'});
    await expect(pgTitle).toHaveText('ux-split-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 visible on page'});
  });
  it('should verify the presence of the Component Object on the page', async () => {
    browser.addTestMeta({zephyrStep: "400607"});

    let sectionId = 'Default';
    let section = await $(page.sectionById(sectionId));
    await section.scrollIntoView();

    await expect(await $(page.splitButtonFromSectionById('Default').currentPath)).toBeExisting({timeout: 5000,
      timeoutMsg: '<Default> section -> is not existing on page', interval: 100
    });
    let splitBtn = page.splitButtonByIndex(1);
    await expect(await $(splitBtn.dataE2E)).toBeExisting({ timeout: 1000,  timeoutMsg:
      'ux-split-button by index "1" is not existing on page', interval: 100 });
    await expect(await splitBtn.defaultComponentsCount()).toBe(16, 'There should be 16 <ux-split-button> components on the page.');
  });
  it('should verify the component elements', async () => {
    browser.addTestMeta({zephyrStep: "400608"});

    let sectionId = 'Default';
    let splitBtn = page.splitButtonFromSectionById(sectionId);
    await expect(await $(splitBtn.currentPath)).toBeDisplayed({message:'SplitButton component not present on page.'});
    await expect(await $(splitBtn.buttonCo.currentPath)).toBeDisplayed({message:'SplitButton - button subcomponent not present on page.'});
    await expect(await $(splitBtn.dropDownButtonCo.currentPath)).toBeDisplayed({message:
      'SplitButton - dropdownbutton subcomponent not present on page.'});

    let btnLabel = await (await splitBtn.buttonCo.element());
    await expect(btnLabel).toHaveText('main button label', {wait: 1000, message: 'Button label is not as expected'});

    let dropDownBtn = splitBtn.dropDownButtonCo.buttonCO.button;
    await expect(await $(dropDownBtn)).toBeExisting({message:'SplitButton - dropdown btn button not present on page.'});
    await (await $(dropDownBtn)).click();
    await expect(await $(splitBtn.dropDownButtonCo.matMenuCO.currentPath)).toBeDisplayed({message:
      'SplitButton - context matMenuCO is not existing on page'});
    await expect(await (await page.dropdownButtonItemByTextContains('link 1').element())).toBeDisplayed({message:
      'SplitButton - dropdown item with label "link 1" from contextual menu is not visible on page'});
    await expect(await (await page.dropdownButtonItemByTextContains('link 2').element())).toBeDisplayed({message:
      'SplitButton - dropdown item with label "link 2" from contextual menu is not visible on page'});

    let dropdownBtnItm4 = await (await page.dropdownButtonItemByTextContains('link 4').element());
    await expect(dropdownBtnItm4).toBeDisplayed({message:
      'SplitButton - dropdown item with label "link 2" from contextual menu is not visible on page'});
      await dropdownBtnItm4.click();
    await expect(await $(splitBtn.dropDownButtonCo.matMenuCO.currentPath)).not.toBeDisplayed({message:
      'SplitButton - context matMenuCO is still displayed on page'});
  });
  it('should verify if the component isOutline', async () => {
    browser.addTestMeta({zephyrStep: "400609"});

    let sectionId = 'isOutline';
    let section = await $(page.sectionById(sectionId));
    await section.scrollIntoView();

    let splitBtn = page.splitButtonFromSectionById(sectionId);
    await expect(await $(splitBtn.currentPath)).toBeDisplayed({message:'SplitButton component not present on page.'});
    await expect(await $(splitBtn.buttonCo.currentPath)).toBeDisplayed({message:'SplitButton - button subcomponent not present on page.'});
    await expect(await splitBtn.isOutline()).toBe(true, 'SplitButton - is not Outline.');

  });
  it('should verify the component typeClass', async () => {
    browser.addTestMeta({zephyrStep: "400610"});

    let sectionId = 'typeClass';
    let section = await $(page.sectionById(sectionId));
    await section.scrollIntoView();

    let splitBtn = page.splitButtonFromSectionById(sectionId);
    await expect(await $(splitBtn.currentPath)).toBeDisplayed({message:'SplitButton component not present on page.'});
    await expect(await page.splitButtonFromSectionByIdAndIndex(sectionId,1).typeClass()).toBe('primary');
    await expect(await page.splitButtonFromSectionByIdAndIndex(sectionId,2).typeClass()).toBe('info');
    await expect(await page.splitButtonFromSectionByIdAndIndex(sectionId,3).typeClass()).toBe('success');
    await expect(await page.splitButtonFromSectionByIdAndIndex(sectionId,4).typeClass()).toBe('warning');
    await expect(await page.splitButtonFromSectionByIdAndIndex(sectionId,5).typeClass()).toBe('danger');
  });
  it('should verify the component isOutline and typeClass', async () => {
    browser.addTestMeta({zephyrStep: "400611"});

    let sectionId = 'typeClass-isOutline';
    let section = await $(page.sectionById(sectionId));
    await section.scrollIntoView();

    let splitBtn = page.splitButtonFromSectionByIdAndIndex(sectionId, 1);
    await expect(await $(splitBtn.currentPath)).toBeDisplayed({message:'SplitButton component not present on page.'});
    await expect(await splitBtn.typeClass()).toBe('primary');
    await expect(await splitBtn.isOutline()).toBe(true, 'SplitButton - is not Outline.');

  });
  it('should verify a component on a modal dialog', async () => {
    browser.addTestMeta({zephyrStep: "400612"});

    let sectionId = 'content-panel-right-content';
    let section = await $(page.sectionById(sectionId));
    await section.scrollIntoView();

    let splitBtn = page.splitButtonFromSectionByIdAndIndex(sectionId, 1);
    await expect(await $(splitBtn.currentPath)).toBeDisplayed({message:'SplitButton component not present on page.'});

    let dropDownBtn = splitBtn.dropDownButtonCo.buttonCO.button;
    await expect(await $(dropDownBtn)).toBeExisting({message:'SplitButton - dropdown btn button not present on page.'});
    await (await $(dropDownBtn)).click();
    await expect(await $(splitBtn.dropDownButtonCo.matMenuCO.currentPath)).toBeDisplayed({message:
      'SplitButton - context matMenuCO is not existing on page'});

    let dropdownItem5 = await (await page.dropdownButtonItemByTextContains('link 5').element());
    await expect(dropdownItem5).toBeDisplayed({message:'SplitButton - dropdown item with label "link 1" from contextual menu is not visible on page'});
    await dropdownItem5.click();

    // check the ux-split-button from the modal dialog
    let modal = page.modalCoBySectionId(sectionId).byAttributeEquals('id','ux-split-button-modal');
    await expect(await $(modal.content)).toBeDisplayed({message:'SplitButton - modal dialog is not present on page.'});

    let splitBtnModal = page.splitButtonInsideModalBySection(sectionId);
    let dropDownBtnModal = splitBtnModal.dropDownButtonCo.buttonCO.button;
    await expect(await $(dropDownBtnModal)).toBeExisting({message:'SplitButton - dropdown btn button not present on page.'});
    await (await $(dropDownBtnModal)).scrollIntoView();
    await expect(await $(dropDownBtnModal)).toBeDisplayed({message:'SplitButton - dropdown btn button not present on page.'});
    await (await $(dropDownBtnModal)).click();

    let contextMenu = await $(splitBtnModal.dropDownButtonCo.matMenuCO.currentPath);
    await expect(contextMenu).toBeExisting({message: 'SplitButton - context matMenuCO is not existing on page'});
    let dropdownBtnItm1 = await (await page.dropdownButtonItemByTextContains('link 1').element());
    await expect(dropdownBtnItm1).toBeDisplayed({message:'SplitButton - dropdown item with label "link 1" from contextual menu is not visible on page'});
    await dropdownBtnItm1.click();
    await expect(contextMenu).not.toBeDisplayed({message: 'SplitButton - context matMenuCO is still displayed on page'});

    let closeBtn = await $(modal.closeBtn);
    await expect(closeBtn).toBeDisplayed({message:'SplitButton - modal dialog close btn is not present on page.'});
    await closeBtn.click();
    await expect(await $(modal.content)).not.toBeDisplayed({message:'SplitButton - modal dialog is still present on page.'});
  });
});
