@instructure/ui-options 10.12.1-snapshot-7 → 10.12.1-snapshot-9

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/es/Options/Item/__new-tests__/Item.test.js +177 -0
  3. package/es/Options/__new-tests__/Options.test.js +155 -0
  4. package/lib/Options/Item/__new-tests__/Item.test.js +179 -0
  5. package/lib/Options/__new-tests__/Options.test.js +156 -0
  6. package/package.json +17 -13
  7. package/src/Options/Item/__new-tests__/Item.test.tsx +213 -0
  8. package/src/Options/__new-tests__/Options.test.tsx +204 -0
  9. package/tsconfig.build.json +1 -1
  10. package/tsconfig.build.tsbuildinfo +1 -1
  11. package/types/Options/Item/__new-tests__/Item.test.d.ts +2 -0
  12. package/types/Options/Item/__new-tests__/Item.test.d.ts.map +1 -0
  13. package/types/Options/__new-tests__/Options.test.d.ts +2 -0
  14. package/types/Options/__new-tests__/Options.test.d.ts.map +1 -0
  15. package/es/Options/Item/OptionsItemLocator.js +0 -33
  16. package/es/Options/Item/locator.js +0 -26
  17. package/es/Options/OptionsLocator.js +0 -36
  18. package/es/Options/locator.js +0 -26
  19. package/lib/Options/Item/OptionsItemLocator.js +0 -39
  20. package/lib/Options/Item/locator.js +0 -37
  21. package/lib/Options/OptionsLocator.js +0 -42
  22. package/lib/Options/locator.js +0 -37
  23. package/src/Options/Item/OptionsItemLocator.ts +0 -34
  24. package/src/Options/Item/locator.ts +0 -27
  25. package/src/Options/OptionsLocator.ts +0 -37
  26. package/src/Options/locator.ts +0 -27
  27. package/types/Options/Item/OptionsItemLocator.d.ts +0 -320
  28. package/types/Options/Item/OptionsItemLocator.d.ts.map +0 -1
  29. package/types/Options/Item/locator.d.ts +0 -4
  30. package/types/Options/Item/locator.d.ts.map +0 -1
  31. package/types/Options/OptionsLocator.d.ts +0 -1085
  32. package/types/Options/OptionsLocator.d.ts.map +0 -1
  33. package/types/Options/locator.d.ts +0 -4
  34. package/types/Options/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.12.1-snapshot-7](https://github.com/instructure/instructure-ui/compare/v10.12.0...v10.12.1-snapshot-7) (2025-03-06)
6
+ ## [10.12.1-snapshot-9](https://github.com/instructure/instructure-ui/compare/v10.12.0...v10.12.1-snapshot-9) (2025-03-06)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-options
9
9
 
@@ -0,0 +1,177 @@
1
+ var _Item, _Item2, _Item3, _Item4, _Item5, _Item6, _Item7, _Item8, _Item9, _Item10, _Item11, _Item12;
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 { vi, expect } from 'vitest';
29
+ import userEvent from '@testing-library/user-event';
30
+ import '@testing-library/jest-dom';
31
+ import { IconCheckSolid } from '@instructure/ui-icons';
32
+ import { Options } from '../../index';
33
+ import { Item } from '../index';
34
+ describe('<Item />', () => {
35
+ it('should render', async () => {
36
+ const _render = render(_Item || (_Item = /*#__PURE__*/React.createElement(Item, null))),
37
+ container = _render.container;
38
+ const optionItem = container.querySelector('[class$="-optionItem"]');
39
+ expect(optionItem).toBeInTheDocument();
40
+ const optionItemContainer = optionItem.querySelector('[class$="-optionItem__container"]');
41
+ expect(optionItemContainer).toBeInTheDocument();
42
+ });
43
+ it('should not render as a list item by default', async () => {
44
+ const _render2 = render(_Item2 || (_Item2 = /*#__PURE__*/React.createElement(Item, null, "Hello World"))),
45
+ container = _render2.container;
46
+ const item = container.querySelector('[class$="-optionItem"]');
47
+ expect(item).toBeInTheDocument();
48
+ expect(item.tagName).not.toBe('LI');
49
+ });
50
+ it('should render designated tag if `as` prop is specified', async () => {
51
+ const _render3 = render(_Item3 || (_Item3 = /*#__PURE__*/React.createElement(Item, {
52
+ as: "li"
53
+ }, "Hello World"))),
54
+ container = _render3.container;
55
+ const item = container.querySelector('[class$="-optionItem"]');
56
+ expect(item).toBeInTheDocument();
57
+ expect(item.tagName).toBe('LI');
58
+ });
59
+ it('should render children properly', async () => {
60
+ const _render4 = render(_Item4 || (_Item4 = /*#__PURE__*/React.createElement(Item, null, /*#__PURE__*/React.createElement("span", {
61
+ id: "customContent"
62
+ }, "Hello World")))),
63
+ container = _render4.container;
64
+ const item = container.querySelector('[class$="-optionItem"]');
65
+ const customContent = item.querySelector('#customContent');
66
+ expect(customContent).toHaveTextContent('Hello World');
67
+ });
68
+ it('should render role attributes appropriately when given a role', async () => {
69
+ const _render5 = render(_Item5 || (_Item5 = /*#__PURE__*/React.createElement(Item, {
70
+ role: "option"
71
+ }, "Hello World"))),
72
+ container = _render5.container;
73
+ const item = container.querySelector('[class$="-optionItem"]');
74
+ const child = screen.getByRole('option');
75
+ expect(item).toHaveAttribute('role', 'none');
76
+ expect(child).toBeInTheDocument();
77
+ });
78
+ it('should render description properly', async () => {
79
+ const _render6 = render(_Item6 || (_Item6 = /*#__PURE__*/React.createElement(Item, {
80
+ description: "Some text as description"
81
+ }, /*#__PURE__*/React.createElement("span", {
82
+ id: "customContent"
83
+ }, "Hello World")))),
84
+ container = _render6.container;
85
+ const item = container.querySelector('[class$="-optionItem"]');
86
+ const customContent = item.querySelector('#customContent');
87
+ const description = item.querySelector('[class$="__description"]');
88
+ expect(customContent).toHaveTextContent('Hello World');
89
+ expect(description).toHaveTextContent('Some text as description');
90
+ });
91
+ it('should render role attributes for description', async () => {
92
+ render(_Item7 || (_Item7 = /*#__PURE__*/React.createElement(Item, {
93
+ description: "Some text as description",
94
+ descriptionRole: "comment"
95
+ }, "Hello World")));
96
+ const description = screen.getByRole('comment');
97
+ expect(description).toBeInTheDocument();
98
+ expect(description).toHaveTextContent('Some text as description');
99
+ });
100
+ it('should pass props through to label', async () => {
101
+ const _render7 = render(_Item8 || (_Item8 = /*#__PURE__*/React.createElement(Item, {
102
+ role: "option",
103
+ tabIndex: -1,
104
+ "data-custom-attr": "true"
105
+ }, "Hello World"))),
106
+ container = _render7.container;
107
+ const optionItem = container.querySelector('[class$="-optionItem"]');
108
+ const optionItemContainer = optionItem.querySelector('[class$="-optionItem__container"]');
109
+ expect(optionItem).toHaveRole('none');
110
+ expect(optionItemContainer).toHaveRole('option');
111
+ expect(optionItemContainer).toHaveAttribute('tabindex', '-1');
112
+ expect(optionItemContainer).toHaveAttribute('data-custom-attr', 'true');
113
+ });
114
+ it('should pass event handlers through to label', async () => {
115
+ const onClick = vi.fn();
116
+ const _render8 = render(/*#__PURE__*/React.createElement(Item, {
117
+ onClick: onClick
118
+ }, "Hello World")),
119
+ container = _render8.container;
120
+ const optionItem = container.querySelector('[class$="-optionItem"]');
121
+ const optionItemContainer = container.querySelector('[class$="-optionItem__container"]');
122
+ userEvent.click(optionItem);
123
+ await waitFor(() => {
124
+ expect(onClick).not.toHaveBeenCalled();
125
+ });
126
+ userEvent.click(optionItemContainer);
127
+ await waitFor(() => {
128
+ expect(onClick).toHaveBeenCalledTimes(1);
129
+ });
130
+ });
131
+ it('should render content before label', async () => {
132
+ const _render9 = render(_Item9 || (_Item9 = /*#__PURE__*/React.createElement(Item, {
133
+ renderBeforeLabel: /*#__PURE__*/React.createElement(IconCheckSolid, null)
134
+ }, "Hello World"))),
135
+ container = _render9.container;
136
+ const content = container.querySelector('[class$=-optionItem__content--before]');
137
+ expect(content).toBeInTheDocument();
138
+ const icon = content.querySelector('svg[name="IconCheck"]');
139
+ expect(icon).toBeInTheDocument();
140
+ });
141
+ it('should render content after label', async () => {
142
+ const _render10 = render(_Item10 || (_Item10 = /*#__PURE__*/React.createElement(Item, {
143
+ renderAfterLabel: /*#__PURE__*/React.createElement(IconCheckSolid, null)
144
+ }, "Hello World"))),
145
+ container = _render10.container;
146
+ const content = container.querySelector('[class$=-optionItem__content--after]');
147
+ expect(content).toBeInTheDocument();
148
+ const icon = content.querySelector('svg[name="IconCheck"]');
149
+ expect(icon).toBeInTheDocument();
150
+ });
151
+ it('should render nested lists', async () => {
152
+ const _render11 = render(_Item11 || (_Item11 = /*#__PURE__*/React.createElement(Item, null, /*#__PURE__*/React.createElement(Options, {
153
+ as: "ul",
154
+ renderLabel: 'Nested list'
155
+ }, /*#__PURE__*/React.createElement(Item, null, "Sub item"))))),
156
+ container = _render11.container;
157
+ const item = container.querySelector('span[class$="-optionItem"]');
158
+ expect(item).toBeInTheDocument();
159
+ const options = item.querySelector('div[class$="-options"]');
160
+ expect(options).toBeInTheDocument();
161
+ const nestedList = options.querySelector('ul');
162
+ const nestedItem = options.querySelector('li[class$="-optionItem"]');
163
+ expect(nestedList).toBeInTheDocument();
164
+ expect(nestedItem).toBeInTheDocument();
165
+ expect(nestedItem).toHaveTextContent('Sub item');
166
+ });
167
+ it('should render as link with href prop', async () => {
168
+ const _render12 = render(_Item12 || (_Item12 = /*#__PURE__*/React.createElement(Item, {
169
+ href: "/helloWorld"
170
+ }, "Hello World"))),
171
+ container = _render12.container;
172
+ const link = container.querySelector('[class$="-optionItem__container"]');
173
+ expect(link).toBeInTheDocument();
174
+ expect(link).toHaveAttribute('href', '/helloWorld');
175
+ expect(link === null || link === void 0 ? void 0 : link.tagName).toBe('A');
176
+ });
177
+ });
@@ -0,0 +1,155 @@
1
+ var _Options, _Options2, _Options$Item, _Options$Item2, _Options3, _Options4, _Options5, _Options6, _Options7, _Options8, _Options9;
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 } from '@testing-library/react';
28
+ import { vi, expect } from 'vitest';
29
+ import { runAxeCheck } from '@instructure/ui-axe-check';
30
+
31
+ // eslint-disable-next-line no-restricted-imports
32
+ import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
33
+ import '@testing-library/jest-dom';
34
+ import { Options } from '../index';
35
+ import OptionsExamples from '../__examples__/Options.examples';
36
+ describe('<Options />', () => {
37
+ it('should render', async () => {
38
+ const _render = render(_Options || (_Options = /*#__PURE__*/React.createElement(Options, null))),
39
+ container = _render.container;
40
+ const options = container.querySelector('div[class$="-options"]');
41
+ expect(options).toBeInTheDocument();
42
+ });
43
+ it('should render items', async () => {
44
+ render(_Options2 || (_Options2 = /*#__PURE__*/React.createElement(Options, null, /*#__PURE__*/React.createElement(Options.Item, null, "Option one"), /*#__PURE__*/React.createElement(Options.Item, null, "Option two"))));
45
+ const items = screen.getAllByRole('listitem');
46
+ expect(items.length).toBe(2);
47
+ });
48
+ it('should provide elementRef', async () => {
49
+ const elementRef = vi.fn();
50
+ render(/*#__PURE__*/React.createElement(Options, {
51
+ elementRef: elementRef,
52
+ as: "ul"
53
+ }, _Options$Item || (_Options$Item = /*#__PURE__*/React.createElement(Options.Item, null, "Option one")), _Options$Item2 || (_Options$Item2 = /*#__PURE__*/React.createElement(Options.Item, null, "Option two"))));
54
+ const optionList = screen.getByRole('list');
55
+ expect(elementRef).toHaveBeenCalledWith(optionList);
56
+ });
57
+ it('should render designated tag if `as` prop is specified', async () => {
58
+ render(_Options3 || (_Options3 = /*#__PURE__*/React.createElement(Options, {
59
+ as: "ol"
60
+ }, /*#__PURE__*/React.createElement(Options.Item, null, "Option one"), /*#__PURE__*/React.createElement(Options.Item, null, "Option two"))));
61
+ const optionList = screen.getByRole('list');
62
+ expect(optionList.tagName).toBe('OL');
63
+ });
64
+ it('should render children as listitems when appropriate', async () => {
65
+ const _render2 = render(_Options4 || (_Options4 = /*#__PURE__*/React.createElement(Options, {
66
+ as: "ul"
67
+ }, /*#__PURE__*/React.createElement(Options.Item, null, "Option one"), /*#__PURE__*/React.createElement(Options.Item, null, "Option two")))),
68
+ container = _render2.container;
69
+ const list = container.querySelector('ul');
70
+ const items = container.querySelectorAll('li');
71
+ expect(list).toBeInTheDocument();
72
+ expect(items.length).toBe(2);
73
+ });
74
+ it('should pass props through to list', async () => {
75
+ const _render3 = render(_Options5 || (_Options5 = /*#__PURE__*/React.createElement(Options, {
76
+ as: "ul",
77
+ role: "listbox",
78
+ "data-custom-attr": "true"
79
+ }, /*#__PURE__*/React.createElement(Options.Item, null, "Option one"), /*#__PURE__*/React.createElement(Options.Item, null, "Option two")))),
80
+ container = _render3.container;
81
+ const options = container.querySelector('[class$="-options__list"]');
82
+ expect(options).toHaveRole('listbox');
83
+ expect(options).toHaveAttribute('data-custom-attr', 'true');
84
+ });
85
+ it('should render root with appropriate role', async () => {
86
+ const _render4 = render(_Options6 || (_Options6 = /*#__PURE__*/React.createElement(Options, {
87
+ role: "listbox"
88
+ }, /*#__PURE__*/React.createElement(Options.Item, null, "Option one"), /*#__PURE__*/React.createElement(Options.Item, null, "Option two")))),
89
+ container = _render4.container;
90
+ const options = container.querySelector('div[class$="-options"]');
91
+ expect(options).toHaveAttribute('role', 'presentation');
92
+ });
93
+ it('should allow null children', async () => {
94
+ render(_Options7 || (_Options7 = /*#__PURE__*/React.createElement(Options, null)));
95
+ const options = screen.getByRole('list');
96
+ expect(options).toBeInTheDocument();
97
+ });
98
+ it('should render nested options properly', async () => {
99
+ const _render5 = render(_Options8 || (_Options8 = /*#__PURE__*/React.createElement(Options, {
100
+ "data-testId": "outer-list"
101
+ }, /*#__PURE__*/React.createElement(Options.Item, null, "Option one "), /*#__PURE__*/React.createElement(Options.Item, null, "Option two "), /*#__PURE__*/React.createElement(Options, {
102
+ renderLabel: 'Nested list',
103
+ "data-testId": "nested-list"
104
+ }, /*#__PURE__*/React.createElement(Options.Item, null, "Nested option one "), /*#__PURE__*/React.createElement(Options.Item, null, "Nested option two "))))),
105
+ container = _render5.container;
106
+ const allLists = container.querySelectorAll('[class$="-options__list"]');
107
+ const allItems = container.querySelectorAll('[class$="-optionItem"]');
108
+ expect(allLists.length).toBe(2);
109
+ expect(allItems.length).toBe(5);
110
+ const outerList = screen.getByTestId('outer-list');
111
+ expect(outerList).toHaveTextContent('Option one Option two');
112
+ const nestedLabel = outerList.querySelector('[class$=-options__label]');
113
+ expect(nestedLabel).toBeInTheDocument();
114
+ expect(nestedLabel).toHaveTextContent('Nested list');
115
+ const nestedList = screen.getByTestId('nested-list');
116
+ expect(nestedList).toHaveTextContent('Nested option one Nested option two');
117
+ const nestedListItems = nestedList.querySelectorAll('[class$=-optionItem]');
118
+ expect(nestedListItems.length).toBe(2);
119
+ expect(outerList).toContainElement(nestedLabel);
120
+ expect(outerList).toContainElement(nestedList);
121
+ });
122
+ describe('with generated examples', () => {
123
+ const generatedComponents = generateA11yTests(Options, OptionsExamples);
124
+ for (const component of generatedComponents) {
125
+ it(component.description, async () => {
126
+ const _render6 = render(component.content),
127
+ container = _render6.container;
128
+
129
+ // axe-check is more strict now, and expects "list" role to have "listitem" children, but we use "role='none'" children. After discussing it with the A11y team, we agreed to ignore this error because the screen readers can read the component perfectly.
130
+ // TODO: try to remove this ignore if axe-check is updated and isn't this strict anymore
131
+ // https://dequeuniversity.com/rules/axe/4.6/aria-required-children?application=axeAPI
132
+ const axeCheck = await runAxeCheck(container, {
133
+ ignores: ['aria-required-children']
134
+ });
135
+ expect(axeCheck).toBe(true);
136
+ });
137
+ }
138
+ });
139
+ describe('for a11y', () => {
140
+ it('should be accessible with links', async () => {
141
+ const _render7 = render(_Options9 || (_Options9 = /*#__PURE__*/React.createElement(Options, null, /*#__PURE__*/React.createElement(Options.Item, null, "Option"), /*#__PURE__*/React.createElement(Options.Item, {
142
+ href: "/"
143
+ }, "Option link")))),
144
+ container = _render7.container;
145
+
146
+ // axe-check is more strict now, and expects "list" role to have "listitem" children, but we use "role='none'" children. After discussing it with the A11y team, we agreed to ignore this error because the screen readers can read the component perfectly.
147
+ // TODO: try to remove this ignore if axe-check is updated and isn't this strict anymore
148
+ // https://dequeuniversity.com/rules/axe/4.6/aria-required-children?application=axeAPI
149
+ const axeCheck = await runAxeCheck(container, {
150
+ ignores: ['aria-required-children']
151
+ });
152
+ expect(axeCheck).toBe(true);
153
+ });
154
+ });
155
+ });
@@ -0,0 +1,179 @@
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 _vitest = require("vitest");
7
+ var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
8
+ require("@testing-library/jest-dom");
9
+ var _uiIcons = require("@instructure/ui-icons");
10
+ var _index = require("../../index");
11
+ var _index2 = require("../index");
12
+ var _Item, _Item2, _Item3, _Item4, _Item5, _Item6, _Item7, _Item8, _Item9, _Item10, _Item11, _Item12;
13
+ /*
14
+ * The MIT License (MIT)
15
+ *
16
+ * Copyright (c) 2015 - present Instructure, Inc.
17
+ *
18
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
19
+ * of this software and associated documentation files (the "Software"), to deal
20
+ * in the Software without restriction, including without limitation the rights
21
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22
+ * copies of the Software, and to permit persons to whom the Software is
23
+ * furnished to do so, subject to the following conditions:
24
+ *
25
+ * The above copyright notice and this permission notice shall be included in all
26
+ * copies or substantial portions of the Software.
27
+ *
28
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34
+ * SOFTWARE.
35
+ */
36
+ describe('<Item />', () => {
37
+ it('should render', async () => {
38
+ const _render = (0, _react2.render)(_Item || (_Item = /*#__PURE__*/_react.default.createElement(_index2.Item, null))),
39
+ container = _render.container;
40
+ const optionItem = container.querySelector('[class$="-optionItem"]');
41
+ (0, _vitest.expect)(optionItem).toBeInTheDocument();
42
+ const optionItemContainer = optionItem.querySelector('[class$="-optionItem__container"]');
43
+ (0, _vitest.expect)(optionItemContainer).toBeInTheDocument();
44
+ });
45
+ it('should not render as a list item by default', async () => {
46
+ const _render2 = (0, _react2.render)(_Item2 || (_Item2 = /*#__PURE__*/_react.default.createElement(_index2.Item, null, "Hello World"))),
47
+ container = _render2.container;
48
+ const item = container.querySelector('[class$="-optionItem"]');
49
+ (0, _vitest.expect)(item).toBeInTheDocument();
50
+ (0, _vitest.expect)(item.tagName).not.toBe('LI');
51
+ });
52
+ it('should render designated tag if `as` prop is specified', async () => {
53
+ const _render3 = (0, _react2.render)(_Item3 || (_Item3 = /*#__PURE__*/_react.default.createElement(_index2.Item, {
54
+ as: "li"
55
+ }, "Hello World"))),
56
+ container = _render3.container;
57
+ const item = container.querySelector('[class$="-optionItem"]');
58
+ (0, _vitest.expect)(item).toBeInTheDocument();
59
+ (0, _vitest.expect)(item.tagName).toBe('LI');
60
+ });
61
+ it('should render children properly', async () => {
62
+ const _render4 = (0, _react2.render)(_Item4 || (_Item4 = /*#__PURE__*/_react.default.createElement(_index2.Item, null, /*#__PURE__*/_react.default.createElement("span", {
63
+ id: "customContent"
64
+ }, "Hello World")))),
65
+ container = _render4.container;
66
+ const item = container.querySelector('[class$="-optionItem"]');
67
+ const customContent = item.querySelector('#customContent');
68
+ (0, _vitest.expect)(customContent).toHaveTextContent('Hello World');
69
+ });
70
+ it('should render role attributes appropriately when given a role', async () => {
71
+ const _render5 = (0, _react2.render)(_Item5 || (_Item5 = /*#__PURE__*/_react.default.createElement(_index2.Item, {
72
+ role: "option"
73
+ }, "Hello World"))),
74
+ container = _render5.container;
75
+ const item = container.querySelector('[class$="-optionItem"]');
76
+ const child = _react2.screen.getByRole('option');
77
+ (0, _vitest.expect)(item).toHaveAttribute('role', 'none');
78
+ (0, _vitest.expect)(child).toBeInTheDocument();
79
+ });
80
+ it('should render description properly', async () => {
81
+ const _render6 = (0, _react2.render)(_Item6 || (_Item6 = /*#__PURE__*/_react.default.createElement(_index2.Item, {
82
+ description: "Some text as description"
83
+ }, /*#__PURE__*/_react.default.createElement("span", {
84
+ id: "customContent"
85
+ }, "Hello World")))),
86
+ container = _render6.container;
87
+ const item = container.querySelector('[class$="-optionItem"]');
88
+ const customContent = item.querySelector('#customContent');
89
+ const description = item.querySelector('[class$="__description"]');
90
+ (0, _vitest.expect)(customContent).toHaveTextContent('Hello World');
91
+ (0, _vitest.expect)(description).toHaveTextContent('Some text as description');
92
+ });
93
+ it('should render role attributes for description', async () => {
94
+ (0, _react2.render)(_Item7 || (_Item7 = /*#__PURE__*/_react.default.createElement(_index2.Item, {
95
+ description: "Some text as description",
96
+ descriptionRole: "comment"
97
+ }, "Hello World")));
98
+ const description = _react2.screen.getByRole('comment');
99
+ (0, _vitest.expect)(description).toBeInTheDocument();
100
+ (0, _vitest.expect)(description).toHaveTextContent('Some text as description');
101
+ });
102
+ it('should pass props through to label', async () => {
103
+ const _render7 = (0, _react2.render)(_Item8 || (_Item8 = /*#__PURE__*/_react.default.createElement(_index2.Item, {
104
+ role: "option",
105
+ tabIndex: -1,
106
+ "data-custom-attr": "true"
107
+ }, "Hello World"))),
108
+ container = _render7.container;
109
+ const optionItem = container.querySelector('[class$="-optionItem"]');
110
+ const optionItemContainer = optionItem.querySelector('[class$="-optionItem__container"]');
111
+ (0, _vitest.expect)(optionItem).toHaveRole('none');
112
+ (0, _vitest.expect)(optionItemContainer).toHaveRole('option');
113
+ (0, _vitest.expect)(optionItemContainer).toHaveAttribute('tabindex', '-1');
114
+ (0, _vitest.expect)(optionItemContainer).toHaveAttribute('data-custom-attr', 'true');
115
+ });
116
+ it('should pass event handlers through to label', async () => {
117
+ const onClick = _vitest.vi.fn();
118
+ const _render8 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index2.Item, {
119
+ onClick: onClick
120
+ }, "Hello World")),
121
+ container = _render8.container;
122
+ const optionItem = container.querySelector('[class$="-optionItem"]');
123
+ const optionItemContainer = container.querySelector('[class$="-optionItem__container"]');
124
+ _userEvent.default.click(optionItem);
125
+ await (0, _react2.waitFor)(() => {
126
+ (0, _vitest.expect)(onClick).not.toHaveBeenCalled();
127
+ });
128
+ _userEvent.default.click(optionItemContainer);
129
+ await (0, _react2.waitFor)(() => {
130
+ (0, _vitest.expect)(onClick).toHaveBeenCalledTimes(1);
131
+ });
132
+ });
133
+ it('should render content before label', async () => {
134
+ const _render9 = (0, _react2.render)(_Item9 || (_Item9 = /*#__PURE__*/_react.default.createElement(_index2.Item, {
135
+ renderBeforeLabel: /*#__PURE__*/_react.default.createElement(_uiIcons.IconCheckSolid, null)
136
+ }, "Hello World"))),
137
+ container = _render9.container;
138
+ const content = container.querySelector('[class$=-optionItem__content--before]');
139
+ (0, _vitest.expect)(content).toBeInTheDocument();
140
+ const icon = content.querySelector('svg[name="IconCheck"]');
141
+ (0, _vitest.expect)(icon).toBeInTheDocument();
142
+ });
143
+ it('should render content after label', async () => {
144
+ const _render10 = (0, _react2.render)(_Item10 || (_Item10 = /*#__PURE__*/_react.default.createElement(_index2.Item, {
145
+ renderAfterLabel: /*#__PURE__*/_react.default.createElement(_uiIcons.IconCheckSolid, null)
146
+ }, "Hello World"))),
147
+ container = _render10.container;
148
+ const content = container.querySelector('[class$=-optionItem__content--after]');
149
+ (0, _vitest.expect)(content).toBeInTheDocument();
150
+ const icon = content.querySelector('svg[name="IconCheck"]');
151
+ (0, _vitest.expect)(icon).toBeInTheDocument();
152
+ });
153
+ it('should render nested lists', async () => {
154
+ const _render11 = (0, _react2.render)(_Item11 || (_Item11 = /*#__PURE__*/_react.default.createElement(_index2.Item, null, /*#__PURE__*/_react.default.createElement(_index.Options, {
155
+ as: "ul",
156
+ renderLabel: 'Nested list'
157
+ }, /*#__PURE__*/_react.default.createElement(_index2.Item, null, "Sub item"))))),
158
+ container = _render11.container;
159
+ const item = container.querySelector('span[class$="-optionItem"]');
160
+ (0, _vitest.expect)(item).toBeInTheDocument();
161
+ const options = item.querySelector('div[class$="-options"]');
162
+ (0, _vitest.expect)(options).toBeInTheDocument();
163
+ const nestedList = options.querySelector('ul');
164
+ const nestedItem = options.querySelector('li[class$="-optionItem"]');
165
+ (0, _vitest.expect)(nestedList).toBeInTheDocument();
166
+ (0, _vitest.expect)(nestedItem).toBeInTheDocument();
167
+ (0, _vitest.expect)(nestedItem).toHaveTextContent('Sub item');
168
+ });
169
+ it('should render as link with href prop', async () => {
170
+ const _render12 = (0, _react2.render)(_Item12 || (_Item12 = /*#__PURE__*/_react.default.createElement(_index2.Item, {
171
+ href: "/helloWorld"
172
+ }, "Hello World"))),
173
+ container = _render12.container;
174
+ const link = container.querySelector('[class$="-optionItem__container"]');
175
+ (0, _vitest.expect)(link).toBeInTheDocument();
176
+ (0, _vitest.expect)(link).toHaveAttribute('href', '/helloWorld');
177
+ (0, _vitest.expect)(link === null || link === void 0 ? void 0 : link.tagName).toBe('A');
178
+ });
179
+ });