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,