From 136f6471ae5b3b35b22abbddb56a8881250b2c8a Mon Sep 17 00:00:00 2001
From: chad1008 <13856531+chad1008@users.noreply.github.com>
Date: Fri, 15 Dec 2023 15:02:34 -0500
Subject: [PATCH 1/2] add unit test
---
.../src/form-token-field/test/index.tsx | 34 +++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/packages/components/src/form-token-field/test/index.tsx b/packages/components/src/form-token-field/test/index.tsx
index 76e308d5993be..9482b597ae00f 100644
--- a/packages/components/src/form-token-field/test/index.tsx
+++ b/packages/components/src/form-token-field/test/index.tsx
@@ -741,6 +741,40 @@ describe( 'FormTokenField', () => {
] );
} );
+ it( 'should not render suggestions after the input is blurred', 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]' );
+
+ // Click the body, blurring the input.
+ await user.click( document.body );
+
+ expect( screen.queryByRole( 'listbox' ) ).not.toBeInTheDocument();
+ } );
+
it( 'should not render suggestions if the text input is not matching any of the suggestions', async () => {
const user = userEvent.setup();
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 2/2] 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();