From fae8fb815d2782d15048b2da0c58ebb80897ddee Mon Sep 17 00:00:00 2001 From: Aramis Date: Mon, 8 Jan 2024 01:04:06 -0500 Subject: [PATCH] fix tests Signed-off-by: Aramis --- .../PaginatedCatalogTable.test.tsx | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/plugins/catalog/src/components/CatalogTable/PaginatedCatalogTable.test.tsx b/plugins/catalog/src/components/CatalogTable/PaginatedCatalogTable.test.tsx index dbf37c2d5c..eb1acc0cee 100644 --- a/plugins/catalog/src/components/CatalogTable/PaginatedCatalogTable.test.tsx +++ b/plugins/catalog/src/components/CatalogTable/PaginatedCatalogTable.test.tsx @@ -13,11 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import React from 'react'; +import React, { ReactNode } from 'react'; import { fireEvent, render } from '@testing-library/react'; import { PaginatedCatalogTable } from './PaginatedCatalogTable'; import { screen } from '@testing-library/react'; import { CatalogTableRow } from './types'; +import { + DefaultEntityFilters, + EntityListContextProps, + MockEntityListContextProvider, +} from '@backstage/plugin-catalog-react'; describe('PaginatedCatalogTable', () => { const data = new Array(100).fill(0).map((_, index) => { @@ -45,8 +50,21 @@ describe('PaginatedCatalogTable', () => { }, ]; + const wrapInContext = ( + node: ReactNode, + value?: Partial>, + ) => { + return ( + + {node} + + ); + }; + it('should display all the items', () => { - render(); + render( + wrapInContext(), + ); for (const item of data) { expect(screen.queryByText(item.resolved.name)).toBeInTheDocument(); @@ -55,7 +73,13 @@ describe('PaginatedCatalogTable', () => { it('should display and invoke the next button', async () => { const { rerender } = render( - , + wrapInContext( + , + ), ); expect( @@ -64,7 +88,11 @@ describe('PaginatedCatalogTable', () => { const fn = jest.fn(); - rerender(); + rerender( + wrapInContext( + , + ), + ); const nextButton = screen.queryAllByRole('button', { name: 'Next Page', @@ -77,7 +105,13 @@ describe('PaginatedCatalogTable', () => { it('should display and invoke the prev button', async () => { const { rerender } = render( - , + wrapInContext( + , + ), ); expect( @@ -86,7 +120,11 @@ describe('PaginatedCatalogTable', () => { const fn = jest.fn(); - rerender(); + rerender( + wrapInContext( + , + ), + ); const prevButton = screen.queryAllByRole('button', { name: 'Previous Page',