aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/e2e/src/utils/elements.ts
blob: d9435e52052305eb6782542a8b08705c9f9a9462 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11




                                                           

 



                                            
                                                                    



                                                                









                                                                                   

 








                                                            
        
              


                     
 
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
}