@instructure/ui-dom-utils 8.46.2-snapshot-17 → 8.47.1-snapshot-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/es/__new-tests__/addEventListener.test.js +42 -0
- package/es/__new-tests__/addInputModeListener.test.js +52 -0
- package/es/__new-tests__/addPositionChangeListener.test.js +64 -0
- package/es/__new-tests__/addResizeListener.test.js +64 -0
- package/es/__new-tests__/findTabbable.test.js +66 -0
- package/es/__new-tests__/getClassList.test.js +46 -0
- package/es/__new-tests__/getFontSize.test.js +40 -0
- package/es/__new-tests__/getOffsetParents.test.js +107 -0
- package/es/__new-tests__/getScrollParents.test.js +87 -0
- package/es/__new-tests__/isCustomElement.test.js +41 -0
- package/es/__new-tests__/isVisible.test.js +111 -0
- package/es/__new-tests__/requestAnimationFrame.test.js +36 -0
- package/es/__new-tests__/transformSelection.test.js +67 -0
- package/lib/__new-tests__/addEventListener.test.js +44 -0
- package/lib/__new-tests__/addInputModeListener.test.js +54 -0
- package/lib/__new-tests__/addPositionChangeListener.test.js +66 -0
- package/lib/__new-tests__/addResizeListener.test.js +66 -0
- package/lib/__new-tests__/findTabbable.test.js +68 -0
- package/lib/__new-tests__/getClassList.test.js +48 -0
- package/lib/__new-tests__/getFontSize.test.js +43 -0
- package/lib/__new-tests__/getOffsetParents.test.js +109 -0
- package/lib/__new-tests__/getScrollParents.test.js +89 -0
- package/lib/__new-tests__/isCustomElement.test.js +43 -0
- package/lib/__new-tests__/isVisible.test.js +113 -0
- package/lib/__new-tests__/requestAnimationFrame.test.js +38 -0
- package/lib/__new-tests__/transformSelection.test.js +69 -0
- package/package.json +6 -5
- package/src/__new-tests__/addEventListener.test.tsx +46 -0
- package/src/__new-tests__/addInputModeListener.test.tsx +60 -0
- package/src/__new-tests__/addPositionChangeListener.test.tsx +65 -0
- package/src/__new-tests__/addResizeListener.test.tsx +65 -0
- package/src/__new-tests__/findTabbable.test.tsx +71 -0
- package/src/__new-tests__/getClassList.test.tsx +47 -0
- package/src/__new-tests__/getFontSize.test.tsx +37 -0
- package/src/__new-tests__/getOffsetParents.test.tsx +99 -0
- package/src/__new-tests__/getScrollParents.test.tsx +84 -0
- package/src/__new-tests__/isCustomElement.test.tsx +45 -0
- package/src/__new-tests__/isVisible.test.tsx +114 -0
- package/src/__new-tests__/requestAnimationFrame.test.tsx +38 -0
- package/src/__new-tests__/transformSelection.test.tsx +80 -0
- package/tsconfig.build.json +3 -12
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/__new-tests__/addEventListener.test.d.ts +2 -0
- package/types/__new-tests__/addEventListener.test.d.ts.map +1 -0
- package/types/__new-tests__/addInputModeListener.test.d.ts +2 -0
- package/types/__new-tests__/addInputModeListener.test.d.ts.map +1 -0
- package/types/__new-tests__/addPositionChangeListener.test.d.ts +2 -0
- package/types/__new-tests__/addPositionChangeListener.test.d.ts.map +1 -0
- package/types/__new-tests__/addResizeListener.test.d.ts +2 -0
- package/types/__new-tests__/addResizeListener.test.d.ts.map +1 -0
- package/types/__new-tests__/findTabbable.test.d.ts +2 -0
- package/types/__new-tests__/findTabbable.test.d.ts.map +1 -0
- package/types/__new-tests__/getClassList.test.d.ts +2 -0
- package/types/__new-tests__/getClassList.test.d.ts.map +1 -0
- package/types/__new-tests__/getFontSize.test.d.ts +2 -0
- package/types/__new-tests__/getFontSize.test.d.ts.map +1 -0
- package/types/__new-tests__/getOffsetParents.test.d.ts +2 -0
- package/types/__new-tests__/getOffsetParents.test.d.ts.map +1 -0
- package/types/__new-tests__/getScrollParents.test.d.ts +2 -0
- package/types/__new-tests__/getScrollParents.test.d.ts.map +1 -0
- package/types/__new-tests__/isCustomElement.test.d.ts +2 -0
- package/types/__new-tests__/isCustomElement.test.d.ts.map +1 -0
- package/types/__new-tests__/isVisible.test.d.ts +2 -0
- package/types/__new-tests__/isVisible.test.d.ts.map +1 -0
- package/types/__new-tests__/requestAnimationFrame.test.d.ts +2 -0
- package/types/__new-tests__/requestAnimationFrame.test.d.ts.map +1 -0
- package/types/__new-tests__/transformSelection.test.d.ts +2 -0
- package/types/__new-tests__/transformSelection.test.d.ts.map +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [8.
|
|
6
|
+
## [8.47.1-snapshot-0](https://github.com/instructure/instructure-ui/compare/v8.47.0...v8.47.1-snapshot-0) (2023-11-02)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-dom-utils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [8.47.0](https://github.com/instructure/instructure-ui/compare/v8.46.1...v8.47.0) (2023-10-27)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-dom-utils
|
|
9
17
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var _div;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { addEventListener } from '../addEventListener';
|
|
30
|
+
describe('addEventListener', () => {
|
|
31
|
+
it('should add an event listener and provide a remove method', () => {
|
|
32
|
+
const callback = jest.fn();
|
|
33
|
+
const _render = render(_div || (_div = /*#__PURE__*/React.createElement("div", null))),
|
|
34
|
+
container = _render.container;
|
|
35
|
+
const node = container.firstChild;
|
|
36
|
+
const listener = addEventListener(node, 'click', callback);
|
|
37
|
+
fireEvent.click(node);
|
|
38
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
39
|
+
expect(typeof listener.remove).toBe('function');
|
|
40
|
+
listener.remove();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var _div;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render, fireEvent, screen } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { addInputModeListener } from '../addInputModeListener';
|
|
30
|
+
describe('addInputModeListener', () => {
|
|
31
|
+
it('should handle input mode changes', () => {
|
|
32
|
+
const handleInputModeChange = jest.fn();
|
|
33
|
+
render(_div || (_div = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", {
|
|
34
|
+
id: "button-1"
|
|
35
|
+
}, "hello"), /*#__PURE__*/React.createElement("button", null, "world"))));
|
|
36
|
+
const inputModeListener = addInputModeListener({
|
|
37
|
+
onInputModeChange: handleInputModeChange
|
|
38
|
+
});
|
|
39
|
+
const button = screen.getByRole('button', {
|
|
40
|
+
name: 'hello'
|
|
41
|
+
});
|
|
42
|
+
fireEvent.mouseUp(button);
|
|
43
|
+
expect(inputModeListener.isKeyboardMode()).toBe(false);
|
|
44
|
+
fireEvent.keyDown(button);
|
|
45
|
+
expect(inputModeListener.isKeyboardMode()).toBe(true);
|
|
46
|
+
expect(handleInputModeChange).toHaveBeenCalledTimes(2);
|
|
47
|
+
inputModeListener.remove();
|
|
48
|
+
fireEvent.mouseUp(button);
|
|
49
|
+
expect(inputModeListener.isKeyboardMode()).toBe(true);
|
|
50
|
+
expect(handleInputModeChange).toHaveBeenCalledTimes(2);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var _div;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render, waitFor } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { addPositionChangeListener } from '../addPositionChangeListener';
|
|
30
|
+
const mockRect = {
|
|
31
|
+
top: 0,
|
|
32
|
+
left: 0,
|
|
33
|
+
right: 0,
|
|
34
|
+
bottom: 0,
|
|
35
|
+
width: 0,
|
|
36
|
+
height: 0,
|
|
37
|
+
x: 0,
|
|
38
|
+
y: 0,
|
|
39
|
+
toJSON: jest.fn()
|
|
40
|
+
};
|
|
41
|
+
describe('addPositionChangeListener', () => {
|
|
42
|
+
it('should provide a remove method', async () => {
|
|
43
|
+
const callback = jest.fn();
|
|
44
|
+
Element.prototype.getBoundingClientRect = jest.fn(() => mockRect);
|
|
45
|
+
const _render = render(_div || (_div = /*#__PURE__*/React.createElement("div", null))),
|
|
46
|
+
container = _render.container;
|
|
47
|
+
const node = container.firstChild;
|
|
48
|
+
const listener = addPositionChangeListener(node, callback);
|
|
49
|
+
|
|
50
|
+
// Manually trigger a position change (since JSDOM won't)
|
|
51
|
+
Element.prototype.getBoundingClientRect = jest.fn(() => {
|
|
52
|
+
return {
|
|
53
|
+
...mockRect,
|
|
54
|
+
top: 200
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
await waitFor(() => {
|
|
58
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
59
|
+
expect(typeof listener.remove).toBe('function');
|
|
60
|
+
});
|
|
61
|
+
listener.remove();
|
|
62
|
+
jest.restoreAllMocks();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var _div;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render, waitFor } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { addResizeListener } from '../addResizeListener';
|
|
30
|
+
const mockRect = {
|
|
31
|
+
top: 0,
|
|
32
|
+
left: 0,
|
|
33
|
+
right: 0,
|
|
34
|
+
bottom: 0,
|
|
35
|
+
width: 0,
|
|
36
|
+
height: 0,
|
|
37
|
+
x: 0,
|
|
38
|
+
y: 0,
|
|
39
|
+
toJSON: jest.fn()
|
|
40
|
+
};
|
|
41
|
+
describe('addResizeListener', () => {
|
|
42
|
+
it('should provide a remove method', async () => {
|
|
43
|
+
const callback = jest.fn();
|
|
44
|
+
Element.prototype.getBoundingClientRect = jest.fn(() => mockRect);
|
|
45
|
+
const _render = render(_div || (_div = /*#__PURE__*/React.createElement("div", null))),
|
|
46
|
+
container = _render.container;
|
|
47
|
+
const node = container.firstChild;
|
|
48
|
+
const listener = addResizeListener(node, callback);
|
|
49
|
+
|
|
50
|
+
// Manually trigger a size change (since JSDOM won't)
|
|
51
|
+
Element.prototype.getBoundingClientRect = jest.fn(() => {
|
|
52
|
+
return {
|
|
53
|
+
...mockRect,
|
|
54
|
+
width: 200
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
await waitFor(() => {
|
|
58
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
59
|
+
expect(typeof listener.remove).toBe('function');
|
|
60
|
+
});
|
|
61
|
+
listener.remove();
|
|
62
|
+
jest.restoreAllMocks();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var _a, _div, _div2, _input, _button, _button2;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { findTabbable } from '../findTabbable';
|
|
30
|
+
describe('findTabbable', () => {
|
|
31
|
+
describe('tabbable content', () => {
|
|
32
|
+
it('should find tabbable descendants', () => {
|
|
33
|
+
/* eslint-disable jsx-a11y/tabindex-no-positive */
|
|
34
|
+
/* eslint-disable jsx-a11y/no-noninteractive-tabindex */
|
|
35
|
+
const _render = render( /*#__PURE__*/React.createElement("div", null, _a || (_a = /*#__PURE__*/React.createElement("a", {
|
|
36
|
+
href: "https://instructure-test"
|
|
37
|
+
}, "Tabbable")), _div || (_div = /*#__PURE__*/React.createElement("div", null, "Not Tabbable")), _div2 || (_div2 = /*#__PURE__*/React.createElement("div", {
|
|
38
|
+
tabIndex: 1
|
|
39
|
+
}, "Tabbable")), _input || (_input = /*#__PURE__*/React.createElement("input", {
|
|
40
|
+
type: "text",
|
|
41
|
+
value: "Tabbable",
|
|
42
|
+
readOnly: true
|
|
43
|
+
})), /*#__PURE__*/React.createElement("div", null, _button || (_button = /*#__PURE__*/React.createElement("button", null, "Tabbable")), /*#__PURE__*/React.createElement("button", {
|
|
44
|
+
style: {
|
|
45
|
+
display: 'none'
|
|
46
|
+
}
|
|
47
|
+
}, "Not Tabbable")))),
|
|
48
|
+
container = _render.container;
|
|
49
|
+
const node = container.firstChild;
|
|
50
|
+
expect(findTabbable(node).length).toBe(4);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('tabbable root', () => {
|
|
54
|
+
it('should search the root node when shouldSearchRootNode is set', () => {
|
|
55
|
+
const shouldSearchRootNode = true;
|
|
56
|
+
const _render2 = render(_button2 || (_button2 = /*#__PURE__*/React.createElement("button", null, /*#__PURE__*/React.createElement("span", null, "hello")))),
|
|
57
|
+
container = _render2.container;
|
|
58
|
+
const node = container.firstChild;
|
|
59
|
+
expect(findTabbable(node).length).toBe(0);
|
|
60
|
+
expect(findTabbable(node, shouldSearchRootNode).length).toBe(1);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
it('should gracefully handle null', () => {
|
|
64
|
+
expect(findTabbable(null).length).toBe(0);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var _span;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { getClassList } from '../getClassList';
|
|
30
|
+
describe('getClassList', () => {
|
|
31
|
+
it('should provide classlist methods', () => {
|
|
32
|
+
const _render = render(_span || (_span = /*#__PURE__*/React.createElement("span", {
|
|
33
|
+
className: "foo bar baz"
|
|
34
|
+
}, "Test"))),
|
|
35
|
+
container = _render.container;
|
|
36
|
+
const node = container.firstChild;
|
|
37
|
+
const classes = getClassList(node);
|
|
38
|
+
expect(classes.toArray().length).toBe(3);
|
|
39
|
+
expect(classes.contains('foo')).toBeTruthy();
|
|
40
|
+
expect(classes.contains('lorem')).toBeFalsy();
|
|
41
|
+
classes.add('lorem');
|
|
42
|
+
expect(classes.contains('lorem')).toBeTruthy();
|
|
43
|
+
classes.remove('lorem');
|
|
44
|
+
expect(classes.contains('lorem')).toBeFalsy();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react';
|
|
26
|
+
import { render } from '@testing-library/react';
|
|
27
|
+
import '@testing-library/jest-dom';
|
|
28
|
+
import { getFontSize } from '../getFontSize';
|
|
29
|
+
describe('getFontSize', () => {
|
|
30
|
+
it('should return font size as a number', () => {
|
|
31
|
+
const _render = render( /*#__PURE__*/React.createElement("span", {
|
|
32
|
+
style: {
|
|
33
|
+
fontSize: '17px'
|
|
34
|
+
}
|
|
35
|
+
}, "Test")),
|
|
36
|
+
container = _render.container;
|
|
37
|
+
const node = container.firstChild;
|
|
38
|
+
expect(getFontSize(node)).toBe(17);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var _div;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { getScrollParents } from '../getScrollParents';
|
|
30
|
+
describe('getScrollParents', () => {
|
|
31
|
+
const node = /*#__PURE__*/React.createElement("div", null, _div || (_div = /*#__PURE__*/React.createElement("div", {
|
|
32
|
+
id: "item-1"
|
|
33
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
34
|
+
id: "item-2"
|
|
35
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
36
|
+
id: "item-3"
|
|
37
|
+
}, "Test"), /*#__PURE__*/React.createElement("span", {
|
|
38
|
+
id: "sibling-1"
|
|
39
|
+
}, "Test"), /*#__PURE__*/React.createElement("span", {
|
|
40
|
+
id: "sibling-2"
|
|
41
|
+
}, "Test"), /*#__PURE__*/React.createElement("span", {
|
|
42
|
+
id: "sibling-3"
|
|
43
|
+
}, "Test")))), /*#__PURE__*/React.createElement("div", {
|
|
44
|
+
id: "ht",
|
|
45
|
+
style: {
|
|
46
|
+
height: '50px'
|
|
47
|
+
}
|
|
48
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
49
|
+
id: "scroll-parent",
|
|
50
|
+
style: {
|
|
51
|
+
height: '200px',
|
|
52
|
+
overflow: 'scroll'
|
|
53
|
+
}
|
|
54
|
+
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
55
|
+
id: "scroll-child",
|
|
56
|
+
style: {
|
|
57
|
+
height: '500px'
|
|
58
|
+
}
|
|
59
|
+
}, "Test"))), /*#__PURE__*/React.createElement("div", {
|
|
60
|
+
id: "scroll-parent-rel",
|
|
61
|
+
style: {
|
|
62
|
+
height: '200px',
|
|
63
|
+
overflow: 'scroll',
|
|
64
|
+
position: 'relative'
|
|
65
|
+
}
|
|
66
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
67
|
+
style: {
|
|
68
|
+
height: '200px',
|
|
69
|
+
overflow: 'scroll'
|
|
70
|
+
}
|
|
71
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
72
|
+
id: "scroll-child-rel",
|
|
73
|
+
style: {
|
|
74
|
+
height: '500px',
|
|
75
|
+
position: 'absolute'
|
|
76
|
+
}
|
|
77
|
+
}, "Test"))), /*#__PURE__*/React.createElement("div", {
|
|
78
|
+
style: {
|
|
79
|
+
height: '200px',
|
|
80
|
+
overflow: 'scroll'
|
|
81
|
+
}
|
|
82
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
83
|
+
id: "scroll-child-fixed",
|
|
84
|
+
style: {
|
|
85
|
+
height: '500px',
|
|
86
|
+
position: 'fixed'
|
|
87
|
+
}
|
|
88
|
+
}, "Test")));
|
|
89
|
+
beforeEach(() => {
|
|
90
|
+
render(node);
|
|
91
|
+
});
|
|
92
|
+
it('should find scroll parent for inline elements', () => {
|
|
93
|
+
const child = document.getElementById('scroll-child');
|
|
94
|
+
const parent = document.getElementById('scroll-parent');
|
|
95
|
+
expect(getScrollParents(child)[0]).toBe(parent);
|
|
96
|
+
});
|
|
97
|
+
it('should ignore static parents when absolute', () => {
|
|
98
|
+
const child = document.getElementById('scroll-child-rel');
|
|
99
|
+
const parent = document.getElementById('scroll-parent-rel');
|
|
100
|
+
expect(getScrollParents(child)[0]).toBe(parent);
|
|
101
|
+
});
|
|
102
|
+
it('should handle fixed', () => {
|
|
103
|
+
const child = document.getElementById('scroll-child-fixed');
|
|
104
|
+
const scrollParent = getScrollParents(child)[0];
|
|
105
|
+
expect(scrollParent).toBe(document);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var _div, _div2;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { getOffsetParents } from '../getOffsetParents';
|
|
30
|
+
describe('getOffsetParents', () => {
|
|
31
|
+
// At rendering, we receive the node_wrapper and the body as extra offsetParents
|
|
32
|
+
const node = /*#__PURE__*/React.createElement("div", {
|
|
33
|
+
"data-testid": "node"
|
|
34
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
35
|
+
"data-testid": "child_1_wrapper_parent",
|
|
36
|
+
style: {
|
|
37
|
+
transform: '200px',
|
|
38
|
+
position: 'relative'
|
|
39
|
+
}
|
|
40
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
41
|
+
"data-testid": "child_1_wrapper"
|
|
42
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
43
|
+
"data-testid": "child-1",
|
|
44
|
+
style: {
|
|
45
|
+
height: '500px'
|
|
46
|
+
}
|
|
47
|
+
}, "Test"))), /*#__PURE__*/React.createElement("div", {
|
|
48
|
+
"data-testid": "child_2_wrapper_parent",
|
|
49
|
+
style: {
|
|
50
|
+
transform: '200px',
|
|
51
|
+
position: 'absolute'
|
|
52
|
+
}
|
|
53
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
54
|
+
"data-testid": "child_2_wrapper",
|
|
55
|
+
style: {
|
|
56
|
+
position: 'absolute'
|
|
57
|
+
}
|
|
58
|
+
}, _div || (_div = /*#__PURE__*/React.createElement("div", {
|
|
59
|
+
"data-testid": "child-2"
|
|
60
|
+
}, "Test")))), _div2 || (_div2 = /*#__PURE__*/React.createElement("div", {
|
|
61
|
+
"data-testid": "child_3_wrapper"
|
|
62
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
63
|
+
"data-testid": "child-3"
|
|
64
|
+
}, "Test"))));
|
|
65
|
+
it('should find offset parent for inline elements', () => {
|
|
66
|
+
const _render = render(node),
|
|
67
|
+
getByTestId = _render.getByTestId;
|
|
68
|
+
const child = getByTestId('child-1');
|
|
69
|
+
const parent = getByTestId('child_1_wrapper_parent');
|
|
70
|
+
const offsetParents = getOffsetParents(child);
|
|
71
|
+
expect(offsetParents[1]).toBe(parent);
|
|
72
|
+
});
|
|
73
|
+
it('should ignore static parents when absolute', () => {
|
|
74
|
+
const _render2 = render(node),
|
|
75
|
+
getByTestId = _render2.getByTestId;
|
|
76
|
+
const child = getByTestId('child-2');
|
|
77
|
+
const offsetParents = getOffsetParents(child);
|
|
78
|
+
expect(offsetParents.length).toBe(5);
|
|
79
|
+
});
|
|
80
|
+
it('should handle fixed', () => {
|
|
81
|
+
const _render3 = render(node),
|
|
82
|
+
getByTestId = _render3.getByTestId;
|
|
83
|
+
const child = getByTestId('child-3');
|
|
84
|
+
const offsetParents = getOffsetParents(child);
|
|
85
|
+
expect(offsetParents.length).toBe(4);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import '@testing-library/jest-dom';
|
|
26
|
+
import { isDefinedCustomElement } from '../isDefinedCustomElement';
|
|
27
|
+
class TestElement extends HTMLElement {}
|
|
28
|
+
describe('isDefinedCustomElement', () => {
|
|
29
|
+
beforeAll(() => {
|
|
30
|
+
customElements.define('test-element', TestElement);
|
|
31
|
+
});
|
|
32
|
+
it('should return true for defined elements', () => {
|
|
33
|
+
const el = document.createElement('test-element');
|
|
34
|
+
expect(isDefinedCustomElement(el)).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
it('should return false for not defined elements', () => {
|
|
37
|
+
// it is possible to create a custom element that is not defined
|
|
38
|
+
const el = document.createElement('my-element');
|
|
39
|
+
expect(isDefinedCustomElement(el)).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
});
|