aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/e2e/src/utils/elements.ts
blob: d9435e52052305eb6782542a8b08705c9f9a9462 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
async function getCheckbox (name: string) {
  const input = $(`my-peertube-checkbox input[id=${name}]`)
  await input.waitForExist()

  return input.parentElement()
}

function isCheckboxSelected (name: string) {
  return $(`input[id=${name}]`).isSelected()
}

async function selectCustomSelect (id: string, valueLabel: string) {
  const wrapper = $(`[formcontrolname=${id}] .ng-arrow-wrapper`)

  await wrapper.waitForClickable()
  await wrapper.click()

  const option = await $$(`[formcontrolname=${id}] .ng-option`).filter(async o => {
    const text = await o.getText()

    return text.trimStart().startsWith(valueLabel)
  }).then(options => options[0])

  await option.waitForDisplayed()

  return option.click()
}

async function findParentElement (
  el: WebdriverIO.Element,
  finder: (el: WebdriverIO.Element) => Promise<boolean>
) {
  if (await finder(el) === true) return el

  return findParentElement(await el.parentElement(), finder)
}

export {
  getCheckbox,
  isCheckboxSelected,
  selectCustomSelect,
  findParentElement
}