+ {/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex, jsx-a11y/no-static-element-interactions */}
+
{title}
);
};
-const ThumbnailCardDetails = ({ actionItem, icon, subtitle, title }: Props) => (
+const ThumbnailCardDetails = ({ actionItem, icon, subtitle, title, onKeyDown }: Props) => (
{icon}
-
+
{subtitle &&
{subtitle}
}
{actionItem}
diff --git a/src/components/thumbnail-card/__tests__/ThumbnailCardDetails.test.js b/src/components/thumbnail-card/__tests__/ThumbnailCardDetails.test.js
index c3935b4628..6858e2d141 100644
--- a/src/components/thumbnail-card/__tests__/ThumbnailCardDetails.test.js
+++ b/src/components/thumbnail-card/__tests__/ThumbnailCardDetails.test.js
@@ -1,13 +1,13 @@
// @flow
import * as React from 'react';
+import userEvent from '@testing-library/user-event';
-import { mount, shallow } from 'enzyme';
+import { render, screen } from '../../../test-utils/testing-library';
import * as libDom from '../../../utils/dom';
-
import ThumbnailCardDetails from '../ThumbnailCardDetails';
-const getWrapper = (props = {}) => shallow(
Foo Bar! } {...props} />);
+const renderComponent = (props = {}) => render(
Foo Bar!} {...props} />);
jest.mock('../../../utils/dom', () => ({ useIsContentOverflowed: jest.fn() }));
@@ -17,37 +17,49 @@ describe('components/thumbnail-card/ThumbnailCardDetails', () => {
});
test('should render', () => {
- const wrapper = getWrapper();
+ const { container } = renderComponent();
- expect(wrapper).toMatchSnapshot();
+ expect(container.querySelector('.thumbnail-card-details')).toBeInTheDocument();
});
test('should render icon', () => {
const icon =
![icon]()
;
- const wrapper = getWrapper({ icon });
+ renderComponent({ icon });
- expect(wrapper).toMatchSnapshot();
+ expect(screen.queryByAltText('icon')).toBeInTheDocument();
});
test('should render subtitle', () => {
const subtitle =
Subtitle!
;
- const wrapper = getWrapper({ subtitle });
+ const { container } = renderComponent({ subtitle });
- expect(wrapper).toMatchSnapshot();
+ expect(container.querySelector('.thumbnail-card-subtitle')).toBeInTheDocument();
});
test('should render actionItem', () => {
- const actionItem =
;
- const wrapper = getWrapper({ actionItem });
+ const actionText = 'Click Me';
+ const actionItem =
;
+ renderComponent({ actionItem });
- expect(wrapper).toMatchSnapshot();
+ expect(screen.getByText(actionText)).toBeInTheDocument();
});
- test('should render a Tooltip if text is overflowed', () => {
+ test('should render a Tooltip if text is overflowed', async () => {
libDom.useIsContentOverflowed.mockReturnValue(true);
+ renderComponent();
+
+ await userEvent.tab();
+
+ expect(screen.getByRole('tooltip')).toBeInTheDocument();
+ });
+
+ test('should accept a keydown callback', async () => {
+ const someFunction = jest.fn();
+ const { container } = renderComponent({ onKeyDown: someFunction });
+ const title = container.querySelector('.thumbnail-card-title');
- const wrapper = mount(
Foo Bar! } />);
+ await userEvent.type(title, '{enter}');
- expect(wrapper.find('Tooltip').length).toBe(1);
+ expect(someFunction).toHaveBeenCalled();
});
});
diff --git a/src/components/thumbnail-card/__tests__/__snapshots__/ThumbnailCardDetails.test.js.snap b/src/components/thumbnail-card/__tests__/__snapshots__/ThumbnailCardDetails.test.js.snap
deleted file mode 100644
index a9703c3f3b..0000000000
--- a/src/components/thumbnail-card/__tests__/__snapshots__/ThumbnailCardDetails.test.js.snap
+++ /dev/null
@@ -1,104 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`components/thumbnail-card/ThumbnailCardDetails should render 1`] = `
-