From d4c3c248495ec32936f2aa37e2600712af8e62c6 Mon Sep 17 00:00:00 2001 From: sawhil Date: Tue, 15 Apr 2025 01:49:59 +0530 Subject: [PATCH] feat: added test cases --- .../__test__/TableViewActions.test.tsx | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 frontend/src/container/LogDetailedView/TableView/__test__/TableViewActions.test.tsx diff --git a/frontend/src/container/LogDetailedView/TableView/__test__/TableViewActions.test.tsx b/frontend/src/container/LogDetailedView/TableView/__test__/TableViewActions.test.tsx new file mode 100644 index 0000000000..f7293ea55e --- /dev/null +++ b/frontend/src/container/LogDetailedView/TableView/__test__/TableViewActions.test.tsx @@ -0,0 +1,130 @@ +import { render, screen } from '@testing-library/react'; +import { RESTRICTED_SELECTED_FIELDS } from 'container/LogsFilters/config'; + +import { TableViewActions } from '../TableViewActions'; + +// Mock the components and hooks +jest.mock('components/Logs/CopyClipboardHOC', () => ({ + __esModule: true, + default: ({ children }: { children: React.ReactNode }): JSX.Element => ( +
{children}
+ ), +})); + +jest.mock('providers/Timezone', () => ({ + useTimezone: (): { + formatTimezoneAdjustedTimestamp: (timestamp: string) => string; + } => ({ + formatTimezoneAdjustedTimestamp: (timestamp: string): string => timestamp, + }), +})); + +jest.mock('react-router-dom', () => ({ + useLocation: (): { + pathname: string; + search: string; + hash: string; + state: null; + } => ({ + pathname: '/test', + search: '', + hash: '', + state: null, + }), +})); + +describe('TableViewActions', () => { + const TEST_VALUE = 'test value'; + const ACTION_BUTTON_TEST_ID = '.action-btn'; + const defaultProps = { + fieldData: { + field: 'test-field', + value: TEST_VALUE, + }, + record: { + key: 'test-key', + field: 'test-field', + value: TEST_VALUE, + }, + isListViewPanel: false, + isfilterInLoading: false, + isfilterOutLoading: false, + onClickHandler: jest.fn(), + onGroupByAttribute: jest.fn(), + }; + + it('should render without crashing', () => { + render( + , + ); + expect(screen.getByText(TEST_VALUE)).toBeInTheDocument(); + }); + + it('should not render action buttons for restricted fields', () => { + RESTRICTED_SELECTED_FIELDS.forEach((field) => { + const { container } = render( + , + ); + // Verify that action buttons are not rendered for restricted fields + expect( + container.querySelector(ACTION_BUTTON_TEST_ID), + ).not.toBeInTheDocument(); + }); + }); + + it('should render action buttons for non-restricted fields', () => { + const { container } = render( + , + ); + // Verify that action buttons are not rendered in list view panel + expect(container.querySelector(ACTION_BUTTON_TEST_ID)).toBeInTheDocument(); + }); + + it('should not render action buttons in list view panel', () => { + const { container } = render( + , + ); + // Verify that action buttons are not rendered in list view panel + expect( + container.querySelector(ACTION_BUTTON_TEST_ID), + ).not.toBeInTheDocument(); + }); +});