Home Manual Reference Source

src/controllers/web/activity.controller.js

import * as WebPageObjects from "../../page_objects/web/webPageObjects.js";
import BaseController from "./base.controller.js";

/**
 * @class ActivityController
 * @extends BaseController
 */
class ActivityController extends BaseController {
  /**
   * Adds the browser to the controller from the Base Controller constructor.
   * This then gets pushed into the various page objects
   * and is ultimately used there to make calls to the actual browser.
   * @param {args} args Args from client
   */
  constructor(args) {
    super(args);
    this.activityPanel = new WebPageObjects.ActivityPanel(args);
  }

  /**
   * Gets information for the most recent call in the recents list
   * @returns {Object} Object containing the caller/callee name, the time the
   * call occurred, and the status(incoming, outgoing, or missed) of the call
   * @example client.activityController.getMostRecentCall()
   * @example
   * // Returns...
   * {
   * name: 'John Doe',
   * time: '4m',
   * status: 'outgoing'
   * }
   */
  async getMostRecentCall() {
    await this.browser.pause(5000);
    const firstRecentCall = await this.activityPanel
      .recentActivityItems()
      .first();
    const text = await firstRecentCall.getText();
    const splitText = text.split("\n");

    const statusIcon = await firstRecentCall.element(
      "i[class^='icon icon-call']"
    );
    const statusClass = await statusIcon.getAttribute("class");
    const status = statusClass.match(/icon icon-call-(.+)/)[1];

    return { name: splitText[0], time: splitText[1], status };
  }

  /**
   * Deletes most recent call from the list of recents in the activity panel.
   */
  async deleteMostRecent() {
    const firstRecentCall = await this.activityPanel
      .recentActivityItems()
      .first();
    await firstRecentCall.hover();
    const removeRecent = await firstRecentCall.element(
      "button[class^='icon icon-cancel components-ActivityFeed-ActivityFeedListItem__removeButton']" // eslint-disable-line max-len
    );
    await removeRecent.click();
    await this.browser.pause(500);
  }

  /**
   * Deletes all recent calls from the list of recents in the activity panel
   */
  async deleteAllRecents() {
    await this.browser.waitUntil(async () => {
      if (await this.activityPanel.emptyRecentsMessage().isVisible()) {
        return true;
      } else {
        await this.deleteMostRecent();
        return false;
      }
    }, 180000);
  }

  /**
   * Determines if the recents list in the activity panel is empty via the
   * presence of the default empty message.
   * @returns {Boolean} true if recents is empty, false if not
   */
  async recentsIsEmpty() {
    if (await this.activityPanel.emptyRecentsMessage().isVisible()) {
      return true;
    }
    return false;
  }
}

export default ActivityController;