@instructure/ui-dom-utils 10.19.2-snapshot-2 → 10.19.2-snapshot-4
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 +1 -1
- package/package.json +4 -4
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/__new-tests__/addEventListener.test.js +0 -43
- package/es/__new-tests__/addInputModeListener.test.js +0 -58
- package/es/__new-tests__/addPositionChangeListener.test.js +0 -65
- package/es/__new-tests__/findTabbable.test.js +0 -79
- package/es/__new-tests__/getClassList.test.js +0 -47
- package/es/__new-tests__/getFontSize.test.js +0 -41
- package/es/__new-tests__/getOffsetParents.test.js +0 -124
- package/es/__new-tests__/getScrollParents.test.js +0 -96
- package/es/__new-tests__/isCustomElement.test.js +0 -41
- package/es/__new-tests__/isVisible.test.js +0 -126
- package/es/__new-tests__/requestAnimationFrame.test.js +0 -37
- package/es/__new-tests__/transformSelection.test.js +0 -67
- package/lib/__new-tests__/addEventListener.test.js +0 -44
- package/lib/__new-tests__/addInputModeListener.test.js +0 -59
- package/lib/__new-tests__/addPositionChangeListener.test.js +0 -66
- package/lib/__new-tests__/findTabbable.test.js +0 -80
- package/lib/__new-tests__/getClassList.test.js +0 -48
- package/lib/__new-tests__/getFontSize.test.js +0 -43
- package/lib/__new-tests__/getOffsetParents.test.js +0 -125
- package/lib/__new-tests__/getScrollParents.test.js +0 -97
- package/lib/__new-tests__/isCustomElement.test.js +0 -43
- package/lib/__new-tests__/isVisible.test.js +0 -127
- package/lib/__new-tests__/requestAnimationFrame.test.js +0 -39
- package/lib/__new-tests__/transformSelection.test.js +0 -69
- package/src/__new-tests__/addEventListener.test.tsx +0 -46
- package/src/__new-tests__/addInputModeListener.test.tsx +0 -60
- package/src/__new-tests__/addPositionChangeListener.test.tsx +0 -65
- package/src/__new-tests__/findTabbable.test.tsx +0 -68
- package/src/__new-tests__/getClassList.test.tsx +0 -46
- package/src/__new-tests__/getFontSize.test.tsx +0 -36
- package/src/__new-tests__/getOffsetParents.test.tsx +0 -98
- package/src/__new-tests__/getScrollParents.test.tsx +0 -83
- package/src/__new-tests__/isCustomElement.test.tsx +0 -45
- package/src/__new-tests__/isVisible.test.tsx +0 -113
- package/src/__new-tests__/requestAnimationFrame.test.tsx +0 -39
- package/src/__new-tests__/transformSelection.test.tsx +0 -80
- package/types/__new-tests__/addEventListener.test.d.ts +0 -2
- package/types/__new-tests__/addEventListener.test.d.ts.map +0 -1
- package/types/__new-tests__/addInputModeListener.test.d.ts +0 -2
- package/types/__new-tests__/addInputModeListener.test.d.ts.map +0 -1
- package/types/__new-tests__/addPositionChangeListener.test.d.ts +0 -2
- package/types/__new-tests__/addPositionChangeListener.test.d.ts.map +0 -1
- package/types/__new-tests__/findTabbable.test.d.ts +0 -2
- package/types/__new-tests__/findTabbable.test.d.ts.map +0 -1
- package/types/__new-tests__/getClassList.test.d.ts +0 -2
- package/types/__new-tests__/getClassList.test.d.ts.map +0 -1
- package/types/__new-tests__/getFontSize.test.d.ts +0 -2
- package/types/__new-tests__/getFontSize.test.d.ts.map +0 -1
- package/types/__new-tests__/getOffsetParents.test.d.ts +0 -2
- package/types/__new-tests__/getOffsetParents.test.d.ts.map +0 -1
- package/types/__new-tests__/getScrollParents.test.d.ts +0 -2
- package/types/__new-tests__/getScrollParents.test.d.ts.map +0 -1
- package/types/__new-tests__/isCustomElement.test.d.ts +0 -2
- package/types/__new-tests__/isCustomElement.test.d.ts.map +0 -1
- package/types/__new-tests__/isVisible.test.d.ts +0 -2
- package/types/__new-tests__/isVisible.test.d.ts.map +0 -1
- package/types/__new-tests__/requestAnimationFrame.test.d.ts +0 -2
- package/types/__new-tests__/requestAnimationFrame.test.d.ts.map +0 -1
- package/types/__new-tests__/transformSelection.test.d.ts +0 -2
- package/types/__new-tests__/transformSelection.test.d.ts.map +0 -1
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _react = require("@testing-library/react");
|
|
4
|
-
require("@testing-library/jest-dom");
|
|
5
|
-
var _isVisible = require("../isVisible");
|
|
6
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
7
|
-
var _div;
|
|
8
|
-
/*
|
|
9
|
-
* The MIT License (MIT)
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
-
* furnished to do so, subject to the following conditions:
|
|
19
|
-
*
|
|
20
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
-
* copies or substantial portions of the Software.
|
|
22
|
-
*
|
|
23
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
-
* SOFTWARE.
|
|
30
|
-
*/
|
|
31
|
-
describe('isVisible', () => {
|
|
32
|
-
it('should recognize visible elements', () => {
|
|
33
|
-
(0, _react.render)(_div || (_div = (0, _jsxRuntime.jsx)("div", {
|
|
34
|
-
"data-testid": "test",
|
|
35
|
-
children: "Hello world!"
|
|
36
|
-
})));
|
|
37
|
-
const element = _react.screen.getByTestId('test');
|
|
38
|
-
expect((0, _isVisible.isVisible)(element)).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
it('should recognize elements with display: none', () => {
|
|
41
|
-
(0, _react.render)((0, _jsxRuntime.jsx)("div", {
|
|
42
|
-
"data-testid": "test",
|
|
43
|
-
children: (0, _jsxRuntime.jsx)("span", {
|
|
44
|
-
style: {
|
|
45
|
-
display: 'none'
|
|
46
|
-
},
|
|
47
|
-
children: "Hello world!"
|
|
48
|
-
})
|
|
49
|
-
}));
|
|
50
|
-
const element = _react.screen.getByTestId('test').firstChild;
|
|
51
|
-
expect((0, _isVisible.isVisible)(element)).toBe(false);
|
|
52
|
-
});
|
|
53
|
-
it('should recognize elements hidden with clip', () => {
|
|
54
|
-
const style = {
|
|
55
|
-
position: 'absolute',
|
|
56
|
-
overflow: 'hidden',
|
|
57
|
-
clip: 'rect(0,0,0,0)'
|
|
58
|
-
};
|
|
59
|
-
(0, _react.render)((0, _jsxRuntime.jsx)("div", {
|
|
60
|
-
"data-testid": "test",
|
|
61
|
-
children: (0, _jsxRuntime.jsx)("span", {
|
|
62
|
-
style: style,
|
|
63
|
-
children: "Hello world!"
|
|
64
|
-
})
|
|
65
|
-
}));
|
|
66
|
-
const element = _react.screen.getByTestId('test').firstChild;
|
|
67
|
-
expect((0, _isVisible.isVisible)(element)).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
it('should recognize clipped elements that are not hidden', () => {
|
|
70
|
-
const style = {
|
|
71
|
-
position: 'absolute',
|
|
72
|
-
overflow: 'hidden',
|
|
73
|
-
clip: 'rect(0,0,10px,0)'
|
|
74
|
-
};
|
|
75
|
-
(0, _react.render)((0, _jsxRuntime.jsx)("div", {
|
|
76
|
-
"data-testid": "test",
|
|
77
|
-
children: (0, _jsxRuntime.jsx)("span", {
|
|
78
|
-
style: style,
|
|
79
|
-
children: "Hello world!"
|
|
80
|
-
})
|
|
81
|
-
}));
|
|
82
|
-
const element = _react.screen.getByTestId('test').firstChild;
|
|
83
|
-
expect((0, _isVisible.isVisible)(element)).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
it('should recursively check parent visibility', () => {
|
|
86
|
-
const style = {
|
|
87
|
-
visibility: 'hidden'
|
|
88
|
-
};
|
|
89
|
-
(0, _react.render)((0, _jsxRuntime.jsx)("div", {
|
|
90
|
-
"data-testid": "test",
|
|
91
|
-
style: style,
|
|
92
|
-
children: (0, _jsxRuntime.jsx)("span", {
|
|
93
|
-
children: (0, _jsxRuntime.jsx)("span", {
|
|
94
|
-
"data-testid": "test-2",
|
|
95
|
-
style: {
|
|
96
|
-
visibility: 'visible'
|
|
97
|
-
},
|
|
98
|
-
children: "Hello world!"
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
}));
|
|
102
|
-
const element = _react.screen.getByTestId('test-2');
|
|
103
|
-
expect((0, _isVisible.isVisible)(element, false)).toBe(true);
|
|
104
|
-
expect((0, _isVisible.isVisible)(element)).toBe(false);
|
|
105
|
-
});
|
|
106
|
-
it('should not recursively check text nodes', () => {
|
|
107
|
-
const style = {
|
|
108
|
-
visibility: 'hidden'
|
|
109
|
-
};
|
|
110
|
-
(0, _react.render)((0, _jsxRuntime.jsx)("div", {
|
|
111
|
-
"data-testid": "test",
|
|
112
|
-
style: style,
|
|
113
|
-
children: (0, _jsxRuntime.jsx)("span", {
|
|
114
|
-
children: (0, _jsxRuntime.jsx)("span", {
|
|
115
|
-
"data-testid": "test-2",
|
|
116
|
-
style: {
|
|
117
|
-
visibility: 'visible'
|
|
118
|
-
},
|
|
119
|
-
children: "Hello world!"
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
}));
|
|
123
|
-
const element = _react.screen.getByTestId('test-2').firstChild;
|
|
124
|
-
expect((0, _isVisible.isVisible)(element, false)).toBe(true);
|
|
125
|
-
expect((0, _isVisible.isVisible)(element)).toBe(false);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _react = require("@testing-library/react");
|
|
4
|
-
var _vitest = require("vitest");
|
|
5
|
-
var _requestAnimationFrame = require("../requestAnimationFrame");
|
|
6
|
-
/*
|
|
7
|
-
* The MIT License (MIT)
|
|
8
|
-
*
|
|
9
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
10
|
-
*
|
|
11
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
13
|
-
* in the Software without restriction, including without limitation the rights
|
|
14
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
16
|
-
* furnished to do so, subject to the following conditions:
|
|
17
|
-
*
|
|
18
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
19
|
-
* copies or substantial portions of the Software.
|
|
20
|
-
*
|
|
21
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
-
* SOFTWARE.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
describe('requestAnimationFrame', () => {
|
|
31
|
-
it('should provide a cancel method', async () => {
|
|
32
|
-
const callback = _vitest.vi.fn();
|
|
33
|
-
const raf = (0, _requestAnimationFrame.requestAnimationFrame)(callback);
|
|
34
|
-
await (0, _react.waitFor)(() => {
|
|
35
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
36
|
-
expect(typeof raf.cancel).toBe('function');
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _transformSelection = require("../transformSelection");
|
|
4
|
-
/*
|
|
5
|
-
* The MIT License (MIT)
|
|
6
|
-
*
|
|
7
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
8
|
-
*
|
|
9
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
-
* in the Software without restriction, including without limitation the rights
|
|
12
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
-
* furnished to do so, subject to the following conditions:
|
|
15
|
-
*
|
|
16
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
-
* copies or substantial portions of the Software.
|
|
18
|
-
*
|
|
19
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
-
* SOFTWARE.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
describe('transformSelection', () => {
|
|
29
|
-
it('should work with transformCursor', () => {
|
|
30
|
-
const paramObj = {
|
|
31
|
-
selectionStart: 2,
|
|
32
|
-
selectionEnd: 3,
|
|
33
|
-
selectionDirection: 'none',
|
|
34
|
-
value: '1x2345'
|
|
35
|
-
};
|
|
36
|
-
const result = (0, _transformSelection.transformSelection)(paramObj, '12345');
|
|
37
|
-
expect(result).toEqual({
|
|
38
|
-
selectionStart: 1,
|
|
39
|
-
selectionEnd: 2,
|
|
40
|
-
selectionDirection: 'none'
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
describe('transformCursor', () => {
|
|
45
|
-
it('should retain cursor at the end', () => {
|
|
46
|
-
const dirtyValue = '12_xxxx_';
|
|
47
|
-
const cleanedValue = '12';
|
|
48
|
-
const cursorIndex = dirtyValue.length;
|
|
49
|
-
expect((0, _transformSelection.transformCursor)(cursorIndex, dirtyValue, cleanedValue)).toBe(cleanedValue.length);
|
|
50
|
-
});
|
|
51
|
-
it('should retain cursor at the start', () => {
|
|
52
|
-
const dirtyValue = '12_xxxx_67';
|
|
53
|
-
const cleanedValue = '1267';
|
|
54
|
-
const cursorIndex = 0;
|
|
55
|
-
expect((0, _transformSelection.transformCursor)(cursorIndex, dirtyValue, cleanedValue)).toBe(0);
|
|
56
|
-
});
|
|
57
|
-
it('should retain cursor between cleaned values', () => {
|
|
58
|
-
const dirtyValue = '12_xxxx_67';
|
|
59
|
-
const cleanedValue = '1267';
|
|
60
|
-
const cursorIndex = 6;
|
|
61
|
-
expect((0, _transformSelection.transformCursor)(cursorIndex, dirtyValue, cleanedValue)).toBe(2);
|
|
62
|
-
});
|
|
63
|
-
it('should retain cursor after cleaned values', () => {
|
|
64
|
-
const dirtyValue = '12_xxxx_67';
|
|
65
|
-
const cleanedValue = '1267';
|
|
66
|
-
const cursorIndex = dirtyValue.length - 1;
|
|
67
|
-
expect((0, _transformSelection.transformCursor)(cursorIndex, dirtyValue, cleanedValue)).toBe(3);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
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 { fireEvent, render } from '@testing-library/react'
|
|
26
|
-
import { vi } from 'vitest'
|
|
27
|
-
import '@testing-library/jest-dom'
|
|
28
|
-
import { addEventListener } from '../addEventListener'
|
|
29
|
-
|
|
30
|
-
describe('addEventListener', () => {
|
|
31
|
-
it('should add an event listener and provide a remove method', () => {
|
|
32
|
-
const callback = vi.fn()
|
|
33
|
-
|
|
34
|
-
const { container } = render(<div />)
|
|
35
|
-
const node = container.firstChild as HTMLDivElement
|
|
36
|
-
|
|
37
|
-
const listener = addEventListener(node, 'click', callback)
|
|
38
|
-
|
|
39
|
-
fireEvent.click(node)
|
|
40
|
-
|
|
41
|
-
expect(callback).toHaveBeenCalledTimes(1)
|
|
42
|
-
expect(typeof listener.remove).toBe('function')
|
|
43
|
-
|
|
44
|
-
listener.remove()
|
|
45
|
-
})
|
|
46
|
-
})
|
|
@@ -1,60 +0,0 @@
|
|
|
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 { render, fireEvent, screen } from '@testing-library/react'
|
|
26
|
-
import { vi } from 'vitest'
|
|
27
|
-
import '@testing-library/jest-dom'
|
|
28
|
-
import { addInputModeListener } from '../addInputModeListener'
|
|
29
|
-
|
|
30
|
-
describe('addInputModeListener', () => {
|
|
31
|
-
it('should handle input mode changes', () => {
|
|
32
|
-
const handleInputModeChange = vi.fn()
|
|
33
|
-
|
|
34
|
-
render(
|
|
35
|
-
<div>
|
|
36
|
-
<button id="button-1">hello</button>
|
|
37
|
-
<button>world</button>
|
|
38
|
-
</div>
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
const inputModeListener = addInputModeListener({
|
|
42
|
-
onInputModeChange: handleInputModeChange
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const button = screen.getByRole('button', { name: 'hello' })
|
|
46
|
-
|
|
47
|
-
fireEvent.mouseUp(button)
|
|
48
|
-
expect(inputModeListener.isKeyboardMode()).toBe(false)
|
|
49
|
-
|
|
50
|
-
fireEvent.keyDown(button)
|
|
51
|
-
expect(inputModeListener.isKeyboardMode()).toBe(true)
|
|
52
|
-
expect(handleInputModeChange).toHaveBeenCalledTimes(2)
|
|
53
|
-
|
|
54
|
-
inputModeListener.remove()
|
|
55
|
-
|
|
56
|
-
fireEvent.mouseUp(button)
|
|
57
|
-
expect(inputModeListener.isKeyboardMode()).toBe(true)
|
|
58
|
-
expect(handleInputModeChange).toHaveBeenCalledTimes(2)
|
|
59
|
-
})
|
|
60
|
-
})
|
|
@@ -1,65 +0,0 @@
|
|
|
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 { render, waitFor } from '@testing-library/react'
|
|
26
|
-
import { vi } from 'vitest'
|
|
27
|
-
import '@testing-library/jest-dom'
|
|
28
|
-
import { addPositionChangeListener } from '../addPositionChangeListener'
|
|
29
|
-
|
|
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: vi.fn()
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe('addPositionChangeListener', () => {
|
|
43
|
-
it('should provide a remove method', async () => {
|
|
44
|
-
const callback = vi.fn()
|
|
45
|
-
Element.prototype.getBoundingClientRect = vi.fn(() => mockRect as DOMRect)
|
|
46
|
-
|
|
47
|
-
const { container } = render(<div />)
|
|
48
|
-
const node = container.firstChild as HTMLDivElement
|
|
49
|
-
|
|
50
|
-
const listener = addPositionChangeListener(node, callback)
|
|
51
|
-
|
|
52
|
-
// Manually trigger a position change (since JSDOM won't)
|
|
53
|
-
Element.prototype.getBoundingClientRect = vi.fn(() => {
|
|
54
|
-
return { ...mockRect, top: 200 } as DOMRect
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
await waitFor(() => {
|
|
58
|
-
expect(callback).toHaveBeenCalledTimes(1)
|
|
59
|
-
expect(typeof listener.remove).toBe('function')
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
listener.remove()
|
|
63
|
-
vi.restoreAllMocks()
|
|
64
|
-
})
|
|
65
|
-
})
|
|
@@ -1,68 +0,0 @@
|
|
|
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 { render } from '@testing-library/react'
|
|
26
|
-
import '@testing-library/jest-dom'
|
|
27
|
-
import { findTabbable } from '../findTabbable'
|
|
28
|
-
|
|
29
|
-
describe('findTabbable', () => {
|
|
30
|
-
describe('tabbable content', () => {
|
|
31
|
-
it('should find tabbable descendants', () => {
|
|
32
|
-
const { container } = render(
|
|
33
|
-
<div>
|
|
34
|
-
<a href="https://instructure-test">Tabbable</a>
|
|
35
|
-
<div>Not Tabbable</div>
|
|
36
|
-
<div tabIndex={1}>Tabbable</div>
|
|
37
|
-
<input type="text" value="Tabbable" readOnly />
|
|
38
|
-
<div>
|
|
39
|
-
<button>Tabbable</button>
|
|
40
|
-
<button style={{ display: 'none' }}>Not Tabbable</button>
|
|
41
|
-
</div>
|
|
42
|
-
</div>
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
const node = container.firstChild as HTMLElement
|
|
46
|
-
expect(findTabbable(node).length).toBe(4)
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
describe('tabbable root', () => {
|
|
51
|
-
it('should search the root node when shouldSearchRootNode is set', () => {
|
|
52
|
-
const shouldSearchRootNode = true
|
|
53
|
-
const { container } = render(
|
|
54
|
-
<button>
|
|
55
|
-
<span>hello</span>
|
|
56
|
-
</button>
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
const node = container.firstChild as HTMLElement
|
|
60
|
-
expect(findTabbable(node).length).toBe(0)
|
|
61
|
-
expect(findTabbable(node, shouldSearchRootNode).length).toBe(1)
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it('should gracefully handle null', () => {
|
|
66
|
-
expect(findTabbable(null).length).toBe(0)
|
|
67
|
-
})
|
|
68
|
-
})
|
|
@@ -1,46 +0,0 @@
|
|
|
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 { render } from '@testing-library/react'
|
|
26
|
-
import '@testing-library/jest-dom'
|
|
27
|
-
import { getClassList } from '../getClassList'
|
|
28
|
-
|
|
29
|
-
describe('getClassList', () => {
|
|
30
|
-
it('should provide classlist methods', () => {
|
|
31
|
-
const { container } = render(<span className="foo bar baz">Test</span>)
|
|
32
|
-
const node = container.firstChild as HTMLElement
|
|
33
|
-
|
|
34
|
-
const classes = getClassList(node)
|
|
35
|
-
|
|
36
|
-
expect(classes.toArray().length).toBe(3)
|
|
37
|
-
expect(classes.contains('foo')).toBeTruthy()
|
|
38
|
-
expect(classes.contains('lorem')).toBeFalsy()
|
|
39
|
-
|
|
40
|
-
classes.add('lorem')
|
|
41
|
-
expect(classes.contains('lorem')).toBeTruthy()
|
|
42
|
-
|
|
43
|
-
classes.remove('lorem')
|
|
44
|
-
expect(classes.contains('lorem')).toBeFalsy()
|
|
45
|
-
})
|
|
46
|
-
})
|
|
@@ -1,36 +0,0 @@
|
|
|
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 { render } from '@testing-library/react'
|
|
26
|
-
import '@testing-library/jest-dom'
|
|
27
|
-
import { getFontSize } from '../getFontSize'
|
|
28
|
-
|
|
29
|
-
describe('getFontSize', () => {
|
|
30
|
-
it('should return font size as a number', () => {
|
|
31
|
-
const { container } = render(<span style={{ fontSize: '17px' }}>Test</span>)
|
|
32
|
-
const node = container.firstChild
|
|
33
|
-
|
|
34
|
-
expect(getFontSize(node)).toBe(17)
|
|
35
|
-
})
|
|
36
|
-
})
|
|
@@ -1,98 +0,0 @@
|
|
|
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 { render } from '@testing-library/react'
|
|
26
|
-
import '@testing-library/jest-dom'
|
|
27
|
-
import { getScrollParents } from '../getScrollParents'
|
|
28
|
-
|
|
29
|
-
describe('getScrollParents', () => {
|
|
30
|
-
const node = (
|
|
31
|
-
<div>
|
|
32
|
-
<div id="item-1">
|
|
33
|
-
<div id="item-2">
|
|
34
|
-
<span id="item-3">Test</span>
|
|
35
|
-
<span id="sibling-1">Test</span>
|
|
36
|
-
<span id="sibling-2">Test</span>
|
|
37
|
-
<span id="sibling-3">Test</span>
|
|
38
|
-
</div>
|
|
39
|
-
</div>
|
|
40
|
-
<div id="ht" style={{ height: '50px' }} />
|
|
41
|
-
<div id="scroll-parent" style={{ height: '200px', overflow: 'scroll' }}>
|
|
42
|
-
<div>
|
|
43
|
-
<div id="scroll-child" style={{ height: '500px' }}>
|
|
44
|
-
Test
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
</div>
|
|
48
|
-
|
|
49
|
-
<div
|
|
50
|
-
id="scroll-parent-rel"
|
|
51
|
-
style={{ height: '200px', overflow: 'scroll', position: 'relative' }}
|
|
52
|
-
>
|
|
53
|
-
<div style={{ height: '200px', overflow: 'scroll' }}>
|
|
54
|
-
<div
|
|
55
|
-
id="scroll-child-rel"
|
|
56
|
-
style={{ height: '500px', position: 'absolute' }}
|
|
57
|
-
>
|
|
58
|
-
Test
|
|
59
|
-
</div>
|
|
60
|
-
</div>
|
|
61
|
-
</div>
|
|
62
|
-
|
|
63
|
-
<div style={{ height: '200px', overflow: 'scroll' }}>
|
|
64
|
-
<div
|
|
65
|
-
id="scroll-child-fixed"
|
|
66
|
-
style={{ height: '500px', position: 'fixed' }}
|
|
67
|
-
>
|
|
68
|
-
Test
|
|
69
|
-
</div>
|
|
70
|
-
</div>
|
|
71
|
-
</div>
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
beforeEach(() => {
|
|
75
|
-
render(node)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('should find scroll parent for inline elements', () => {
|
|
79
|
-
const child = document.getElementById('scroll-child')
|
|
80
|
-
const parent = document.getElementById('scroll-parent')
|
|
81
|
-
|
|
82
|
-
expect(getScrollParents(child)[0]).toBe(parent)
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('should ignore static parents when absolute', () => {
|
|
86
|
-
const child = document.getElementById('scroll-child-rel')
|
|
87
|
-
const parent = document.getElementById('scroll-parent-rel')
|
|
88
|
-
|
|
89
|
-
expect(getScrollParents(child)[0]).toBe(parent)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('should handle fixed', () => {
|
|
93
|
-
const child = document.getElementById('scroll-child-fixed')
|
|
94
|
-
const scrollParent = getScrollParents(child)[0]
|
|
95
|
-
|
|
96
|
-
expect(scrollParent).toBe(document)
|
|
97
|
-
})
|
|
98
|
-
})
|