Skip to content

Commit c118a44

Browse files
committed
chore(@clayui/autocomplete): LPD-55597 Simplify announcement-related tests into a single test
1 parent 5e49a25 commit c118a44

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

packages/clay-autocomplete/src/__tests__/IncrementalInteractions.tsx

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -787,50 +787,21 @@ describe('Autocomplete incremental interactions', () => {
787787
});
788788
});
789789

790-
it('announces the initial amount of items', async () => {
791-
const itemsCount = 5;
792-
793-
const {getAllByRole, getByRole} = render(
794-
<ClayAutocomplete onLoadMore={() => Promise.resolve()}>
795-
{Array(itemsCount)
796-
.fill(0)
797-
.map((_, index) => (
798-
<ClayAutocomplete.Item
799-
key={index}
800-
textValue={`Item ${index + 1}`}
801-
>
802-
Item {index + 1}
803-
</ClayAutocomplete.Item>
804-
))}
805-
</ClayAutocomplete>
806-
);
807-
808-
const combobox = getByRole('combobox');
809-
810-
userEvent.click(combobox);
811-
812-
userEvent.type(combobox, '{arrowdown}');
813-
814-
const [announcer] = getAllByRole('log');
815-
816-
await waitFor(() => {
817-
expect(announcer?.innerHTML).toContain(
818-
`${itemsCount} items loaded. Reach the last item to load more.`
819-
);
820-
});
821-
});
822-
823-
it('announces when more items are loaded', async () => {
790+
it('announces count of initially loaded items and when more items are loaded', async () => {
824791
const initialCount = 10;
792+
const step = 5;
825793

826794
const TestComponent = () => {
795+
const [count, setCount] = React.useState(initialCount);
827796
const [networkStatus, setNetworkStatus] =
828797
React.useState<NetworkStatus>(NetworkStatus.Unused);
829798

830799
const onLoadMore = jest.fn().mockImplementation(() => {
831800
return new Promise<void>((resolve) => {
832801
setNetworkStatus(NetworkStatus.Loading);
802+
833803
setTimeout(() => {
804+
setCount((count) => count + step);
834805
setNetworkStatus(NetworkStatus.Unused);
835806
resolve();
836807
}, 100);
@@ -842,7 +813,7 @@ describe('Autocomplete incremental interactions', () => {
842813
loadingState={networkStatus}
843814
onLoadMore={onLoadMore}
844815
>
845-
{Array(initialCount)
816+
{Array(count)
846817
.fill(0)
847818
.map((_, index) => (
848819
<ClayAutocomplete.Item
@@ -862,15 +833,23 @@ describe('Autocomplete incremental interactions', () => {
862833

863834
userEvent.click(combobox);
864835

865-
userEvent.type(combobox, '{arrowup}');
836+
userEvent.type(combobox, '{arrowdown}');
866837

867838
const [announcer] = getAllByRole('log');
868839

840+
await waitFor(() => {
841+
expect(announcer?.innerHTML).toContain(
842+
`${initialCount} items loaded. Reach the last item to load more.`
843+
);
844+
});
845+
846+
userEvent.type(combobox, '{arrowup}');
847+
869848
await waitFor(() => {
870849
expect(announcer?.innerHTML).toContain(`Loading more items.`);
871850

872851
expect(announcer?.innerHTML).toContain(
873-
`${initialCount} items loaded.`
852+
`${initialCount + step} items loaded.`
874853
);
875854
});
876855
});

0 commit comments

Comments
 (0)