diff --git a/src/web/components/dashboard/display/__tests__/withFilterSelection.test.tsx b/src/web/components/dashboard/display/__tests__/withFilterSelection.test.tsx deleted file mode 100644 index 8db9561163..0000000000 --- a/src/web/components/dashboard/display/__tests__/withFilterSelection.test.tsx +++ /dev/null @@ -1,117 +0,0 @@ -/* SPDX-FileCopyrightText: 2026 Greenbone AG - * - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -import {describe, expect, test, testing} from '@gsa/testing'; -import {fireEvent, rendererWith, screen, waitFor} from 'web/testing'; -import type FilterType from 'gmp/models/filter/filter-type'; -import QueryFilter from 'gmp/models/filter/query-filter'; -import withFilterSelection from 'web/components/dashboard/display/withFilterSelection'; - -interface TestProps { - filter?: FilterType; - onSelectFilterClick?: () => void; - showFilterSelection?: boolean; - value?: string; -} - -const filtersFilter = QueryFilter.fromString('type=task'); - -const filters = [ - {id: 'f-1', name: 'Filter One'}, - {id: 'f-2', name: 'Filter Two'}, -]; - -const createGmp = () => ({ - filters: { - get: testing.fn().mockResolvedValue({ - data: filters, - meta: {filter: 'type=task', counts: {}}, - }), - }, -}); - -const TestComponent = ({ - filter, - onSelectFilterClick, - showFilterSelection, - value, -}: TestProps) => ( -
- {filter?.name ?? 'none'} - - {String(showFilterSelection)} - - {value} -
-); - -const WrappedComponent = withFilterSelection({filtersFilter})(TestComponent); - -describe('withFilterSelection tests', () => { - test('should render the wrapped component without filter selection by default', () => { - const gmp = createGmp(); - const {render: renderWithGmp} = rendererWith({gmp, store: true}); - - renderWithGmp(); - - expect(screen.queryByTestId('filter-selection')).not.toBeInTheDocument(); - expect(screen.getByTestId('filter')).toHaveTextContent('none'); - expect(screen.getByTestId('show-filter-selection')).toHaveTextContent( - 'false', - ); - expect(screen.getByTestId('value')).toHaveTextContent('value'); - }); - - test('should render FilterSelection and passes its selected filter', () => { - const gmp = createGmp(); - const {render: renderWithGmp} = rendererWith({gmp, store: true}); - - renderWithGmp(); - - expect(gmp.filters.get).toHaveBeenCalledWith({filter: filtersFilter}); - expect(screen.getByTestId('filter')).toHaveTextContent('none'); - expect(screen.getByTestId('show-filter-selection')).toHaveTextContent( - 'true', - ); - }); - - test('should pass FilterSelection callback to the wrapped component', () => { - const receivedCallback = testing.fn(); - const SelectableComponent = ({onSelectFilterClick}: TestProps) => { - receivedCallback(onSelectFilterClick); - return null; - }; - const WrappedSelectable = withFilterSelection({filtersFilter})( - SelectableComponent, - ); - - const gmp = createGmp(); - const {render: renderWithGmp} = rendererWith({gmp, store: true}); - - renderWithGmp(); - - expect(receivedCallback).toHaveBeenCalledWith(expect.any(Function)); - }); - - test('should open the real filter selection dialog through the injected callback', async () => { - const gmp = createGmp(); - const {render: renderWithGmp} = rendererWith({gmp, store: true}); - - renderWithGmp(); - - fireEvent.click(screen.getByTestId('select-filter')); - - await waitFor(() => { - expect(screen.getDialogTitle()).toHaveTextContent('Select Filter'); - }); - }); - - test('should set a descriptive display name', () => { - expect(WrappedComponent.displayName).toBe( - 'withFilterSelection(TestComponent)', - ); - }); -}); diff --git a/src/web/components/dashboard/display/withFilterSelection.tsx b/src/web/components/dashboard/display/withFilterSelection.tsx deleted file mode 100644 index 8bb7a82180..0000000000 --- a/src/web/components/dashboard/display/withFilterSelection.tsx +++ /dev/null @@ -1,77 +0,0 @@ -/* SPDX-FileCopyrightText: 2024 Greenbone AG - * - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -import React from 'react'; -import hoistStatics from 'hoist-non-react-statics'; -import type FilterType from 'gmp/models/filter/filter-type'; -import useFilterSelection, { - type UseFilterSelectionProps, -} from 'web/components/dashboard/display/useFilterSelection'; -import {updateDisplayName} from 'web/utils/display-name'; - -export interface WithFilterSelectionInjectedProps { - filter?: FilterType; - onSelectFilterClick?: () => void; -} - -export interface WithFilterSelectionControlProps { - showFilterSelection?: boolean; -} - -export interface WithFilterSelectionConfig { - filtersFilter: FilterType; -} - -type WithFilterSelectionProps = Omit< - TProps, - keyof WithFilterSelectionInjectedProps -> & - WithFilterSelectionControlProps; - -const withFilterSelection = - ({filtersFilter}: WithFilterSelectionConfig) => - ( - Component: React.ComponentType, - ) => { - const FilterSelectionWrapper = ({ - showFilterSelection = false, - ...props - }: WithFilterSelectionProps) => { - const {filterId, onFilterIdChanged} = props as TProps & - UseFilterSelectionProps; - const {filter, selectFilter, filterSelectionDialog} = useFilterSelection({ - filterId, - filtersFilter, - onFilterIdChanged, - }); - - return ( - <> - - {filterSelectionDialog} - - ); - }; - - return hoistStatics( - updateDisplayName( - FilterSelectionWrapper, - Component, - 'withFilterSelection', - ), - Component, - ); - }; - -export default withFilterSelection;