1
1
// @flow
2
2
import * as React from 'react' ;
3
+ import userEvent from '@testing-library/user-event' ;
3
4
4
- import { mount , shallow } from 'enzyme ' ;
5
+ import { render , screen } from '../../../test-utils/testing-library ' ;
5
6
6
7
import * as libDom from '../../../utils/dom' ;
7
-
8
8
import ThumbnailCardDetails from '../ThumbnailCardDetails' ;
9
9
10
- const getWrapper = ( props = { } ) => shallow ( < ThumbnailCardDetails title = { < div > Foo Bar!</ div > } { ...props } /> ) ;
10
+ const renderComponent = ( props = { } ) => render ( < ThumbnailCardDetails title = { < div > Foo Bar!</ div > } { ...props } /> ) ;
11
11
12
12
jest . mock ( '../../../utils/dom' , ( ) => ( { useIsContentOverflowed : jest . fn ( ) } ) ) ;
13
13
@@ -17,37 +17,49 @@ describe('components/thumbnail-card/ThumbnailCardDetails', () => {
17
17
} ) ;
18
18
19
19
test ( 'should render' , ( ) => {
20
- const wrapper = getWrapper ( ) ;
20
+ const { container } = renderComponent ( ) ;
21
21
22
- expect ( wrapper ) . toMatchSnapshot ( ) ;
22
+ expect ( container . querySelector ( '.thumbnail-card-details' ) ) . toBeInTheDocument ( ) ;
23
23
} ) ;
24
24
25
25
test ( 'should render icon' , ( ) => {
26
26
const icon = < img alt = "icon" /> ;
27
- const wrapper = getWrapper ( { icon } ) ;
27
+ renderComponent ( { icon } ) ;
28
28
29
- expect ( wrapper ) . toMatchSnapshot ( ) ;
29
+ expect ( screen . queryByAltText ( 'icon' ) ) . toBeInTheDocument ( ) ;
30
30
} ) ;
31
31
32
32
test ( 'should render subtitle' , ( ) => {
33
33
const subtitle = < div > Subtitle!</ div > ;
34
- const wrapper = getWrapper ( { subtitle } ) ;
34
+ const { container } = renderComponent ( { subtitle } ) ;
35
35
36
- expect ( wrapper ) . toMatchSnapshot ( ) ;
36
+ expect ( container . querySelector ( '.thumbnail-card-subtitle' ) ) . toBeInTheDocument ( ) ;
37
37
} ) ;
38
38
39
39
test ( 'should render actionItem' , ( ) => {
40
- const actionItem = < button type = "button" > Click Me</ button > ;
41
- const wrapper = getWrapper ( { actionItem } ) ;
40
+ const actionText = 'Click Me' ;
41
+ const actionItem = < button type = "button" > { actionText } </ button > ;
42
+ renderComponent ( { actionItem } ) ;
42
43
43
- expect ( wrapper ) . toMatchSnapshot ( ) ;
44
+ expect ( screen . getByText ( actionText ) ) . toBeInTheDocument ( ) ;
44
45
} ) ;
45
46
46
- test ( 'should render a Tooltip if text is overflowed' , ( ) => {
47
+ test ( 'should render a Tooltip if text is overflowed' , async ( ) => {
47
48
libDom . useIsContentOverflowed . mockReturnValue ( true ) ;
49
+ renderComponent ( ) ;
50
+
51
+ await userEvent . tab ( ) ;
52
+
53
+ expect ( screen . getByRole ( 'tooltip' ) ) . toBeInTheDocument ( ) ;
54
+ } ) ;
55
+
56
+ test ( 'should accept a keydown callback' , async ( ) => {
57
+ const someFunction = jest . fn ( ) ;
58
+ const { container } = renderComponent ( { onKeyDown : someFunction } ) ;
59
+ const title = container . querySelector ( '.thumbnail-card-title' ) ;
48
60
49
- const wrapper = mount ( < ThumbnailCardDetails title = { < div > Foo Bar! </ div > } /> ) ;
61
+ await userEvent . type ( title , '{enter}' ) ;
50
62
51
- expect ( wrapper . find ( 'Tooltip' ) . length ) . toBe ( 1 ) ;
63
+ expect ( someFunction ) . toHaveBeenCalled ( ) ;
52
64
} ) ;
53
65
} ) ;
0 commit comments