@@ -10,6 +10,33 @@ function Heading({ children }) {
10
10
return < h3 className = "text-xs font-bold" > { children } </ h3 > ;
11
11
}
12
12
13
+ // The reviver parses serialized regexes back to a real regexp.
14
+ // This function is required if the data comes in via message transport
15
+ // think of the chrome-extension.
16
+ function reviver ( obj ) {
17
+ if ( typeof obj ?. $regexp === 'string' ) {
18
+ return new RegExp ( obj . $regexp , obj . $flags ) ;
19
+ }
20
+
21
+ return obj ;
22
+ }
23
+
24
+ // we use our own stringify method instead of the one from @testing -library/dom,
25
+ // because it might have been removed for message transport.
26
+ function suggestionToString ( { queryArgs, queryMethod } ) {
27
+ let [ text , options ] = queryArgs ;
28
+
29
+ text = typeof text === 'string' ? `'${ text } '` : reviver ( text ) ;
30
+
31
+ options = options
32
+ ? `, { ${ Object . entries ( options )
33
+ . map ( ( [ k , v ] ) => `${ k } : ${ reviver ( v ) } ` )
34
+ . join ( ', ' ) } }`
35
+ : '' ;
36
+
37
+ return `${ queryMethod } (${ text } ${ options } )` ;
38
+ }
39
+
13
40
const Field = React . memo ( function Field ( {
14
41
data,
15
42
method,
@@ -19,11 +46,12 @@ const Field = React.memo(function Field({
19
46
} ) {
20
47
const field = getFieldName ( method ) ;
21
48
const value = data [ field ] ;
49
+
22
50
const handleClick = value
23
51
? ( ) => {
24
52
dispatch ( {
25
53
type : 'SET_QUERY' ,
26
- query : `screen.${ query . toString ( ) } ` ,
54
+ query : `screen.${ suggestionToString ( query ) } ` ,
27
55
} ) ;
28
56
}
29
57
: undefined ;
0 commit comments