@@ -11,7 +11,7 @@ import {
11
11
import HadronDocument from 'hadron-document' ;
12
12
import Document from './document' ;
13
13
14
- const EditableDoc = ( { doc } ) => {
14
+ const EditableDoc = ( { doc } : { doc : HadronDocument } ) => {
15
15
const [ editing , setEditing ] = useState ( false ) ;
16
16
17
17
return (
@@ -61,8 +61,11 @@ describe('Document', function () {
61
61
render ( < Document value = { doc } editable editing > </ Document > ) ;
62
62
63
63
const el = document . querySelector < HTMLElement > (
64
- `[data-id="${ doc . get ( 'str' ) . uuid } "]`
64
+ `[data-id="${ doc . get ( 'str' ) ? .uuid } "]`
65
65
) ;
66
+ if ( ! el ) {
67
+ throw new Error ( 'Could not find element' ) ;
68
+ }
66
69
const keyEditor = within ( el ) . getByTestId ( 'hadron-document-key-editor' ) ;
67
70
68
71
userEvent . clear ( keyEditor ) ;
@@ -71,16 +74,19 @@ describe('Document', function () {
71
74
72
75
expect ( screen . getByDisplayValue ( 'new_name' ) ) . to . exist ;
73
76
74
- expect ( doc . get ( 'new_name' ) . key ) . to . eq ( 'str' ) ;
75
- expect ( doc . get ( 'new_name' ) . currentKey ) . to . eq ( 'new_name' ) ;
77
+ expect ( doc . get ( 'new_name' ) ? .key ) . to . eq ( 'str' ) ;
78
+ expect ( doc . get ( 'new_name' ) ? .currentKey ) . to . eq ( 'new_name' ) ;
76
79
} ) ;
77
80
78
81
it ( 'should change element string value on edit' , function ( ) {
79
82
render ( < Document value = { doc } editable editing > </ Document > ) ;
80
83
81
84
const el = document . querySelector < HTMLElement > (
82
- `[data-id="${ doc . get ( 'str' ) . uuid } "]`
85
+ `[data-id="${ doc . get ( 'str' ) ? .uuid } "]`
83
86
) ;
87
+ if ( ! el ) {
88
+ throw new Error ( 'Could not find element' ) ;
89
+ }
84
90
85
91
const valueEditor = within ( el ) . getByTestId (
86
92
'hadron-document-value-editor'
@@ -90,16 +96,19 @@ describe('Document', function () {
90
96
userEvent . keyboard ( 'bla' ) ;
91
97
userEvent . tab ( ) ;
92
98
93
- expect ( doc . get ( 'str' ) . currentValue ) . to . eq ( 'bla' ) ;
94
- expect ( doc . get ( 'str' ) . currentType ) . to . eq ( 'String' ) ;
99
+ expect ( doc . get ( 'str' ) ? .currentValue ) . to . eq ( 'bla' ) ;
100
+ expect ( doc . get ( 'str' ) ? .currentType ) . to . eq ( 'String' ) ;
95
101
} ) ;
96
102
97
103
it ( 'should change element number value on edit' , function ( ) {
98
104
render ( < Document value = { doc } editable editing > </ Document > ) ;
99
105
100
106
const el = document . querySelector < HTMLElement > (
101
- `[data-id="${ doc . get ( 'num' ) . uuid } "]`
107
+ `[data-id="${ doc . get ( 'num' ) ? .uuid } "]`
102
108
) ;
109
+ if ( ! el ) {
110
+ throw new Error ( 'Could not find element' ) ;
111
+ }
103
112
104
113
const valueEditor = within ( el ) . getByTestId (
105
114
'hadron-document-value-editor'
@@ -109,16 +118,19 @@ describe('Document', function () {
109
118
userEvent . keyboard ( '321' ) ;
110
119
userEvent . tab ( ) ;
111
120
112
- expect ( doc . get ( 'num' ) . currentValue . valueOf ( ) ) . to . eq ( 321 ) ;
113
- expect ( doc . get ( 'num' ) . currentType ) . to . eq ( 'Int32' ) ;
121
+ expect ( doc . get ( 'num' ) ? .currentValue ? .valueOf ( ) ) . to . eq ( 321 ) ;
122
+ expect ( doc . get ( 'num' ) ? .currentType ) . to . eq ( 'Int32' ) ;
114
123
} ) ;
115
124
116
125
it ( 'should change element date value on edit' , function ( ) {
117
126
render ( < Document value = { doc } editable editing > </ Document > ) ;
118
127
119
128
const el = document . querySelector < HTMLElement > (
120
- `[data-id="${ doc . get ( 'date' ) . uuid } "]`
129
+ `[data-id="${ doc . get ( 'date' ) ? .uuid } "]`
121
130
) ;
131
+ if ( ! el ) {
132
+ throw new Error ( 'Could not find element' ) ;
133
+ }
122
134
123
135
const valueEditor = within ( el ) . getByTestId (
124
136
'hadron-document-value-editor'
@@ -128,26 +140,29 @@ describe('Document', function () {
128
140
userEvent . keyboard ( '2000-01-01' ) ;
129
141
userEvent . tab ( ) ;
130
142
131
- expect ( ( doc . get ( 'date' ) . currentValue as Date ) . toISOString ( ) ) . to . eq (
143
+ expect ( ( doc . get ( 'date' ) ? .currentValue as Date ) . toISOString ( ) ) . to . eq (
132
144
'2000-01-01T00:00:00.000Z'
133
145
) ;
134
- expect ( doc . get ( 'date' ) . currentType ) . to . eq ( 'Date' ) ;
146
+ expect ( doc . get ( 'date' ) ? .currentType ) . to . eq ( 'Date' ) ;
135
147
} ) ;
136
148
137
149
it ( 'should change element type on edit' , function ( ) {
138
150
render ( < Document value = { doc } editable editing > </ Document > ) ;
139
151
140
152
const el = document . querySelector < HTMLElement > (
141
- `[data-id="${ doc . get ( 'num' ) . uuid } "]`
153
+ `[data-id="${ doc . get ( 'num' ) ? .uuid } "]`
142
154
) ;
155
+ if ( ! el ) {
156
+ throw new Error ( 'Could not find element' ) ;
157
+ }
143
158
144
159
const typeEditor = within ( el ) . getByTestId ( 'hadron-document-type-editor' ) ;
145
160
146
161
userEvent . selectOptions ( typeEditor , 'String' ) ;
147
162
userEvent . tab ( ) ;
148
163
149
- expect ( doc . get ( 'num' ) . currentValue . valueOf ( ) ) . to . eq ( '123' ) ;
150
- expect ( doc . get ( 'num' ) . currentType ) . to . eq ( 'String' ) ;
164
+ expect ( doc . get ( 'num' ) ? .currentValue ? .valueOf ( ) ) . to . eq ( '123' ) ;
165
+ expect ( doc . get ( 'num' ) ? .currentType ) . to . eq ( 'String' ) ;
151
166
} ) ;
152
167
} ) ;
153
168
@@ -168,8 +183,11 @@ describe('Document', function () {
168
183
render ( < Document value = { doc } editable editing > </ Document > ) ;
169
184
170
185
const el = document . querySelector < HTMLElement > (
171
- `[data-id="${ doc . get ( 'null_value' ) . uuid } "]`
186
+ `[data-id="${ doc . get ( 'null_value' ) ? .uuid } "]`
172
187
) ;
188
+ if ( ! el ) {
189
+ throw new Error ( 'Could not find element' ) ;
190
+ }
173
191
174
192
const typeEditor = within ( el ) . getByTestId ( 'hadron-document-type-editor' ) ;
175
193
@@ -182,16 +200,19 @@ describe('Document', function () {
182
200
userEvent . keyboard ( 'foo bar' ) ;
183
201
userEvent . tab ( ) ;
184
202
185
- expect ( doc . get ( 'null_value' ) . currentValue . valueOf ( ) ) . to . eq ( 'foo bar' ) ;
186
- expect ( doc . get ( 'null_value' ) . currentType ) . to . eq ( 'String' ) ;
203
+ expect ( doc . get ( 'null_value' ) ? .currentValue ? .valueOf ( ) ) . to . eq ( 'foo bar' ) ;
204
+ expect ( doc . get ( 'null_value' ) ? .currentType ) . to . eq ( 'String' ) ;
187
205
} ) ;
188
206
189
207
it ( 'should autofocus key editor when double-clicking key' , function ( ) {
190
208
render ( < EditableDoc doc = { doc } > </ EditableDoc > ) ;
191
209
192
210
const el = document . querySelector < HTMLElement > (
193
- `[data-id="${ doc . get ( 'str' ) . uuid } "]`
211
+ `[data-id="${ doc . get ( 'str' ) ? .uuid } "]`
194
212
) ;
213
+ if ( ! el ) {
214
+ throw new Error ( 'Could not find element' ) ;
215
+ }
195
216
196
217
userEvent . dblClick ( within ( el ) . getByTestId ( 'hadron-document-clickable-key' ) ) ;
197
218
@@ -204,8 +225,11 @@ describe('Document', function () {
204
225
render ( < EditableDoc doc = { doc } > </ EditableDoc > ) ;
205
226
206
227
const el = document . querySelector < HTMLElement > (
207
- `[data-id="${ doc . get ( 'str' ) . uuid } "]`
228
+ `[data-id="${ doc . get ( 'str' ) ? .uuid } "]`
208
229
) ;
230
+ if ( ! el ) {
231
+ throw new Error ( 'Could not find element' ) ;
232
+ }
209
233
210
234
userEvent . dblClick (
211
235
within ( el ) . getByTestId ( 'hadron-document-clickable-value' )
@@ -220,8 +244,11 @@ describe('Document', function () {
220
244
render ( < EditableDoc doc = { doc } > </ EditableDoc > ) ;
221
245
222
246
const el = document . querySelector < HTMLElement > (
223
- `[data-id="${ doc . get ( 'null_value' ) . uuid } "]`
247
+ `[data-id="${ doc . get ( 'null_value' ) ? .uuid } "]`
224
248
) ;
249
+ if ( ! el ) {
250
+ throw new Error ( 'Could not find element' ) ;
251
+ }
225
252
226
253
userEvent . dblClick (
227
254
within ( el ) . getByTestId ( 'hadron-document-clickable-value' )
0 commit comments