1
1
import renderer from 'react-test-renderer' ;
2
+ import { cleanup , screen , fireEvent , render } from '@testing-library/react' ;
3
+ import userEvent from '@testing-library/user-event' ;
2
4
import { CountInfoExtra } from './countInfoExtra' ;
3
5
4
6
@@ -31,4 +33,85 @@ it('renders <CountInfoExtra /> onAdd test case', () => {
31
33
height : '1em' ,
32
34
width : '1em' ,
33
35
} ) ;
34
- } ) ;
36
+ } ) ;
37
+
38
+ it ( 'renders <CountInfoExtra /> onDelete/parentValue test case' , ( ) => {
39
+ const component = renderer . create (
40
+ < CountInfoExtra editable parentValue = { { ab : 1 } } visible showTools value = { { a : 123 } } onDelete = { ( ) => true } onAdd = { ( ) => true } />
41
+ ) ;
42
+ let tree = component . toJSON ( ) ;
43
+ expect ( Array . isArray ( tree ) ) . toBe ( true ) ;
44
+ if ( Array . isArray ( tree ) ) {
45
+ const child1 = tree [ 1 ] ;
46
+ expect ( child1 ) . toHaveProperty ( 'type' ) ;
47
+ expect ( child1 ) . toHaveProperty ( 'props' ) ;
48
+ expect ( child1 ) . toHaveProperty ( 'children' ) ;
49
+ expect ( child1 ) . toHaveProperty ( 'type' , 'svg' ) ;
50
+ expect ( child1 ) . toHaveProperty ( 'props.fill' , 'var(--w-rjv-delete-color, #dc3545)' )
51
+ expect ( child1 ) . toHaveProperty ( 'props.viewBox' , '0 0 40 40' )
52
+ expect ( child1 ) . toHaveProperty ( 'props.style' , {
53
+ verticalAlign : 'middle' ,
54
+ display : 'inline-block' ,
55
+ cursor : 'pointer' ,
56
+ marginLeft : 5 ,
57
+ height : '1em' ,
58
+ width : '1em' ,
59
+ } ) ;
60
+ }
61
+ } ) ;
62
+
63
+ it ( 'renders <CountInfoExtra /> `onDelete/onAdd` test case' , async ( ) => {
64
+ const user = userEvent . setup ( ) ;
65
+ const { container } = render (
66
+ < CountInfoExtra
67
+ editable
68
+ visible
69
+ showTools
70
+ keyName = "ab"
71
+ parentValue = { { ab : { a : 123 } } }
72
+ value = { { a : 123 } }
73
+ onDelete = { ( keyName , value , parentValue ) => {
74
+ expect ( keyName ) . toEqual ( 'ab' ) ;
75
+ return true ;
76
+ } }
77
+ setValue = { ( ) => { } }
78
+ setParentValue = { ( ) => { } }
79
+ onAdd = { ( keyOrValue ) => {
80
+ expect ( keyOrValue ) . toEqual ( 'AddKeyOrValue' ) ;
81
+ return true
82
+ } }
83
+ />
84
+ ) ;
85
+ expect ( container . firstElementChild ) . toBeInstanceOf ( SVGSVGElement ) ;
86
+ await user . click ( container . firstElementChild ! ) ;
87
+ expect ( container . lastElementChild ) . toBeInstanceOf ( SVGSVGElement ) ;
88
+ await user . click ( container . lastElementChild ! ) ;
89
+ } ) ;
90
+
91
+ it ( 'renders <CountInfoExtra /> `onDelete/onAdd` test case' , async ( ) => {
92
+ const user = userEvent . setup ( ) ;
93
+ const { container } = render (
94
+ < CountInfoExtra
95
+ editable
96
+ visible
97
+ showTools
98
+ keyName = { 0 }
99
+ parentValue = { [ 'ab' , 1 , 3 ] }
100
+ value = { [ 'ab' , 1 , 3 ] }
101
+ onDelete = { ( keyName , value , parentValue ) => {
102
+ expect ( keyName ) . toEqual ( 0 ) ;
103
+ return true ;
104
+ } }
105
+ setValue = { ( ) => { } }
106
+ setParentValue = { ( ) => { } }
107
+ onAdd = { ( keyOrValue ) => {
108
+ expect ( keyOrValue ) . toEqual ( 'AddKeyOrValue' ) ;
109
+ return true
110
+ } }
111
+ />
112
+ ) ;
113
+ expect ( container . firstElementChild ) . toBeInstanceOf ( SVGSVGElement ) ;
114
+ await user . click ( container . firstElementChild ! ) ;
115
+ expect ( container . lastElementChild ) . toBeInstanceOf ( SVGSVGElement ) ;
116
+ await user . click ( container . lastElementChild ! ) ;
117
+ } ) ;
0 commit comments