import Routing from '../../../../pages/eui/10x/routing-10x.js'
import CookieBannerActions from '../../../../actions/cookieBanner.js'
import FieldSearchPage from '../../../../pages/eui/10x/ux/ux-field-search-10x.po.js'

describe('should navigate to  <ux-field-search> Component Object ', async () => {
  let page = new FieldSearchPage();
  it('should navigate to <ux-field-search> component', async () => {
   browser.addTestMeta({uuid:"0b6748da-96e6-11eb-a8b3-0242ac130003", zephyrKey: "CCQA-631", zephyrStep: "338042", reportGroups: ["eUI.10x.ux"]});
   await page.open(Routing.getUxComponentUrl('ux-field-search'));
   await CookieBannerActions.cookieBanner(true);
   let pgTitle = await $(page.pageTitle);
   let appDocPageId = await $(page.appDocPageById('ux-field-search'));
   let navigationList = await $(page.navigationList);
   await expect(pgTitle).toBeDisplayed({wait:1000, message:'<ux-field-search> page title is not displayed on page'});
   await expect(pgTitle).toHaveText('ux-field-search', {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 verify the presence of <ux-field-search> CO in page',  async () => {
   browser.addTestMeta({zephyrStep: "338044"});
   let sectionId= 'Default';
   let scrollIntoSection = await $(page.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   let search = page.searchByIndex(1);
   await expect(await $(search.dataE2E)).toBeDisplayedInViewport({message:'Field search by index 1 is not displayed on page'});
   await expect(await $(page.searchByTextContains('Search').dataE2E)).toBeDisplayedInViewport({message:'Field search by text "Search" is not displayed on page'});
   await expect(await $(page.searchByTextEqualsAndIndex('Search', 1).dataE2E)).toBeDisplayedInViewport({message:'Field search by text "Search" and index 1 is not displayed on page'});
   await expect(await $$(search.byDefault().dataE2E)).toBeElementsArrayOfSize(22);
  });
  it('should verify CO static elements', async () => {
   browser.addTestMeta({zephyrStep: "338045"});
   let sectionId= 'Default';
   let scrollIntoSection = await $(page.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   let search = page.searchByIndex(1);
   await expect(await $(search.dataE2E)).toBeDisplayedInViewport({message:'Field search by index 1 is not displayed on page'});
   await expect(await $(search.inputGroup)).toBeDisplayedInViewport({message:'Property inputGroup is not displayed on page'});
   await expect(await $(search.inputGroupPrepend)).toBeDisplayedInViewport({message:'Property inputGroupPrepend is not displayed on page'});
   await expect(await $(search.inputGroupText)).toBeDisplayedInViewport({message:'Property inputGroupText is not displayed on page'});
   await expect(await $(search.inputGroupIcon)).toBeDisplayedInViewport({message:'Property inputGroupIcon is not displayed on page'});
   await expect(await $(search.inputWrapper)).toBeDisplayedInViewport({message:'Property inputWrapper is not displayed on page'});
   await expect(await $(search.inputField)).toBeDisplayedInViewport({message:'Property inputField is not displayed on page'});
   sectionId= 'search-filter';
   scrollIntoSection = await $(page.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   search = page.searchFromSectionWithIdByIndex(sectionId,1);
   await expect(await $(search.groupAppend)).toBeDisplayedInViewport({message:'Property groupAppend is not displayed on page'});
   await expect(await search.isDropdownFilter()).toBe(true);
   await expect(await $(search.searchButtonCO.currentPath)).toBeDisplayedInViewport({message:'Property searchButtonCO.currentpath is not displayed on page'});
   await expect(await $(search.searchButtonSpan)).toBeDisplayedInViewport({message:'Property searchButonLabel is not displayed on page'});
   await expect(await $(search.secondaryButtonCO.currentPath)).toBeDisplayedInViewport({message:'Property secondaryButton is not displayed on page'});
   await expect(await search.hasFilterButtonTrigger()).toBe(true);
   sectionId= 'buttons-icons';
   scrollIntoSection = await $(page.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   search = page.searchFromSectionWithIdByIndex(sectionId,1);
   await expect(await $(search.searchButtonIcon)).toBeDisplayedInViewport({message:'Property searchButonAsIcon is not displayed on page'});
   await expect(await search.hasSearchButtonAsIcon()).toBe(true);
  });
  it('should verify CO dropdown list', async () => {
   browser.addTestMeta({zephyrStep: "338046"});

   let sectionId= 'Default';
   let scrollIntoSection = await $(page.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   let search = page.searchFromSectionWithIdByIndex(sectionId,2);
   await (await $(search.inputField)).click();
   await expect(await $(search.inputField)).toHaveAttrContaining('aria-expanded', 'true');
  });
  it('should verify CO input filed clear button',  async () => {
   browser.addTestMeta({zephyrStep: "338159"});

   let sectionId= 'Default';
   let scrollIntoSection = await $(page.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   let search = page.searchByIndex(1);
   await expect(await $(search.dataE2E)).toBeDisplayedInViewport({message:'Field search by index 1 is not displayed on page'});
   await expect(await search.hasData()).toBe(false);
   let inputField = await $(search.inputField);
   await expect(inputField).toBeDisplayedInViewport({message:'Property inputField is not displayed on page'});
   await inputField.setValue(12);
   await expect(await $(search.clearText)).toBeDisplayedInViewport({message:'Property clearText is not displayed on page'});
   await expect(await search.hasData()).toBe(true);
  });
  it('should verify the dropdown button from input field', async () => {
   browser.addTestMeta({zephyrStep: "338161"});

   let sectionId= 'search-filter';
   let scrollIntoSection = await $(page.sectionById(sectionId));
   await scrollIntoSection.scrollIntoView();
   let search = page.searchFromSectionWithIdByIndex(sectionId,1);
   await expect(await search.isDropdownFilter()).toBe(true);
   await expect(await $(search.dropdownButtonCO.currentPath)).toBeDisplayedInViewport({message:'Property dropdownButtonCO is not displayed on page'});
   await expect(await $(search.dropdownButtonCO.currentPath)).toHaveTextContaining('Advanced search');
   await (await $(search.dropdownButtonCO.buttonCO.button)).click();
   await expect(await $(search.dropdownButtonCO.buttonCO.currentPath)).toHaveAttrContaining('aria-expanded', 'true');
  });
});
