@instructure/ui-toggle-details 10.14.1-snapshot-0 → 10.14.1-snapshot-2
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/es/ToggleDetails/__new-tests__/ToggleDetails.test.js +166 -0
- package/es/ToggleGroup/__new-tests__/ToggleGroup.test.js +201 -0
- package/lib/ToggleDetails/__new-tests__/ToggleDetails.test.js +168 -0
- package/lib/ToggleGroup/__new-tests__/ToggleGroup.test.js +203 -0
- package/package.json +23 -20
- package/src/ToggleDetails/__new-tests__/ToggleDetails.test.tsx +210 -0
- package/src/ToggleGroup/__new-tests__/ToggleGroup.test.tsx +270 -0
- package/tsconfig.build.json +1 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/ToggleDetails/__new-tests__/ToggleDetails.test.d.ts +2 -0
- package/types/ToggleDetails/__new-tests__/ToggleDetails.test.d.ts.map +1 -0
- package/types/ToggleGroup/__new-tests__/ToggleGroup.test.d.ts +2 -0
- package/types/ToggleGroup/__new-tests__/ToggleGroup.test.d.ts.map +1 -0
- package/es/ToggleDetails/ToggleDetailsLocator.js +0 -41
- package/es/ToggleDetails/locator.js +0 -27
- package/es/ToggleGroup/ToggleGroupLocator.js +0 -45
- package/es/ToggleGroup/locator.js +0 -27
- package/lib/ToggleDetails/ToggleDetailsLocator.js +0 -48
- package/lib/ToggleDetails/locator.js +0 -43
- package/lib/ToggleGroup/ToggleGroupLocator.js +0 -52
- package/lib/ToggleGroup/locator.js +0 -43
- package/src/ToggleDetails/ToggleDetailsLocator.ts +0 -49
- package/src/ToggleDetails/locator.ts +0 -29
- package/src/ToggleGroup/ToggleGroupLocator.ts +0 -48
- package/src/ToggleGroup/locator.ts +0 -29
- package/types/ToggleDetails/ToggleDetailsLocator.d.ts +0 -1223
- package/types/ToggleDetails/ToggleDetailsLocator.d.ts.map +0 -1
- package/types/ToggleDetails/locator.d.ts +0 -5
- package/types/ToggleDetails/locator.d.ts.map +0 -1
- package/types/ToggleGroup/ToggleGroupLocator.d.ts +0 -1223
- package/types/ToggleGroup/ToggleGroupLocator.d.ts.map +0 -1
- package/types/ToggleGroup/locator.d.ts +0 -5
- package/types/ToggleGroup/locator.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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
|
-
## [10.14.1-snapshot-
|
|
6
|
+
## [10.14.1-snapshot-2](https://github.com/instructure/instructure-ui/compare/v10.14.0...v10.14.1-snapshot-2) (2025-03-18)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-toggle-details
|
|
9
9
|
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
var _ToggleDetails, _ToggleDetails2, _ToggleDetails3, _ToggleDetails4, _ToggleDetails5, _ToggleDetails6, _ToggleDetails7, _ToggleDetails8;
|
|
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, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
29
|
+
import userEvent from '@testing-library/user-event';
|
|
30
|
+
import { vi } from 'vitest';
|
|
31
|
+
import '@testing-library/jest-dom';
|
|
32
|
+
import { ToggleDetails } from '../index';
|
|
33
|
+
describe('<ToggleDetails />', () => {
|
|
34
|
+
let consoleWarningMock;
|
|
35
|
+
let consoleErrorMock;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
// Mocking console to prevent test output pollution
|
|
38
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
39
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
40
|
+
});
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
consoleWarningMock.mockRestore();
|
|
43
|
+
consoleErrorMock.mockRestore();
|
|
44
|
+
});
|
|
45
|
+
it('should hide its content', async () => {
|
|
46
|
+
render(_ToggleDetails || (_ToggleDetails = /*#__PURE__*/React.createElement(ToggleDetails, {
|
|
47
|
+
summary: "Click me"
|
|
48
|
+
}, "Content")));
|
|
49
|
+
const content = screen.queryByText('Content');
|
|
50
|
+
expect(content).not.toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
it('should place the icon after the summary when prop is set', async () => {
|
|
53
|
+
const _render = render(_ToggleDetails2 || (_ToggleDetails2 = /*#__PURE__*/React.createElement(ToggleDetails, {
|
|
54
|
+
iconPosition: "end",
|
|
55
|
+
summary: "Click me"
|
|
56
|
+
}, "Content"))),
|
|
57
|
+
container = _render.container;
|
|
58
|
+
const summary = container.querySelector('[class$="-toggleDetails__summaryText"]');
|
|
59
|
+
const icon = container.querySelector('[class$="-toggleDetails__icon"]');
|
|
60
|
+
expect(icon === null || icon === void 0 ? void 0 : icon.previousSibling).toBe(summary);
|
|
61
|
+
});
|
|
62
|
+
it('should have an aria-controls attribute', async () => {
|
|
63
|
+
const _render2 = render(_ToggleDetails3 || (_ToggleDetails3 = /*#__PURE__*/React.createElement(ToggleDetails, {
|
|
64
|
+
summary: "Click me"
|
|
65
|
+
}, "Details"))),
|
|
66
|
+
container = _render2.container;
|
|
67
|
+
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
68
|
+
const content = container.querySelector('[class$="-toggleDetails__details"]');
|
|
69
|
+
expect(toggle).toHaveAttribute('aria-controls', content === null || content === void 0 ? void 0 : content.id);
|
|
70
|
+
});
|
|
71
|
+
it('should have an aria-expanded attribute', async () => {
|
|
72
|
+
const _render3 = render(_ToggleDetails4 || (_ToggleDetails4 = /*#__PURE__*/React.createElement(ToggleDetails, {
|
|
73
|
+
summary: "Click me"
|
|
74
|
+
}, "Details"))),
|
|
75
|
+
container = _render3.container;
|
|
76
|
+
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
77
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
78
|
+
});
|
|
79
|
+
it('should not have aria attributes when it has no children', async () => {
|
|
80
|
+
render(_ToggleDetails5 || (_ToggleDetails5 = /*#__PURE__*/React.createElement(ToggleDetails, {
|
|
81
|
+
summary: "Click me",
|
|
82
|
+
"data-testid": "td__0"
|
|
83
|
+
})));
|
|
84
|
+
const toggle = screen.getByTestId('td__0');
|
|
85
|
+
expect(toggle).not.toHaveAttribute('aria-controls');
|
|
86
|
+
expect(toggle).not.toHaveAttribute('aria-expanded');
|
|
87
|
+
});
|
|
88
|
+
it('should toggle on click events', async () => {
|
|
89
|
+
const _render4 = render(_ToggleDetails6 || (_ToggleDetails6 = /*#__PURE__*/React.createElement(ToggleDetails, {
|
|
90
|
+
summary: "Click me"
|
|
91
|
+
}, "Details"))),
|
|
92
|
+
container = _render4.container;
|
|
93
|
+
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
94
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
95
|
+
await userEvent.click(screen.getByText('Click me'));
|
|
96
|
+
await waitFor(() => {
|
|
97
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
it('should call onToggle on click events', async () => {
|
|
101
|
+
const onToggle = vi.fn();
|
|
102
|
+
render(/*#__PURE__*/React.createElement(ToggleDetails, {
|
|
103
|
+
summary: "Click me",
|
|
104
|
+
expanded: false,
|
|
105
|
+
onToggle: onToggle
|
|
106
|
+
}, "Details"));
|
|
107
|
+
await userEvent.click(screen.getByText('Click me'));
|
|
108
|
+
await waitFor(() => {
|
|
109
|
+
const args = onToggle.mock.calls[0];
|
|
110
|
+
expect(onToggle).toHaveBeenCalledTimes(1);
|
|
111
|
+
expect(args[0].type).toBe('click');
|
|
112
|
+
expect(args[1]).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
it('should call onToggle on click events when it has no children', async () => {
|
|
116
|
+
const onToggle = vi.fn();
|
|
117
|
+
render(/*#__PURE__*/React.createElement(ToggleDetails, {
|
|
118
|
+
summary: "Click me",
|
|
119
|
+
expanded: false,
|
|
120
|
+
onToggle: onToggle,
|
|
121
|
+
"data-testid": "td__1"
|
|
122
|
+
}));
|
|
123
|
+
const toggle = screen.getByTestId('td__1');
|
|
124
|
+
await userEvent.click(toggle);
|
|
125
|
+
await waitFor(() => {
|
|
126
|
+
const args = onToggle.mock.calls[0];
|
|
127
|
+
expect(onToggle).toHaveBeenCalledTimes(1);
|
|
128
|
+
expect(args[0].type).toBe('click');
|
|
129
|
+
expect(args[1]).toBe(true);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
it('should be initialized by defaultExpanded prop', async () => {
|
|
133
|
+
const _render5 = render(_ToggleDetails7 || (_ToggleDetails7 = /*#__PURE__*/React.createElement(ToggleDetails, {
|
|
134
|
+
summary: "Click me",
|
|
135
|
+
defaultExpanded: true
|
|
136
|
+
}, "Content"))),
|
|
137
|
+
container = _render5.container;
|
|
138
|
+
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
139
|
+
const content = container.querySelector('[class$="-toggleDetails__details"]');
|
|
140
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
|
141
|
+
expect(content).toHaveTextContent('Content');
|
|
142
|
+
});
|
|
143
|
+
it('should meet a11y standards', async () => {
|
|
144
|
+
const _render6 = render(_ToggleDetails8 || (_ToggleDetails8 = /*#__PURE__*/React.createElement(ToggleDetails, {
|
|
145
|
+
summary: "Click me"
|
|
146
|
+
}, "Content"))),
|
|
147
|
+
container = _render6.container;
|
|
148
|
+
const axeCheck = await runAxeCheck(container);
|
|
149
|
+
expect(axeCheck).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
it('focuses with the focus helper', async () => {
|
|
152
|
+
var _toggleRef;
|
|
153
|
+
let toggleRef;
|
|
154
|
+
const _render7 = render(/*#__PURE__*/React.createElement(ToggleDetails, {
|
|
155
|
+
summary: "Click me",
|
|
156
|
+
ref: el => {
|
|
157
|
+
toggleRef = el;
|
|
158
|
+
}
|
|
159
|
+
}, "Content")),
|
|
160
|
+
container = _render7.container;
|
|
161
|
+
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
162
|
+
expect(document.activeElement).not.toBe(toggle);
|
|
163
|
+
(_toggleRef = toggleRef) === null || _toggleRef === void 0 ? void 0 : _toggleRef.focus();
|
|
164
|
+
expect(document.activeElement).toBe(toggle);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
var _ToggleGroup, _ToggleGroup2, _ToggleGroup3, _ToggleGroup4, _ToggleGroup5, _svg, _svg2, _ToggleGroup6;
|
|
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, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
29
|
+
import userEvent from '@testing-library/user-event';
|
|
30
|
+
import { vi } from 'vitest';
|
|
31
|
+
import '@testing-library/jest-dom';
|
|
32
|
+
import { ToggleGroup } from '../index';
|
|
33
|
+
describe('<ToggleGroup />', () => {
|
|
34
|
+
let consoleWarningMock;
|
|
35
|
+
let consoleErrorMock;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
// Mocking console to prevent test output pollution
|
|
38
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
39
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
40
|
+
});
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
consoleWarningMock.mockRestore();
|
|
43
|
+
consoleErrorMock.mockRestore();
|
|
44
|
+
});
|
|
45
|
+
it('should show its summary and hide its children by default', async () => {
|
|
46
|
+
render(_ToggleGroup || (_ToggleGroup = /*#__PURE__*/React.createElement(ToggleGroup, {
|
|
47
|
+
"data-testId": "toggle-group",
|
|
48
|
+
transition: false,
|
|
49
|
+
summary: "This is the summary section",
|
|
50
|
+
toggleLabel: "This is the toggleLabel"
|
|
51
|
+
}, "This is the details section")));
|
|
52
|
+
const toggleGroup = screen.getByTestId('toggle-group');
|
|
53
|
+
expect(toggleGroup).toHaveTextContent('This is the summary section');
|
|
54
|
+
expect(toggleGroup).not.toHaveTextContent('This is the details section');
|
|
55
|
+
});
|
|
56
|
+
it('should render with children showing with the defaultExpanded prop', async () => {
|
|
57
|
+
const _render = render(_ToggleGroup2 || (_ToggleGroup2 = /*#__PURE__*/React.createElement(ToggleGroup, {
|
|
58
|
+
"data-testId": "toggle-group",
|
|
59
|
+
transition: false,
|
|
60
|
+
summary: "This is the summary section",
|
|
61
|
+
toggleLabel: "This is the toggleLabel",
|
|
62
|
+
defaultExpanded: true
|
|
63
|
+
}, "This is the details section"))),
|
|
64
|
+
container = _render.container;
|
|
65
|
+
const toggleGroup = screen.getByTestId('toggle-group');
|
|
66
|
+
const toggle = container.querySelector('button');
|
|
67
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
|
68
|
+
expect(toggleGroup).toHaveTextContent('This is the details section');
|
|
69
|
+
});
|
|
70
|
+
it('should have an aria-controls attribute', async () => {
|
|
71
|
+
const _render2 = render(_ToggleGroup3 || (_ToggleGroup3 = /*#__PURE__*/React.createElement(ToggleGroup, {
|
|
72
|
+
transition: false,
|
|
73
|
+
summary: "This is the summary section",
|
|
74
|
+
toggleLabel: "This is the toggleLabel",
|
|
75
|
+
defaultExpanded: true
|
|
76
|
+
}, "This is the details section"))),
|
|
77
|
+
container = _render2.container;
|
|
78
|
+
const content = screen.getByText('This is the details section');
|
|
79
|
+
const toggle = container.querySelector('button');
|
|
80
|
+
expect(toggle).toHaveAttribute('aria-controls', content.id);
|
|
81
|
+
});
|
|
82
|
+
it('should have an aria-expanded attribute', async () => {
|
|
83
|
+
const _render3 = render(_ToggleGroup4 || (_ToggleGroup4 = /*#__PURE__*/React.createElement(ToggleGroup, {
|
|
84
|
+
transition: false,
|
|
85
|
+
summary: "This is the summary section",
|
|
86
|
+
toggleLabel: "This is the toggleLabel"
|
|
87
|
+
}, "This is the details section"))),
|
|
88
|
+
container = _render3.container;
|
|
89
|
+
const toggle = container.querySelector('button');
|
|
90
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
91
|
+
});
|
|
92
|
+
it('should toggle on click events', async () => {
|
|
93
|
+
const _render4 = render(_ToggleGroup5 || (_ToggleGroup5 = /*#__PURE__*/React.createElement(ToggleGroup, {
|
|
94
|
+
transition: false,
|
|
95
|
+
summary: "This is the summary section",
|
|
96
|
+
toggleLabel: "This is the toggleLabel"
|
|
97
|
+
}, "This is the details section"))),
|
|
98
|
+
container = _render4.container;
|
|
99
|
+
const toggle = container.querySelector('button');
|
|
100
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
101
|
+
await userEvent.click(toggle);
|
|
102
|
+
await waitFor(() => {
|
|
103
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
it('should call onToggle on click events', async () => {
|
|
107
|
+
const onToggle = vi.fn();
|
|
108
|
+
const _render5 = render(/*#__PURE__*/React.createElement(ToggleGroup, {
|
|
109
|
+
transition: false,
|
|
110
|
+
summary: "This is the summary section",
|
|
111
|
+
toggleLabel: "This is the toggleLabel",
|
|
112
|
+
expanded: false,
|
|
113
|
+
onToggle: onToggle
|
|
114
|
+
}, "This is the details section")),
|
|
115
|
+
container = _render5.container;
|
|
116
|
+
const toggle = container.querySelector('button');
|
|
117
|
+
await userEvent.click(toggle);
|
|
118
|
+
await waitFor(() => {
|
|
119
|
+
const args = onToggle.mock.calls[0];
|
|
120
|
+
expect(onToggle).toHaveBeenCalledTimes(1);
|
|
121
|
+
expect(args[0].type).toBe('click');
|
|
122
|
+
expect(args[1]).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
it('should update the toggle screenreader label based on the expanded state', async () => {
|
|
126
|
+
const _render6 = render(/*#__PURE__*/React.createElement(ToggleGroup, {
|
|
127
|
+
transition: false,
|
|
128
|
+
summary: "This is the summary section",
|
|
129
|
+
toggleLabel: expanded => expanded ? 'Hide content' : 'Show content'
|
|
130
|
+
}, "This is the details section")),
|
|
131
|
+
container = _render6.container;
|
|
132
|
+
const toggle = container.querySelector('button');
|
|
133
|
+
const scrContent = container.querySelector('[class$="-screenReaderContent"]');
|
|
134
|
+
expect(scrContent).toHaveTextContent('Show content');
|
|
135
|
+
await userEvent.click(toggle);
|
|
136
|
+
await waitFor(() => {
|
|
137
|
+
expect(scrContent).toHaveTextContent('Hide content');
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
it('should accept custom icons', async () => {
|
|
141
|
+
const Icon = _svg || (_svg = /*#__PURE__*/React.createElement("svg", {
|
|
142
|
+
height: "50",
|
|
143
|
+
width: "50"
|
|
144
|
+
}, /*#__PURE__*/React.createElement("title", null, "Icon collapsed"), /*#__PURE__*/React.createElement("circle", {
|
|
145
|
+
cx: "25",
|
|
146
|
+
cy: "25",
|
|
147
|
+
r: "20"
|
|
148
|
+
})));
|
|
149
|
+
const IconExpanded = _svg2 || (_svg2 = /*#__PURE__*/React.createElement("svg", {
|
|
150
|
+
height: "50",
|
|
151
|
+
width: "50"
|
|
152
|
+
}, /*#__PURE__*/React.createElement("title", null, "Icon expanded"), /*#__PURE__*/React.createElement("circle", {
|
|
153
|
+
cx: "25",
|
|
154
|
+
cy: "25",
|
|
155
|
+
r: "20"
|
|
156
|
+
})));
|
|
157
|
+
const _render7 = render(/*#__PURE__*/React.createElement(ToggleGroup, {
|
|
158
|
+
transition: false,
|
|
159
|
+
summary: "This is the summary section",
|
|
160
|
+
toggleLabel: "This is the toggleLabel",
|
|
161
|
+
icon: () => Icon,
|
|
162
|
+
iconExpanded: () => IconExpanded
|
|
163
|
+
}, "This is the details section")),
|
|
164
|
+
container = _render7.container;
|
|
165
|
+
const toggle = container.querySelector('button');
|
|
166
|
+
const svg = container.querySelector('svg');
|
|
167
|
+
expect(svg).toHaveTextContent('Icon collapsed');
|
|
168
|
+
await userEvent.click(toggle);
|
|
169
|
+
await waitFor(() => {
|
|
170
|
+
expect(svg).toHaveTextContent('Icon expanded');
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
it('should meet a11y standards', async () => {
|
|
174
|
+
const _render8 = render(_ToggleGroup6 || (_ToggleGroup6 = /*#__PURE__*/React.createElement(ToggleGroup, {
|
|
175
|
+
transition: false,
|
|
176
|
+
summary: "This is the summary section",
|
|
177
|
+
toggleLabel: "This is the toggleLabel"
|
|
178
|
+
}, "This is the details section"))),
|
|
179
|
+
container = _render8.container;
|
|
180
|
+
const axeCheck = await runAxeCheck(container);
|
|
181
|
+
expect(axeCheck).toBe(true);
|
|
182
|
+
});
|
|
183
|
+
it('focuses with the focus helper', async () => {
|
|
184
|
+
var _toggleRef;
|
|
185
|
+
let toggleRef;
|
|
186
|
+
const _render9 = render(/*#__PURE__*/React.createElement(ToggleGroup, {
|
|
187
|
+
"data-testId": "toggle-group",
|
|
188
|
+
transition: false,
|
|
189
|
+
summary: "This is the summary section",
|
|
190
|
+
toggleLabel: "This is the toggleLabel",
|
|
191
|
+
ref: el => {
|
|
192
|
+
toggleRef = el;
|
|
193
|
+
}
|
|
194
|
+
}, "This is the details section")),
|
|
195
|
+
container = _render9.container;
|
|
196
|
+
const toggle = container.querySelector('button');
|
|
197
|
+
expect(document.activeElement).not.toBe(toggle);
|
|
198
|
+
(_toggleRef = toggleRef) === null || _toggleRef === void 0 ? void 0 : _toggleRef.focus();
|
|
199
|
+
expect(document.activeElement).toBe(toggle);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
7
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
8
|
+
var _vitest = require("vitest");
|
|
9
|
+
require("@testing-library/jest-dom");
|
|
10
|
+
var _index = require("../index");
|
|
11
|
+
var _ToggleDetails, _ToggleDetails2, _ToggleDetails3, _ToggleDetails4, _ToggleDetails5, _ToggleDetails6, _ToggleDetails7, _ToggleDetails8;
|
|
12
|
+
/*
|
|
13
|
+
* The MIT License (MIT)
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
16
|
+
*
|
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
* in the Software without restriction, including without limitation the rights
|
|
20
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
* furnished to do so, subject to the following conditions:
|
|
23
|
+
*
|
|
24
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
25
|
+
* copies or substantial portions of the Software.
|
|
26
|
+
*
|
|
27
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
|
+
* SOFTWARE.
|
|
34
|
+
*/
|
|
35
|
+
describe('<ToggleDetails />', () => {
|
|
36
|
+
let consoleWarningMock;
|
|
37
|
+
let consoleErrorMock;
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
// Mocking console to prevent test output pollution
|
|
40
|
+
consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
41
|
+
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
42
|
+
});
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
consoleWarningMock.mockRestore();
|
|
45
|
+
consoleErrorMock.mockRestore();
|
|
46
|
+
});
|
|
47
|
+
it('should hide its content', async () => {
|
|
48
|
+
(0, _react2.render)(_ToggleDetails || (_ToggleDetails = /*#__PURE__*/_react.default.createElement(_index.ToggleDetails, {
|
|
49
|
+
summary: "Click me"
|
|
50
|
+
}, "Content")));
|
|
51
|
+
const content = _react2.screen.queryByText('Content');
|
|
52
|
+
expect(content).not.toBeInTheDocument();
|
|
53
|
+
});
|
|
54
|
+
it('should place the icon after the summary when prop is set', async () => {
|
|
55
|
+
const _render = (0, _react2.render)(_ToggleDetails2 || (_ToggleDetails2 = /*#__PURE__*/_react.default.createElement(_index.ToggleDetails, {
|
|
56
|
+
iconPosition: "end",
|
|
57
|
+
summary: "Click me"
|
|
58
|
+
}, "Content"))),
|
|
59
|
+
container = _render.container;
|
|
60
|
+
const summary = container.querySelector('[class$="-toggleDetails__summaryText"]');
|
|
61
|
+
const icon = container.querySelector('[class$="-toggleDetails__icon"]');
|
|
62
|
+
expect(icon === null || icon === void 0 ? void 0 : icon.previousSibling).toBe(summary);
|
|
63
|
+
});
|
|
64
|
+
it('should have an aria-controls attribute', async () => {
|
|
65
|
+
const _render2 = (0, _react2.render)(_ToggleDetails3 || (_ToggleDetails3 = /*#__PURE__*/_react.default.createElement(_index.ToggleDetails, {
|
|
66
|
+
summary: "Click me"
|
|
67
|
+
}, "Details"))),
|
|
68
|
+
container = _render2.container;
|
|
69
|
+
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
70
|
+
const content = container.querySelector('[class$="-toggleDetails__details"]');
|
|
71
|
+
expect(toggle).toHaveAttribute('aria-controls', content === null || content === void 0 ? void 0 : content.id);
|
|
72
|
+
});
|
|
73
|
+
it('should have an aria-expanded attribute', async () => {
|
|
74
|
+
const _render3 = (0, _react2.render)(_ToggleDetails4 || (_ToggleDetails4 = /*#__PURE__*/_react.default.createElement(_index.ToggleDetails, {
|
|
75
|
+
summary: "Click me"
|
|
76
|
+
}, "Details"))),
|
|
77
|
+
container = _render3.container;
|
|
78
|
+
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
79
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
80
|
+
});
|
|
81
|
+
it('should not have aria attributes when it has no children', async () => {
|
|
82
|
+
(0, _react2.render)(_ToggleDetails5 || (_ToggleDetails5 = /*#__PURE__*/_react.default.createElement(_index.ToggleDetails, {
|
|
83
|
+
summary: "Click me",
|
|
84
|
+
"data-testid": "td__0"
|
|
85
|
+
})));
|
|
86
|
+
const toggle = _react2.screen.getByTestId('td__0');
|
|
87
|
+
expect(toggle).not.toHaveAttribute('aria-controls');
|
|
88
|
+
expect(toggle).not.toHaveAttribute('aria-expanded');
|
|
89
|
+
});
|
|
90
|
+
it('should toggle on click events', async () => {
|
|
91
|
+
const _render4 = (0, _react2.render)(_ToggleDetails6 || (_ToggleDetails6 = /*#__PURE__*/_react.default.createElement(_index.ToggleDetails, {
|
|
92
|
+
summary: "Click me"
|
|
93
|
+
}, "Details"))),
|
|
94
|
+
container = _render4.container;
|
|
95
|
+
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
96
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
|
97
|
+
await _userEvent.default.click(_react2.screen.getByText('Click me'));
|
|
98
|
+
await (0, _react2.waitFor)(() => {
|
|
99
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
it('should call onToggle on click events', async () => {
|
|
103
|
+
const onToggle = _vitest.vi.fn();
|
|
104
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.ToggleDetails, {
|
|
105
|
+
summary: "Click me",
|
|
106
|
+
expanded: false,
|
|
107
|
+
onToggle: onToggle
|
|
108
|
+
}, "Details"));
|
|
109
|
+
await _userEvent.default.click(_react2.screen.getByText('Click me'));
|
|
110
|
+
await (0, _react2.waitFor)(() => {
|
|
111
|
+
const args = onToggle.mock.calls[0];
|
|
112
|
+
expect(onToggle).toHaveBeenCalledTimes(1);
|
|
113
|
+
expect(args[0].type).toBe('click');
|
|
114
|
+
expect(args[1]).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
it('should call onToggle on click events when it has no children', async () => {
|
|
118
|
+
const onToggle = _vitest.vi.fn();
|
|
119
|
+
(0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.ToggleDetails, {
|
|
120
|
+
summary: "Click me",
|
|
121
|
+
expanded: false,
|
|
122
|
+
onToggle: onToggle,
|
|
123
|
+
"data-testid": "td__1"
|
|
124
|
+
}));
|
|
125
|
+
const toggle = _react2.screen.getByTestId('td__1');
|
|
126
|
+
await _userEvent.default.click(toggle);
|
|
127
|
+
await (0, _react2.waitFor)(() => {
|
|
128
|
+
const args = onToggle.mock.calls[0];
|
|
129
|
+
expect(onToggle).toHaveBeenCalledTimes(1);
|
|
130
|
+
expect(args[0].type).toBe('click');
|
|
131
|
+
expect(args[1]).toBe(true);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
it('should be initialized by defaultExpanded prop', async () => {
|
|
135
|
+
const _render5 = (0, _react2.render)(_ToggleDetails7 || (_ToggleDetails7 = /*#__PURE__*/_react.default.createElement(_index.ToggleDetails, {
|
|
136
|
+
summary: "Click me",
|
|
137
|
+
defaultExpanded: true
|
|
138
|
+
}, "Content"))),
|
|
139
|
+
container = _render5.container;
|
|
140
|
+
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
141
|
+
const content = container.querySelector('[class$="-toggleDetails__details"]');
|
|
142
|
+
expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
|
143
|
+
expect(content).toHaveTextContent('Content');
|
|
144
|
+
});
|
|
145
|
+
it('should meet a11y standards', async () => {
|
|
146
|
+
const _render6 = (0, _react2.render)(_ToggleDetails8 || (_ToggleDetails8 = /*#__PURE__*/_react.default.createElement(_index.ToggleDetails, {
|
|
147
|
+
summary: "Click me"
|
|
148
|
+
}, "Content"))),
|
|
149
|
+
container = _render6.container;
|
|
150
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
151
|
+
expect(axeCheck).toBe(true);
|
|
152
|
+
});
|
|
153
|
+
it('focuses with the focus helper', async () => {
|
|
154
|
+
var _toggleRef;
|
|
155
|
+
let toggleRef;
|
|
156
|
+
const _render7 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.ToggleDetails, {
|
|
157
|
+
summary: "Click me",
|
|
158
|
+
ref: el => {
|
|
159
|
+
toggleRef = el;
|
|
160
|
+
}
|
|
161
|
+
}, "Content")),
|
|
162
|
+
container = _render7.container;
|
|
163
|
+
const toggle = container.querySelector('[class$="-toggleDetails__toggle"]');
|
|
164
|
+
expect(document.activeElement).not.toBe(toggle);
|
|
165
|
+
(_toggleRef = toggleRef) === null || _toggleRef === void 0 ? void 0 : _toggleRef.focus();
|
|
166
|
+
expect(document.activeElement).toBe(toggle);
|
|
167
|
+
});
|
|
168
|
+
});
|