|
10 | 10 | * governing permissions and limitations under the License.
|
11 | 11 | */
|
12 | 12 |
|
13 |
| -import {act, render, setupIntersectionObserverMock, within} from '@react-spectrum/test-utils-internal'; |
| 13 | +jest.mock('@react-aria/live-announcer'); |
| 14 | +import {act, pointerMap, render, setupIntersectionObserverMock, within} from '@react-spectrum/test-utils-internal'; |
| 15 | +import {announce} from '@react-aria/live-announcer'; |
14 | 16 | import {ComboBox, ComboBoxItem} from '../src';
|
15 | 17 | import React from 'react';
|
16 | 18 | import {User} from '@react-aria/test-utils';
|
| 19 | +import userEvent from '@testing-library/user-event'; |
17 | 20 |
|
18 | 21 | describe('Combobox', () => {
|
| 22 | + let user; |
19 | 23 | let testUtilUser = new User();
|
20 | 24 |
|
21 | 25 | beforeAll(function () {
|
22 | 26 | jest.useFakeTimers();
|
23 | 27 | jest.spyOn(window.HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(() => 100);
|
24 | 28 | jest.spyOn(window.HTMLElement.prototype, 'clientHeight', 'get').mockImplementation(() => 100);
|
| 29 | + user = userEvent.setup({delay: null, pointerMap}); |
25 | 30 | });
|
26 | 31 |
|
27 | 32 | afterEach(() => {
|
@@ -95,4 +100,26 @@ describe('Combobox', () => {
|
95 | 100 | // we want to leave that to user discretion
|
96 | 101 | expect(onLoadMore).toHaveBeenCalledTimes(2);
|
97 | 102 | });
|
| 103 | + |
| 104 | + it('should omit the laoder from the count of items', async () => { |
| 105 | + jest.spyOn(navigator, 'platform', 'get').mockImplementation(() => 'MacIntel'); |
| 106 | + let tree = render( |
| 107 | + <ComboBox label="test" loadingState="loadingMore"> |
| 108 | + <ComboBoxItem>Chocolate</ComboBoxItem> |
| 109 | + <ComboBoxItem>Mint</ComboBoxItem> |
| 110 | + <ComboBoxItem>Strawberry</ComboBoxItem> |
| 111 | + <ComboBoxItem>Vanilla</ComboBoxItem> |
| 112 | + <ComboBoxItem>Chocolate Chip Cookie Dough</ComboBoxItem> |
| 113 | + </ComboBox> |
| 114 | + ); |
| 115 | + |
| 116 | + let comboboxTester = testUtilUser.createTester('ComboBox', {root: tree.container, interactionType: 'mouse'}); |
| 117 | + await comboboxTester.open(); |
| 118 | + |
| 119 | + expect(announce).toHaveBeenLastCalledWith('5 options available.'); |
| 120 | + expect(within(comboboxTester.listbox!).getByRole('progressbar', {hidden: true})).toBeInTheDocument(); |
| 121 | + |
| 122 | + await user.keyboard('C'); |
| 123 | + expect(announce).toHaveBeenLastCalledWith('2 options available.'); |
| 124 | + }); |
98 | 125 | });
|
0 commit comments