Skip to content

Commit

Permalink
bugfix: fix ActionCellRenderer tests
Browse files Browse the repository at this point in the history
  - some housekeeping of component as well
DEVSU-2049
  • Loading branch information
kttkjl committed Oct 14, 2023
1 parent 0a0f090 commit 9b7e31b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { ColumnApi } from '@ag-grid-community/core';

import ActionCellRenderer from '..';
import { act } from 'react-dom/test-utils';
import { ActionCellRenderer } from '..';

// eslint-disable-next-line react/display-name
jest.mock('../../SvgViewer', () => (() => (<div role="presentation" />)));
Expand Down Expand Up @@ -67,20 +68,20 @@ describe('ActionCellRenderer', () => {

test('It shows a link to GraphKB when multiple entries exist', async () => {
const statements = ['#155:863', '#120:109'];
render(
const { getByText } = render(
<ActionCellRenderer
data={{
kbStatementId: statements,
}}
/>,
);

fireEvent.click(await screen.findByRole('button'));

statements.forEach(async (statement) => {
expect(await screen.findByText(statement))
.toHaveAttribute('href', `${window._env_.GRAPHKB_URL}/view/Statement/${statement.replace('#', '')}`);
await act(async () => {
fireEvent.click(await screen.findByRole('button'));
});

expect(getByText(statements[0])).toHaveAttribute('href', `${window._env_.GRAPHKB_URL}/view/Statement/155:863`);
expect(getByText(statements[1])).toHaveAttribute('href', `${window._env_.GRAPHKB_URL}/view/Statement/120:109`);
});

test('It shows the delete icon when allowed', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type ActionCellRendererProps = {
} & Partial<ICellRendererParams>;

const WrapperComponent = ({
displayMode,
displayMode = 'tableCell',
children,
onClick = () => {},
...rest
Expand All @@ -58,7 +58,11 @@ const WrapperComponent = ({
}

if (React.isValidElement(children)) {
return React.cloneElement(children, { onClick, ...rest });
const newProps = {
onClick,
...rest,
};
return React.cloneElement(children, newProps);
}
return null;
};
Expand Down

0 comments on commit 9b7e31b

Please sign in to comment.