Skip to content

Commit

Permalink
fix jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Apr 18, 2023
1 parent 6fee2b8 commit 8908281
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,22 @@ export const TableActionButton: FC<TableActionButtonProps> = ({
);

const unwrappedButton = !isDisabled ? (
<EuiLink onClick={onClick} color={'text'} aria-label={message}>
<EuiLink
data-test-subj="aiopsTableActionButtonEnabled"
onClick={onClick}
color={'text'}
aria-label={message}
>
{buttonContent}
</EuiLink>
) : (
<EuiText size="s" color={'subdued'} aria-label={message} css={{ fontWeight: 500 }}>
<EuiText
data-test-subj="aiopsTableActionButtonDisabled"
size="s"
color={'subdued'}
aria-label={message}
css={{ fontWeight: 500 }}
>
{buttonContent}
</EuiText>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ describe('useCopyToClipboardAction', () => {
it('renders the action for a single significant term', async () => {
execCommandMock.mockImplementationOnce(() => true);
const { result } = renderHook(() => useCopyToClipboardAction());
const { getByLabelText } = render((result.current as Action).render(significantTerms[0]));
const { findByText, getByTestId } = render(
(result.current as Action).render(significantTerms[0])
);

const button = getByLabelText('Copy field/value pair as KQL syntax to clipboard');
const button = getByTestId('aiopsTableActionButtonEnabled');

expect(button).toBeInTheDocument();
userEvent.hover(button);

// The tooltip from EUI takes 250ms to appear, so we must
// use a `find*` query to asynchronously poll for it.
expect(
await findByText('Copy field/value pair as KQL syntax to clipboard')
).toBeInTheDocument();

await act(async () => {
await userEvent.click(button);
Expand All @@ -50,12 +58,16 @@ describe('useCopyToClipboardAction', () => {
it('renders the action for a group of items', async () => {
execCommandMock.mockImplementationOnce(() => true);
const groupTableItems = getGroupTableItems(finalSignificantTermGroups);
const { result } = renderHook(() => useCopyToClipboardAction());
const { getByLabelText } = render((result.current as Action).render(groupTableItems[0]));
const { result } = renderHook(useCopyToClipboardAction);
const { findByText, getByText } = render((result.current as Action).render(groupTableItems[0]));

const button = getByText('Copy to clipboard');

const button = getByLabelText('Copy group items as KQL syntax to clipboard');
userEvent.hover(button);

expect(button).toBeInTheDocument();
// The tooltip from EUI takes 250ms to appear, so we must
// use a `find*` query to asynchronously poll for it.
expect(await findByText('Copy group items as KQL syntax to clipboard')).toBeInTheDocument();

await act(async () => {
await userEvent.click(button);
Expand Down

0 comments on commit 8908281

Please sign in to comment.