From 4923367b4a5864cb3047c62caeaf6066a062ebf6 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Fri, 8 Nov 2024 14:28:28 -0500 Subject: [PATCH] fix(RHINENG-12310): Tag filter error on Reports page To reproduce: Go to https://console.redhat.com/insights/vulnerability/cves At top in 'Filter by tag' select a value with systems Navigate to https://console.redhat.com/insights/vulnerability/reports#SIDs=&tags= Select Create report Error is displayed The issue is that the `useSelector` on ReportsPage was not putting the tags into an array, AND if there were no tags, then it wasn't returning an empty array properly. Make sure to apply multiple variations of workloads, SAP IDs, and tags to make sure this feature works correctly. --- .../SmartComponents/Reports/ReportsPage.js | 3 ++- .../Reports/ReportsPage.test.js | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Components/SmartComponents/Reports/ReportsPage.js b/src/Components/SmartComponents/Reports/ReportsPage.js index 71cc3d756..0c473702c 100644 --- a/src/Components/SmartComponents/Reports/ReportsPage.js +++ b/src/Components/SmartComponents/Reports/ReportsPage.js @@ -36,7 +36,8 @@ const ReportsPage = () => { const [inheritGlobalTags, setInheritGlobalTags] = useState(true); const [cvesWithoutErrata, setCvesWithoutErrata] = useState(false); - const globalFilterTags = useSelector(({ ReportsPageStore }) => ReportsPageStore.parameters.tags) ?? []; + const globalFilterTags = useSelector(({ ReportsPageStore }) => + ReportsPageStore.parameters.tags?.length && ReportsPageStore.parameters.tags.split(',')) || []; const dispatch = useDispatch(); diff --git a/src/Components/SmartComponents/Reports/ReportsPage.test.js b/src/Components/SmartComponents/Reports/ReportsPage.test.js index e20c56b45..ff5854fe9 100644 --- a/src/Components/SmartComponents/Reports/ReportsPage.test.js +++ b/src/Components/SmartComponents/Reports/ReportsPage.test.js @@ -33,7 +33,7 @@ jest.mock("../../../Helpers/APIHelper.js", () => ({ getCveListByAccount: () => new Promise(() => {}, () => {}) })); -const state = { +let state = { parameters: {} } @@ -205,4 +205,22 @@ describe('Reports page component', () => { expect(screen.getByText(/systems: 1 or more conventional \(rpm\-dnf\), 1 or more immutable \(ostree\)/i)).toBeVisible(); }); + + it('Should apply global tags.', async () => { + state.parameters = { tags: "AAaNIKhDBt/LorNtSjoRt=WRTmPByfQ,BMCRfrl/kgWDqQYPT=KVdLiE" }; + render( + + + + ); + + await waitFor(() => { + fireEvent.click(screen.getByText(/create report/i)); + }); + + screen.logTestingPlaygroundURL(); + + expect(screen.getByText(/tags: aaanikhdbt: lorntsjort = wrtmpbyfq, bmcrfrl: kgwdqqypt = kvdlie/i)).toBeVisible(); + expect(screen.queryByText(/tags: all/i)).toBeFalsy(); + }); });