From c9cedf6d7ff4e8d900acae6dd8253a1c4f5ecd5d Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Fri, 4 Dec 2026 14:29:36 +0530 Subject: [PATCH] Fixes #39774: Request the schema table's test summary only for its own test suite (#39776) * Request the schema table's test summary only for its own test suite SchemaTable called getTestCaseExecutionSummary(table?.testSuite?.id) on every table FQN change. For a table without a test suite, or before the table's testSuite field had loaded, that sent the request without testSuiteId, so the server summarised every test suite and the page used that aggregate as the table's column test summary. It also made AssetHealthWidget.browser.test.tsx flaky: the unscoped request could land before its 'no test suite, nothing to summarise' assertion. Fetch only when the table has a test suite, refetch when that suite changes, and clear the summary otherwise. * Cover the schema table refetching its test summary when the test suite changes (cherry picked from commit 9904563e1ec77563fcf1e44593ec65f496f421f3) --- .../SchemaTable/SchemaTable.component.tsx | 16 +++- .../Database/SchemaTable/SchemaTable.test.tsx | 73 +++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Database/SchemaTable/SchemaTable.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Database/SchemaTable/SchemaTable.component.tsx index 97b67cdbde9f..c9de521aa4f7 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Database/SchemaTable/SchemaTable.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Database/SchemaTable/SchemaTable.component.tsx @@ -343,18 +343,26 @@ const SchemaTable = () => { [handlePageChange] ); - const fetchTestCaseSummary = async () => { + const testSuiteId = table?.testSuite?.id; + + const fetchTestCaseSummary = async (id: string) => { try { - const response = await getTestCaseExecutionSummary(table?.testSuite?.id); + const response = await getTestCaseExecutionSummary(id); setTestCaseSummary(response); } catch { setTestCaseSummary(undefined); } }; + // Without a test suite id the endpoint summarises every test suite, not + // this table's. useEffect(() => { - void fetchTestCaseSummary(); - }, [tableFqn]); + if (testSuiteId) { + void fetchTestCaseSummary(testSuiteId); + } else { + setTestCaseSummary(undefined); + } + }, [testSuiteId]); useEffect(() => { if (searchText || hasTagFilter) { diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Database/SchemaTable/SchemaTable.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Database/SchemaTable/SchemaTable.test.tsx index ca63088e1794..fa370dac55fc 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Database/SchemaTable/SchemaTable.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Database/SchemaTable/SchemaTable.test.tsx @@ -20,8 +20,10 @@ import { getTableColumnsByFQN, searchTableColumnsByFQN, } from '../../../rest/tableAPI'; +import { getTestCaseExecutionSummary } from '../../../rest/testAPI'; import { DEFAULT_ENTITY_PERMISSION } from '../../../utils/PermissionsUtils'; import { getAllTags } from '../../../utils/TableTags/TableTags.utils'; +import { useGenericContext } from '../../Customization/GenericProvider/GenericContext'; import SchemaTable from './SchemaTable.component'; const mockTableConstraints = [ @@ -477,6 +479,77 @@ describe('Test EntityTable Component', () => { expect(emptyPlaceholder).toBeInTheDocument(); }); + describe('column test summary', () => { + const renderWithTable = async (table: Table) => { + (useGenericContext as jest.Mock).mockImplementation(() => ({ + ...mockGenericContextProps, + data: table, + })); + await act(async () => { + render(, { wrapper: MemoryRouter }); + }); + + expect(await screen.findByTestId('entity-table')).toBeInTheDocument(); + }; + + afterEach(() => { + (useGenericContext as jest.Mock).mockImplementation( + () => mockGenericContextProps + ); + }); + + it('should not request a summary when the table has no test suite', async () => { + const { testSuite: _testSuite, ...tableWithoutSuite } = + mockGenericContextProps.data; + + await renderWithTable(tableWithoutSuite as Table); + + expect(getTestCaseExecutionSummary).not.toHaveBeenCalled(); + }); + + it("should request the summary of the table's own test suite", async () => { + await renderWithTable({ + ...mockGenericContextProps.data, + testSuite: { id: 'table-suite-id', type: 'testSuite' }, + }); + + expect(getTestCaseExecutionSummary).toHaveBeenCalledWith( + 'table-suite-id' + ); + }); + + it('should request the new summary when the table switches test suite', async () => { + const withSuite = (id: string) => ({ + ...mockGenericContextProps, + data: { + ...mockGenericContextProps.data, + testSuite: { id, type: 'testSuite' }, + }, + }); + (useGenericContext as jest.Mock).mockImplementation(() => + withSuite('first-suite-id') + ); + const { rerender } = render(, { wrapper: MemoryRouter }); + + expect(await screen.findByTestId('entity-table')).toBeInTheDocument(); + + (useGenericContext as jest.Mock).mockImplementation(() => + withSuite('second-suite-id') + ); + await act(async () => { + rerender(); + }); + + expect(getTestCaseExecutionSummary).toHaveBeenNthCalledWith( + 1, + 'first-suite-id' + ); + expect(getTestCaseExecutionSummary).toHaveBeenLastCalledWith( + 'second-suite-id' + ); + }); + }); + it('should render column name only if displayName is not present', async () => { (getTableColumnsByFQN as jest.Mock).mockResolvedValue({ data: mockColumns,