Home Manual Reference Source

src/page_objects/web/contacts/create/base.contactForm.js

// DON'T FORGET TO ADD ME TO WebPageObjects!
import BaseModalPage from "../../general/base.modal.js";

/** 
 * BaseContactFormPage
 * @extends BaseModalPage
 */
class BaseContactFormPage extends BaseModalPage {
  /**
   * @param {args} args Args from controller
   */
  constructor(args) {
    super(args);
    this.favoriteCheckBoxId = "createFavorite";
  }

  // PAGE ELEMENTS
  /* eslint-disable require-jsdoc, max-len */
  nameField() {
    return this.element("input[name=name]");
  }

  nameFieldErrorText() {
    return this.element(
      '//*[@name="name"]/parent::*/descendant::*[contains(@class,"error")]'
    );
  }

  nameFieldErrorExclamation() {
    return this.element(
      '//*[@name="name"]/parent::*/descendant::*[contains(@class,"icon-exclamation")]'
    );
  }

  cancelButton() {
    return this.element("button=Cancel");
  }

  saveButton() {
    return this.element("button=Save");
  }
  /* eslint-enable require-jsdoc, max-len */

  // PAGE FUNCTIONS

  /**
   * Set Name field in contact modal
   * @param  {String}  name Name of contact
   */
  async setNameField(name) {
    await this.nameField().setValue(name);
  }

  /**
   * Returns whether the favorite field in the modal is set
   * @return {Boolean} true or false whether the field is set or not
   */
  async isFavoriteFieldSet() {
    const fieldSet = await this.browser.execute(
      elementId => document.getElementById(elementId).getAttribute("value"), // eslint-disable-line
      this.favoriteCheckBoxId
    );
    return fieldSet.value === "true" ? true : false;
  }

  /**
   * Sets favorite field in create contact modal
   * @param  {Boolean}  favorite true or false to set the favorite field
   */
  async setFavoriteField(favorite) {
    const isFieldSet = await this.isFavoriteFieldSet();

    if (favorite !== isFieldSet) {
      await this.browser.execute(elementId => {
        document.getElementById(elementId).click(); // eslint-disable-line
      }, this.favoriteCheckBoxId);
    }

    await this.browser.pause(1000);
  }

  /**
   * Returns name field error text
   * @return {String} Name field error text
   */
  async getNameFieldErrorText() {
    return await this.nameFieldErrorText().getText();
  }

  /**
   * Returns if saveButtonisEnabled
   * @return {Boolean} whether save button is enabled
   */
  async isSaveButtonEnabled() {
    return await this.saveButton().isEnabled();
  }

  /**
   * Checks to see if name field's error exclamation point is visible
   * @returns {Boolean} True if it is visible
   */
  async isNameFieldErrorExclamationVisible() {
    return await this.nameFieldErrorExclamation().isVisible();
  }

  /**
   * Click the save button
   */
  async clickSaveButton() {
    await this.saveButton().click();
  }

  /**
   * Click the cancel button
   */
  async clickCancelButton() {
    await this.cancelButton().click();
  }

  /**
   * Get the name field limit via the HTML
   * @returns {Integer} Value for namefield's "maxlength" attribute
   */
  async getNameFieldLimit() {
    return await this.nameField().getAttribute("maxlength");
  }
}

export default BaseContactFormPage;