File size: 1,148 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
/// <reference types="cypress" />

/**
 * @method abGetProperty
 * @description
 * ### Usage
 *
 * ```javascript
 * // your property in AdminJS
 * resourceOptions: {
 *   properties: {
 *     isAdmin: {...}
 *   }
 * }
 * ```
 *
 * ```javascript
 * // accessing it in test.
 * cy.abGetProperty('isAdmin', 'input[type="checkbox"]')
 * ```
 *
 * `abGetProperty` returns the wrapper Section for a given property. You can pass inner element
 * which allows you to select `input`, `label`, `options`, etc. inside it.
 *
 * @memberof module:cy
 * @param {string} path           path of the property
 * @param {string} [selector=null]
 * @example
 * it('shows disabled checkBox', () => {
 *   cy.abGetProperty('isAdmin', 'input[type="checkbox"]')
 *     .should('be.disabled')
 *     .should('not.be.checked')
 *
 *   cy.abGetProperty('isAdmin', 'label')
 *     .click()
 *     .should('not.be.checked')
 * })
 */
Cypress.Commands.add('abGetProperty', (path, selector = null) => {
  let propertySelector = `[data-testid$="-${path}"]`
  if (selector) {
    propertySelector = [propertySelector, selector].join(' ')
  }
  return cy.get(propertySelector)
})