{"size": 740, "ext": "js", "max_stars_repo_path": "src/platform/testing/e2e/nightwatch-commands/clickIf.js", "max_stars_repo_name": "bkjohnson/vets-website-content-build", "max_stars_repo_stars_event_min_datetime": "2020-04-03T14:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-03T14:22:47.000Z", "max_issues_repo_path": "src/platform/testing/e2e/nightwatch-commands/clickIf.js", "max_issues_repo_name": "bkjohnson/vets-website-content-build", "max_issues_repo_issues_event_min_datetime": "2021-04-08T19:02:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-20T15:04:36.000Z", "max_forks_repo_path": "src/platform/testing/e2e/nightwatch-commands/clickIf.js", "max_forks_repo_name": "bkjohnson/vets-website-content-build", "max_forks_repo_forks_event_min_datetime": "2018-09-26T12:02:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-09-26T12:02:49.000Z"}
{"max_stars_count": 1, "max_issues_count": 126, "max_forks_count": 1, "avg_line_length": 29.6, "max_line_length": 69, "alphanum_fraction": 0.6797297297}
/**
 * Clicks the input specified if the condition evaluates to true.
 *
 * @param {string} selector The css selector for the element to click
 * @param {function} condition Function that will be run to determine
 * whether or not to click the element
 * @param {...any} params Parameters that will be passed to condition
 */
exports.command = function clickIf(selector, condition, ...params) {
  let shouldClick = !!condition;
  if (typeof condition === 'function') {
    shouldClick = !!condition(...params);
  }

  if (shouldClick) {
    this.click(selector);
  } else {
    // Needs to call some nightwatch function anyhow to queue this
    // http://nightwatchjs.org/guide/#extending
    this.perform(() => {});
  }

  return this;
};
