From b4d3b5f880059a217efca6beb4aa2c47517e2543 Mon Sep 17 00:00:00 2001 From: Aramis Date: Thu, 25 Jan 2024 19:36:33 -0500 Subject: [PATCH] add test for count Signed-off-by: Aramis Signed-off-by: aramissennyeydd --- .../catalog-react/src/testUtils/providers.tsx | 1 + .../PaginatedCatalogTable.test.tsx | 34 +++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-react/src/testUtils/providers.tsx b/plugins/catalog-react/src/testUtils/providers.tsx index 8ab6d118a9..ae99352f2c 100644 --- a/plugins/catalog-react/src/testUtils/providers.tsx +++ b/plugins/catalog-react/src/testUtils/providers.tsx @@ -71,6 +71,7 @@ export function MockEntityListContextProvider< loading: value?.loading ?? false, queryParameters: value?.queryParameters ?? defaultValues.queryParameters, error: value?.error, + count: (value?.entities ?? defaultValues.entities).length, }), [value, defaultValues, filters, updateFilters], ); diff --git a/plugins/catalog/src/components/CatalogTable/PaginatedCatalogTable.test.tsx b/plugins/catalog/src/components/CatalogTable/PaginatedCatalogTable.test.tsx index eb1acc0cee..84f9beea7c 100644 --- a/plugins/catalog/src/components/CatalogTable/PaginatedCatalogTable.test.tsx +++ b/plugins/catalog/src/components/CatalogTable/PaginatedCatalogTable.test.tsx @@ -14,14 +14,16 @@ * limitations under the License. */ import React, { ReactNode } from 'react'; -import { fireEvent, render } from '@testing-library/react'; +import { fireEvent, render, waitFor } from '@testing-library/react'; import { PaginatedCatalogTable } from './PaginatedCatalogTable'; import { screen } from '@testing-library/react'; import { CatalogTableRow } from './types'; +import { renderInTestApp } from '@backstage/test-utils'; import { + EntityKindFilter, + MockEntityListContextProvider, DefaultEntityFilters, EntityListContextProps, - MockEntityListContextProvider, } from '@backstage/plugin-catalog-react'; describe('PaginatedCatalogTable', () => { @@ -134,4 +136,32 @@ describe('PaginatedCatalogTable', () => { fireEvent.click(prevButton); expect(fn).toHaveBeenCalled(); }); + + it('should display entity names when loading has finished and no error occurred', async () => { + await renderInTestApp( + e.entity), + count: data.length, + filters: { + kind: new EntityKindFilter('component'), + }, + }} + > + + , + ); + + expect(screen.getByText(/component-0/)).toBeInTheDocument(); + expect(screen.getByText(/component-50/)).toBeInTheDocument(); + expect(screen.getByText(/component-99/)).toBeInTheDocument(); + await waitFor(() => { + expect(screen.getByText(/My title/)).toBeInTheDocument(); + }); + }); });