import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import ToolbarFilterPage from '../../../../pages/eui/10x/ux/ux-a-toolbar-filter-10x.po.js'
import SwitchPage from '../../../../pages/eui/10x/ux/ux-switch.po.js.10x.js'

describe('eUI - <ux-a-toolbar-filter> Component Object @CCQA-558', async() => {
  let toolbarFilterPage = new ToolbarFilterPage();
  let switchPage = new SwitchPage();

  it('should navigate to <ux-a-toolbar-filter> component',async() => {
    browser.addTestMeta({uuid:"57fc5399-b47b-4f65-b52a-ebfa8d1e3e62", zephyrKey: "CCQA-558", zephyrStep: "319457", reportGroups: ["eUI.10x.ux"]});
    await toolbarFilterPage.open(Routing.getUxComponentUrl('ux-a-toolbar-filter'));
    await CookieBannerActions.cookieBanner(true);
    let pgTitle = await $(toolbarFilterPage.pageTitle);
    let appDocPageId = await $(toolbarFilterPage.appDocPageById('ux-a-toolbar-filter'));
    let navigationList = await $(toolbarFilterPage.navigationList);
    await pgTitle.scrollIntoView();
    await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-a-toolbar-filter> page title is not visible on page'});
    await expect(await pgTitle.getText()).toBe('ux-a-toolbar-filter', '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 all section titles of the component object', async() => {
    browser.addTestMeta({zephyrStep: "319458"});
    let docSampleDefault = await $(toolbarFilterPage.sectionById('Default'));
    let docSampleCustom = await $(toolbarFilterPage.sectionById('custom-labels'));
    let docSampleBlank = await $(toolbarFilterPage.sectionById('expandAllLabel-collapseAllLabel-blank'));
    let docSampleUxToolbar = await $(toolbarFilterPage.sectionById('content-uxToolbarFilterButtons'));
    let docSampleIsFilter = await $(toolbarFilterPage.sectionById('isFilterVisible'));

    await expect(await docSampleDefault.isExisting()).toBe(true);
    await expect(await docSampleCustom.isExisting()).toBe(true);
    await expect(await docSampleBlank.isExisting()).toBe(true);
    await expect(await docSampleUxToolbar.isExisting()).toBe(true);
    await expect(await docSampleIsFilter.isExisting()).toBe(true);
  });

  it('should verify the presence of all the Component Object on the page', async() => {
    browser.addTestMeta({zephyrStep: "319460"});
    for(var i = 1; i <= await $(toolbarFilterPage.toolbarFilterCO.toolbarFilter).length; i++) {
      let searchField = await $(toolbarFilterPage.toolbarFilterByIndex(i).inputGroupFilterInput);
      let serchIcon = await $(toolbarFilterPage.toolbarFilterByIndex(i).inputGroupPrependIcon);
      let triggerButton = await $(toolbarFilterPage.toolbarFilterByIndex(i).toolbarFilterTriggerButton);
      let triggerIcon = await $(toolbarFilterPage.toolbarFilterByIndex(i).toolbarFilterTriggerButtonIcon);

      //typing 'test' in toolbar element filter
      searchField.setValue('test');
      //checking if input field  element exists
     await expect(searchField.isExisting()).toBe(true);
      //checking if search icon element exists
     await expect(serchIcon.isExisting()).toBe(true);
      //checking if trigger button element exists
     await expect(triggerButton.isExisting()).toBe(true);
      //checking if trigger icon element exists
     await expect(triggerIcon.isExisting()).toBe(true);
    }
  });

  it('should verify all toolbar filter buttons are clicked', async() => {
    browser.addTestMeta({zephyrStep: "377954"});
    for(var i = 1; i <= await $(toolbarFilterPage.toolbarFilterCO.toolbarFilterTriggerButton).length; i++) {
      browser.execute("arguments[0].click();" , await $(toolbarFilterPage.toolbarFilterByIndex(i).toolbarFilterTriggerButton));
     await expect(toolbarFilterPage.toolbarFilterByIndex(i).isToggleExpanded).toBe(true);
    }
  });

  it('should verify the Component Object <isFilterVisible> and <isChecked> methods are working', async() => {
    browser.addTestMeta({zephyrStep: "319461"});
    let isToolbarFilterVisible = toolbarFilterPage.toolbarFilterByIndex(6);
    await expect(await isToolbarFilterVisible.isFilterVisible()).toBe(false);
    let switch1 = switchPage.switchFromSectionWithIdByIndex('isFilterVisible', '1');
    await expect(await switch1.isChecked()).toBe(false);
    await (await $(switch1.currentPath)).click();
    await expect(await switch1.isChecked()).toBe(true);
    await expect(await isToolbarFilterVisible.isFilterVisible()).toBe(true);
  });
});
