Home Manual Reference Source

src/controllers/web/profile.controller.js

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

/**
 * Controller to perform actions accessible from the My Profile Modal
 * @extends BaseController
*/
class ProfileController 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.
   * Creates objects for accessing the Profile Page, Header Panel, and Password
   * Page.
   * @param {args} args Args from client
   */
  constructor(args) {
    super(args);
    this.profilePage = new WebPageObjects.ProfilePage(args);
    this.headerPanel = new WebPageObjects.HeaderPanel(args);
    this.passwordPage = new WebPageObjects.PasswordPage(args);
    this.profileModal = new WebPageObjects.ProfileModal(args);
    this.settingsPage = new WebPageObjects.SettingsPage(args);
  }

  /** Navigates to settings page using availability dropdown */
  async goToSettingsViaHeader() {
    await this.headerPanel.goToSettings();
  }

  /** Navigates to my profile using availability dropdown */
  async goToMyProfileViaHeader() {
    await this.headerPanel.goToMyProfile();
  }

  /** Navigates to settings using settings tab on profile modal */
  async goToSettingsViaModal() {
    await this.goToMyProfileViaHeader();
    await this.profileModal.goToSettings();
  }

  /** Navigates to my profile using my profile tab on profile modal */
  async goToMyProfileViaModal() {
    await this.goToSettingsViaHeader();
    await this.profileModal.goToMyProfile();
  }

  /** Gets all relevant information from profile
   * @returns {Object} containing profile information 
   */
  async getProfileDetails() {
    return await this.profilePage.parseMyProfile();
  }

  /** 
   * Changes username and submits.
   * @param {String} name Desired new username with changes made
   */
  async submitEditUserName(name) {
    await this.profilePage.editNameSubmit(name);
  }

  /** Changes username and cancels.
   * @param {String} name New username with changes made
   */
  async cancelEditUserName(name) {
    await this.profilePage.editNameCancel(name);
  }

  /** Gets username
  * @return {String} containing username
  */
  async getUsername() {
    return await this.profilePage.usernameText();
  }

  /** Opens page to change password, fills in fields, and updates password.
   * @param {String} currentPassword Current password for user
   * @param {String} newPassword Desired new password for user
   * @param {String} confirmPassword Confirmation of new password for user
   */
  async changePassword(currentPassword, newPassword, confirmPassword) {
    await this.profileModal.goToChangePassword();
    await this.passwordPage.changePassword(
      currentPassword,
      newPassword,
      confirmPassword
    );
  }

  /** Changes language of all text to desired language
 * @param {String} newLang Language user desires to change to
 * @return {String} Text that reads 'Select your language' in English to test
 * the language has changed
 */
  async changeLang(newLang) {
    await this.settingsPage.changeLanguage(newLang);
    return this.settingsPage.selectYourLanguageText();
  }

  /**
   * Get extension from change password URL
   * @returns {String} Extension from URL
   */
  async passwordUrlExtension() {
    return await this.profileModal.getExtensionFromPasswordURL();
  }
}

export default ProfileController;