Skip to content

Commit 63db21e

Browse files
committed
update getItemCount so it doesnt include loaders in custom announcements
1 parent 7c5f1e8 commit 63db21e

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

packages/@react-spectrum/s2/test/Combobox.test.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

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';
1416
import {ComboBox, ComboBoxItem} from '../src';
1517
import React from 'react';
1618
import {User} from '@react-aria/test-utils';
19+
import userEvent from '@testing-library/user-event';
1720

1821
describe('Combobox', () => {
22+
let user;
1923
let testUtilUser = new User();
2024

2125
beforeAll(function () {
2226
jest.useFakeTimers();
2327
jest.spyOn(window.HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(() => 100);
2428
jest.spyOn(window.HTMLElement.prototype, 'clientHeight', 'get').mockImplementation(() => 100);
29+
user = userEvent.setup({delay: null, pointerMap});
2530
});
2631

2732
afterEach(() => {
@@ -95,4 +100,26 @@ describe('Combobox', () => {
95100
// we want to leave that to user discretion
96101
expect(onLoadMore).toHaveBeenCalledTimes(2);
97102
});
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+
});
98125
});

packages/@react-stately/collections/src/getItemCount.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function getItemCount<T>(collection: Collection<Node<T>>): number {
2727
for (let item of items) {
2828
if (item.type === 'section') {
2929
countItems(getChildNodes(item, collection));
30-
} else {
30+
} else if (item.type === 'item') {
3131
counter++;
3232
}
3333
}

0 commit comments

Comments
 (0)