From 333952bf915fb6a41a7d08d4350ce38238f2b11a Mon Sep 17 00:00:00 2001
From: chad1008 <13856531+chad1008@users.noreply.github.com>
Date: Fri, 15 Dec 2023 15:27:28 -0500
Subject: [PATCH] add tests for suggestion visibility after selection
---
.../src/form-token-field/test/index.tsx | 63 +++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/packages/components/src/form-token-field/test/index.tsx b/packages/components/src/form-token-field/test/index.tsx
index 9482b597ae00f..961214a574c90 100644
--- a/packages/components/src/form-token-field/test/index.tsx
+++ b/packages/components/src/form-token-field/test/index.tsx
@@ -741,6 +741,69 @@ describe( 'FormTokenField', () => {
] );
} );
+ it( 'should render suggestions after a selection is made when the `__experimentalExpandOnFocus` prop is set to `true`', async () => {
+ const user = userEvent.setup();
+
+ const onFocusSpy = jest.fn();
+
+ const suggestions = [ 'Green', 'Emerald', 'Seaweed' ];
+
+ render(
+ <>
+
+ >
+ );
+
+ const input = screen.getByRole( 'combobox' );
+
+ await user.type( input, 'ee' );
+
+ expectVisibleSuggestionsToBe( screen.getByRole( 'listbox' ), [
+ 'Green',
+ 'Seaweed',
+ ] );
+
+ // Select the first suggestion ("Green")
+ await user.keyboard( '[ArrowDown][Enter]' );
+
+ expect( screen.getByRole( 'listbox' ) ).toBeVisible();
+ } );
+
+ it( 'should not render suggestions after a selection is made when the `__experimentalExpandOnFocus` prop is set to `false` or not defined', async () => {
+ const user = userEvent.setup();
+
+ const onFocusSpy = jest.fn();
+
+ const suggestions = [ 'Green', 'Emerald', 'Seaweed' ];
+
+ render(
+ <>
+
+ >
+ );
+
+ const input = screen.getByRole( 'combobox' );
+
+ await user.type( input, 'ee' );
+
+ expectVisibleSuggestionsToBe( screen.getByRole( 'listbox' ), [
+ 'Green',
+ 'Seaweed',
+ ] );
+
+ // Select the first suggestion ("Green")
+ await user.keyboard( '[ArrowDown][Enter]' );
+
+ expect( screen.queryByRole( 'listbox' ) ).not.toBeInTheDocument();
+ } );
+
it( 'should not render suggestions after the input is blurred', async () => {
const user = userEvent.setup();