Skip to content

Commit b456764

Browse files
committed
feat(ui-test-utils): add helpers to get tag, computedStyle
Change-Id: Iae05fa6e4563cba190237230ca40ac0cbbfc1c2b Reviewed-on: https://gerrit.instructure.com/165518 Tested-by: Jenkins Reviewed-by: Stephen Jensen <sejensen@instructure.com> Product-Review: Jennifer Stern <jstern@instructure.com> QA-Review: Jennifer Stern <jstern@instructure.com>
1 parent bbb3a8b commit b456764

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

packages/ui-test-utils/src/utils/helpers.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
import runAxeCheck from '@instructure/ui-axe-check'
2525
import { fireEvent, prettyDOM } from 'dom-testing-library'
2626

27+
function getOwnerDocument (element) {
28+
return element.ownerDocument
29+
}
30+
31+
function getOwnerWindow (element) {
32+
const doc = getOwnerDocument(element)
33+
return doc.defaultView || doc.parentWindow
34+
}
35+
2736
function typeIn (element, value) {
2837
element.value = value // eslint-disable-line no-param-reassign
2938
fireEvent(element, new Event('change', {
@@ -33,10 +42,18 @@ function typeIn (element, value) {
3342
}))
3443
}
3544

36-
function text (element) {
45+
function getTextContent (element) {
3746
return element.textContent
3847
}
3948

49+
function getTagName (element) {
50+
return element.tagName.toLowerCase()
51+
}
52+
53+
function getComputedStyle (element) {
54+
return getOwnerWindow(element).getComputedStyle(element)
55+
}
56+
4057
function visible (element) {
4158
return !!( element.offsetWidth || element.offsetHeight || element.getClientRects().length )
4259
}
@@ -45,12 +62,12 @@ function getAttribute (element, ...args) {
4562
return element.getAttribute(...args)
4663
}
4764

48-
function parent (element) {
65+
function getParentNode (element) {
4966
return element.parentNode
5067
}
5168

5269
function focused (element) {
53-
return (element === element.ownerDocument.activeElement)
70+
return (element === getOwnerDocument(element).activeElement)
5471
}
5572

5673
function getDOMNode (element) {
@@ -70,13 +87,29 @@ async function accessible (element = document.documentElement, options) {
7087
}
7188
}
7289

90+
// aliases
91+
const parent = getParentNode
92+
const text = getTextContent
93+
const tag = getTagName
94+
const computedStyle = getComputedStyle
95+
const attribute = getAttribute
96+
7397
export {
98+
getOwnerWindow,
99+
getOwnerDocument,
100+
computedStyle,
101+
getComputedStyle,
102+
tag,
103+
getTagName,
74104
typeIn,
105+
attribute,
75106
getAttribute,
76107
getDOMNode,
77108
debug,
78109
accessible,
110+
getTextContent,
79111
text,
112+
getParentNode,
80113
parent,
81114
focused,
82115
visible

0 commit comments

Comments
 (0)