import { By, Key } from 'selenium-webdriver';
import { OjButtonBase } from './OjButtonBase';

/**
 * The component WebElement for [oj-button](../../jsdocs/oj.ojButton.html).
 * Do not instantiate this class directly, instead, use
 * [ojButton](../functions/elements.ojButton-1.html).
 */
export class OjButton extends OjButtonBase {
  /**
   * Perform a click on the button
   */
  doAction() {
    return this.click();
  }

  /**
   * Perform a context-click on the button
   */
  async doContextClick() {
    let button = await this.findElement(By.css('button'));
    await button.sendKeys(Key.SHIFT, Key.F10);
  }

  /**
   * Perform a click on the button
   */
  async click() {
    // Find the <button> element to click so that it can receive focus
    const button = await this.findElement(By.css('button'));
    return button.click();
  }
}
