{"size": 1035, "ext": "js", "max_stars_repo_path": "test-e2e/helpers.js", "max_stars_repo_name": "schnogz/ledger-live-desktop", "max_stars_repo_stars_event_min_datetime": "2019-06-25T15:11:00.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-08T12:22:29.000Z", "max_issues_repo_path": "test-e2e/helpers.js", "max_issues_repo_name": "takeratta/ledger-live-desktop", "max_issues_repo_issues_event_min_datetime": "2022-03-25T19:18:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T19:18:37.000Z", "max_forks_repo_path": "test-e2e/helpers.js", "max_forks_repo_name": "takeratta/ledger-live-desktop", "max_forks_repo_forks_event_min_datetime": "2019-12-31T21:55:11.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-25T01:06:16.000Z"}
{"max_stars_count": 2, "max_issues_count": 1, "max_forks_count": 2, "avg_line_length": 25.243902439, "max_line_length": 76, "alphanum_fraction": 0.6270531401}
import { delay } from 'helpers/promise'

// Wait for an element to be present then continue
export function waitForExpectedText(app, selector, expected, maxRetry = 5) {
  async function check() {
    if (!maxRetry) {
      throw new Error(`Cant find the element ${selector} in the page`)
    }
    try {
      const str = await app.client.getText(selector)
      if (str === expected) {
        return true
      }
    } catch (err) {} // eslint-disable-line
    await delay(500)
    --maxRetry
    return check()
  }
  return check()
}

// Wait for an element to disappear then continue
export function waitForDisappear(app, selector, maxRetry = 5) {
  async function check() {
    if (!maxRetry) {
      throw new Error('Too many retries for waiting element to disappear')
    }
    try {
      await app.client.getText(selector)
    } catch (err) {
      if (err.message.startsWith('An element could not be located')) {
        return true
      }
    }
    await delay(500)
    --maxRetry
    return check()
  }
  return check()
}
