-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1446 from bendemboski/dom-element-descriptors
Support passing IDOMElementDescriptors as targets
- Loading branch information
Showing
32 changed files
with
656 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
addon/addon-test-support/@ember/test-helpers/dom/-get-description.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { isDescriptor, lookupDescriptorData } from 'dom-element-descriptors'; | ||
import type Target from './-target'; | ||
|
||
/** | ||
Used internally by the DOM interaction helpers to get a description of a | ||
target for debug/error messaging. | ||
@private | ||
@param {Target} target the target | ||
@returns {string} a description of the target | ||
*/ | ||
export default function getDescription(target: Target): string { | ||
let data = isDescriptor(target) ? lookupDescriptorData(target) : null; | ||
if (data) { | ||
return data.description || '<unknown descriptor>'; | ||
} else { | ||
return `${target}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 19 additions & 2 deletions
21
addon/addon-test-support/@ember/test-helpers/dom/-get-elements.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
import { | ||
type IDOMElementDescriptor, | ||
lookupDescriptorData, | ||
resolveDOMElements, | ||
} from 'dom-element-descriptors'; | ||
import getRootElement from './get-root-element'; | ||
|
||
function getElements(target: string): NodeListOf<Element>; | ||
function getElements(target: IDOMElementDescriptor): Iterable<Element>; | ||
function getElements(target: string | IDOMElementDescriptor): Iterable<Element>; | ||
/** | ||
Used internally by the DOM interaction helpers to find multiple elements. | ||
@private | ||
@param {string} target the selector to retrieve | ||
@returns {NodeList} the matched elements | ||
*/ | ||
export default function getElements(target: string): NodeListOf<Element> { | ||
function getElements( | ||
target: string | IDOMElementDescriptor | ||
): NodeListOf<Element> | Iterable<Element> { | ||
if (typeof target === 'string') { | ||
let rootElement = getRootElement(); | ||
|
||
return rootElement.querySelectorAll(target); | ||
} else { | ||
throw new Error('Must use a selector string'); | ||
let descriptorData = lookupDescriptorData(target); | ||
if (descriptorData) { | ||
return resolveDOMElements(descriptorData); | ||
} else { | ||
throw new Error('Must use a selector string or DOM element descriptor'); | ||
} | ||
} | ||
} | ||
|
||
export default getElements; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.