|
| 1 | +import { getExecutionContext } from '../-private/execution_context'; |
| 2 | +import { filterWhitelistedOption } from "../-private/helpers"; |
| 3 | + |
| 4 | +/** |
| 5 | + * @public |
| 6 | + * |
| 7 | + * Returns a element |
| 8 | + * |
| 9 | + * @example |
| 10 | + * |
| 11 | + * import { findOne } from 'ember-cli-page-object'; |
| 12 | + * |
| 13 | + * export default function isDisabled(selector, options = {}) { |
| 14 | + * return { |
| 15 | + * isDescriptor: true, |
| 16 | + * |
| 17 | + * get() { |
| 18 | + * return findOne(this, selector, options).disabled; |
| 19 | + * } |
| 20 | + * }; |
| 21 | + * } |
| 22 | + * |
| 23 | + * @param {Ceibo} pageObjectNode - Node of the tree |
| 24 | + * @param {string} targetSelector - Specific CSS selector |
| 25 | + * @param {Object} options - Additional options |
| 26 | + * @param {boolean} options.resetScope - Do not use inherited scope |
| 27 | + * @param {string} options.contains - Filter by using :contains('foo') pseudo-class |
| 28 | + * @param {string} options.scope |
| 29 | + * @param {number} options.at - Filter by index using :eq(x) pseudo-class |
| 30 | + * @param {boolean} options.last - Filter by using :last pseudo-class |
| 31 | + * @param {boolean} options.visible - Filter by using :visible pseudo-class |
| 32 | + * @param {string} options.testContainer - Context where to search elements in the DOM |
| 33 | + * @param {string} options.pageObjectKey - Used in the error message when the element is not found |
| 34 | + * @return {Element} |
| 35 | + * |
| 36 | + * @throws If no elements found |
| 37 | + * @throws If more than one element found |
| 38 | + */ |
| 39 | +export function findOne(pageObjectNode, targetSelector, options = {}) { |
| 40 | + const filteredOptions = filterWhitelistedOption(options, [ |
| 41 | + 'resetScope', 'visible', 'testContainer', 'contains', 'at', 'last', 'scope', 'pageObjectKey' |
| 42 | + ]); |
| 43 | + const opts = Object.assign({}, filteredOptions, { multiple: false }); |
| 44 | + return getExecutionContext(pageObjectNode).findWithAssert(targetSelector, opts).get(0); |
| 45 | +} |
0 commit comments