From 8a0490fb669ef8e9a43a965d0af0600006f76ab7 Mon Sep 17 00:00:00 2001 From: Mengnan Gong Date: Thu, 27 Jul 2023 14:21:31 +0800 Subject: [PATCH] Fix the query filter in the MyGroupsPicker The current implementation has filter `type=Group` which won't get any result from the catalog. I believe that the purpose of this component is to query `Group` kind entities: https://backstage.io/docs/features/software-catalog/descriptor-format#kind-group. Also fixed the tests to properly `await` the user events to avoid warnings like this: ``` console.error Warning: You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one. at printWarning (../../../node_modules/react-dom/cjs/react-dom-test-utils.development.js:67:30) at error (../../../node_modules/react-dom/cjs/react-dom-test-utils.development.js:43:5) at onDone (../../../node_modules/react-dom/cjs/react-dom-test-utils.development.js:1034:9) at ../../../node_modules/react-dom/cjs/react-dom-test-utils.development.js:1073:13 ``` Signed-off-by: Mengnan Gong --- .changeset/cold-numbers-sleep.md | 5 +++++ .../fields/MyGroupsPicker/MyGroupsPicker.test.tsx | 12 ++++++------ .../fields/MyGroupsPicker/MyGroupsPicker.tsx | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 .changeset/cold-numbers-sleep.md diff --git a/.changeset/cold-numbers-sleep.md b/.changeset/cold-numbers-sleep.md new file mode 100644 index 0000000000..ac53307b07 --- /dev/null +++ b/.changeset/cold-numbers-sleep.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder': patch +--- + +Fix the get entities query in the `MyGroupsPicker` to query the `kind=Group` entities. diff --git a/plugins/scaffolder/src/components/fields/MyGroupsPicker/MyGroupsPicker.test.tsx b/plugins/scaffolder/src/components/fields/MyGroupsPicker/MyGroupsPicker.test.tsx index 0bdfe5f153..099d6fa6ed 100644 --- a/plugins/scaffolder/src/components/fields/MyGroupsPicker/MyGroupsPicker.test.tsx +++ b/plugins/scaffolder/src/components/fields/MyGroupsPicker/MyGroupsPicker.test.tsx @@ -129,7 +129,7 @@ describe('', () => { expect(catalogApi.getEntities).toHaveBeenCalledWith({ filter: { - type: 'Group', + kind: 'Group', 'relations.hasMember': ['user:default/bob'], }, }); @@ -201,8 +201,8 @@ describe('', () => { // Simulate user input const inputField = getByRole('combobox'); - userEvent.click(inputField); - userEvent.type(inputField, 'group'); + await userEvent.click(inputField); + await userEvent.type(inputField, 'group'); // Wait for the dropdown elements to appear await waitFor(() => { @@ -257,8 +257,8 @@ describe('', () => { ); const inputField = getByRole('combobox'); - userEvent.click(inputField); - userEvent.type(inputField, 'group'); + await userEvent.click(inputField); + await userEvent.type(inputField, 'group'); await waitFor(() => { expect( @@ -267,7 +267,7 @@ describe('', () => { }); const option = getByRole('option', { name: 'My First Group' }); - userEvent.click(option); + await userEvent.click(option); await waitFor(() => { expect(onChange).toHaveBeenCalledTimes(1); diff --git a/plugins/scaffolder/src/components/fields/MyGroupsPicker/MyGroupsPicker.tsx b/plugins/scaffolder/src/components/fields/MyGroupsPicker/MyGroupsPicker.tsx index 28bc2b93fa..fefdd4230c 100644 --- a/plugins/scaffolder/src/components/fields/MyGroupsPicker/MyGroupsPicker.tsx +++ b/plugins/scaffolder/src/components/fields/MyGroupsPicker/MyGroupsPicker.tsx @@ -62,7 +62,7 @@ export const MyGroupsPicker = (props: MyGroupsPickerProps) => { const { items } = await catalogApi.getEntities({ filter: { - type: 'Group', + kind: 'Group', ['relations.hasMember']: [userEntityRef], }, });