/**
 * This class requires the module {@link module../../pages/eui/14x/eui-base.po.js}.
  * @requires ../../pages/eui/14x/eui-base.po.js
 */
import EuiBasePage from "../../pages/eui/14x/eui-base.po.js"

  /**
   * Base action class with general(repeating) methods.
   * The class is used in tests.
   */
export default class BaseActions {
   /**
   * This method verify if section exists, scrolls to section and checks section visibility.
   * @async
   * @param {string} sectionId - Section name eg : Default
   * @param {string} pageName - Page name eg : eui-alert
   */
  static async verifySection(sectionId, pageName) {
    let page = new EuiBasePage();
    let sectionElement = await $(page.sectionById(sectionId));
    await expect(sectionElement).toExist('<' + pageName + '> section with id: ' + sectionId + ' does not exist on page');
    await sectionElement.scrollIntoView();
    await expect(sectionElement).toBeDisplayedInViewport({message:'<' + pageName + '> section with id: ' + sectionId + ' is not visible on page'});
  }
   /**
   * This method verify page title exists, scrolls to page title, checks page title visibility
   * and verify page title to have expected text.
   * @async
   * @param {string} sectionId - Section name eg : Default
   * @param {string} pageName - Page name eg : eui-alert
   */
  static async verifyPageTitle(pageTitle, pageIdExists=true){
    let page = new EuiBasePage();
    let pgTitle = await $(page.pageTitle);
    await expect(pgTitle).toExist('<' + pageTitle + '> page title does not exist on page');
    await pgTitle.scrollIntoView();
    await expect(pgTitle).toBeDisplayedInViewport({message:'<' + pageTitle + '> page title is not visible on page'});
    if(pageIdExists) {
      await expect(await $(page.appDocPageById(pageTitle))).toExist({ message: 'Page Id is existing on page' });
    } else {
      await expect(await $(page.appDocPageById(pageTitle))).not.toExist({message:'Page Id is existing on page'});
    }
    await expect(pgTitle).toHaveText(pageTitle, { wait: 1000, message: 'Page title text is not as expected' });
  }
}
