Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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(<SchemaTable />, { 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(<SchemaTable />, { wrapper: MemoryRouter });

expect(await screen.findByTestId('entity-table')).toBeInTheDocument();

(useGenericContext as jest.Mock).mockImplementation(() =>
withSuite('second-suite-id')
);
await act(async () => {
rerender(<SchemaTable />);
});

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,
Expand Down
Loading