11import * as React from 'react' ;
2- import { render } from '@testing-library/react' ;
2+ import { render , fireEvent } from '@testing-library/react' ;
33import PanelTable from './panelTable' ;
44
5- jest . mock ( 'lodash/isUndefined' , ( ) => ( { default : ( ) => { } } ) ) ;
6- jest . mock ( 'lodash/isObject' , ( ) => ( { default : ( ) => { } } ) ) ;
7-
85describe ( 'PanelTable' , ( ) => {
9- it ( 'should render correctly ' , ( ) => {
6+ it ( 'should render collapsed ' , ( ) => {
107 const { asFragment } = render (
118 < PanelTable
129 isNative = { false }
@@ -26,4 +23,183 @@ describe('PanelTable', () => {
2623 ) ;
2724 expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
2825 } ) ;
26+
27+ it ( 'should render string field values correctly' , ( ) => {
28+ const { getByTitle, getByTestId } = render (
29+ < PanelTable
30+ isNative = { false }
31+ errorMessage = "test"
32+ errorType = "test"
33+ hasError
34+ type = "test"
35+ isTouched
36+ isDirty
37+ readFormStateRef = { { current : { touched : false } } }
38+ index = { 0 }
39+ fieldsValues = { { test : 'RHF' } }
40+ name = "test"
41+ collapseAll = { false }
42+ refObject = { { } }
43+ /> ,
44+ ) ;
45+
46+ fireEvent . click ( getByTitle ( 'Toggle field table' ) ) ;
47+
48+ expect ( getByTestId ( 'test-field-value' ) . textContent ) . toBe ( 'RHF' ) ;
49+ } ) ;
50+
51+ it ( 'should render number field values correctly' , ( ) => {
52+ const { getByTitle, getByTestId } = render (
53+ < PanelTable
54+ isNative = { false }
55+ errorMessage = "test"
56+ errorType = "test"
57+ hasError
58+ type = "test"
59+ isTouched
60+ isDirty
61+ readFormStateRef = { { current : { touched : false } } }
62+ index = { 0 }
63+ fieldsValues = { { test : 1234 } }
64+ name = "test"
65+ collapseAll = { false }
66+ refObject = { { } }
67+ /> ,
68+ ) ;
69+
70+ fireEvent . click ( getByTitle ( 'Toggle field table' ) ) ;
71+
72+ expect ( getByTestId ( 'test-field-value' ) . textContent ) . toBe ( '1234' ) ;
73+ } ) ;
74+
75+ it ( 'should render boolean field values correctly' , ( ) => {
76+ const { getByTitle, getByTestId } = render (
77+ < PanelTable
78+ isNative = { false }
79+ errorMessage = "test"
80+ errorType = "test"
81+ hasError
82+ type = "test"
83+ isTouched
84+ isDirty
85+ readFormStateRef = { { current : { touched : false } } }
86+ index = { 0 }
87+ fieldsValues = { { test : false } }
88+ name = "test"
89+ collapseAll = { false }
90+ refObject = { { } }
91+ /> ,
92+ ) ;
93+
94+ fireEvent . click ( getByTitle ( 'Toggle field table' ) ) ;
95+
96+ expect ( getByTestId ( 'test-field-value' ) . textContent ) . toBe ( 'false' ) ;
97+ } ) ;
98+
99+ it ( 'should render null field values correctly' , ( ) => {
100+ const { getByTitle, getByTestId } = render (
101+ < PanelTable
102+ isNative = { false }
103+ errorMessage = "test"
104+ errorType = "test"
105+ hasError
106+ type = "test"
107+ isTouched
108+ isDirty
109+ readFormStateRef = { { current : { touched : false } } }
110+ index = { 0 }
111+ fieldsValues = { { test : null } }
112+ name = "test"
113+ collapseAll = { false }
114+ refObject = { { } }
115+ /> ,
116+ ) ;
117+
118+ fireEvent . click ( getByTitle ( 'Toggle field table' ) ) ;
119+
120+ expect ( getByTestId ( 'test-field-value' ) . textContent ) . toBe ( 'null' ) ;
121+ } ) ;
122+
123+ it ( 'should render object field values correctly' , ( ) => {
124+ const { getByTitle, getByTestId } = render (
125+ < PanelTable
126+ isNative = { false }
127+ errorMessage = "test"
128+ errorType = "test"
129+ hasError
130+ type = "test"
131+ isTouched
132+ isDirty
133+ readFormStateRef = { { current : { touched : false } } }
134+ index = { 0 }
135+ fieldsValues = { { test : { deeply : { nested : 'value' } } } }
136+ name = "test"
137+ collapseAll = { false }
138+ refObject = { { } }
139+ /> ,
140+ ) ;
141+
142+ fireEvent . click ( getByTitle ( 'Toggle field table' ) ) ;
143+
144+ expect ( getByTestId ( 'test-field-value' ) . textContent ) . toMatchInlineSnapshot ( `
145+ "{
146+ \\"deeply\\": {
147+ \\"nested\\": \\"value\\"
148+ }
149+ }"
150+ ` ) ;
151+ } ) ;
152+
153+ it ( 'should render non-serializable field values correctly' , ( ) => {
154+ const circular : any = { } ;
155+ circular . circular = circular ;
156+
157+ const { getByTitle, getByTestId } = render (
158+ < PanelTable
159+ isNative = { false }
160+ errorMessage = "test"
161+ errorType = "test"
162+ hasError
163+ type = "test"
164+ isTouched
165+ isDirty
166+ readFormStateRef = { { current : { touched : false } } }
167+ index = { 0 }
168+ fieldsValues = { { test : circular } }
169+ name = "test"
170+ collapseAll = { false }
171+ refObject = { { } }
172+ /> ,
173+ ) ;
174+
175+ fireEvent . click ( getByTitle ( 'Toggle field table' ) ) ;
176+
177+ expect ( getByTestId ( 'test-field-value' ) . textContent ) . toMatchInlineSnapshot (
178+ `"[Nested Object]"` ,
179+ ) ;
180+ } ) ;
181+
182+ it ( 'should not render undefined field values' , ( ) => {
183+ const { getByTitle, queryByTestId } = render (
184+ < PanelTable
185+ isNative = { false }
186+ errorMessage = "test"
187+ errorType = "test"
188+ hasError
189+ type = "test"
190+ isTouched
191+ isDirty
192+ readFormStateRef = { { current : { touched : false } } }
193+ index = { 0 }
194+ fieldsValues = { { test : undefined } }
195+ name = "test"
196+ collapseAll = { false }
197+ refObject = { { } }
198+ /> ,
199+ ) ;
200+
201+ fireEvent . click ( getByTitle ( 'Toggle field table' ) ) ;
202+
203+ expect ( queryByTestId ( 'test-field-value' ) ) . toBeNull ( ) ;
204+ } ) ;
29205} ) ;
0 commit comments