@@ -8,31 +8,50 @@ function Code({ children }) {
8
8
return < span className = "font-bold font-mono" > { children } </ span > ;
9
9
}
10
10
11
- function ResultSuggestion ( { data, suggestion, result, dispatch } ) {
11
+ const levels = {
12
+ Role : 0 ,
13
+ LabelText : 0 ,
14
+ PlaceholderText : 0 ,
15
+ Text : 0 ,
16
+ DisplayValue : 0 ,
17
+ AltText : 1 ,
18
+ Title : 1 ,
19
+ TestId : 2 ,
20
+ generic : 3 ,
21
+ } ;
22
+
23
+ function ResultSuggestion ( { queries, result, dispatch } ) {
24
+ const suggestion = Object . values ( queries ) . find ( Boolean ) ;
12
25
const used = result ?. expression || { } ;
13
26
14
- const usingAdvisedMethod = suggestion . method === used . method ;
15
- const hasNameArg = data . name && used . args ?. [ 1 ] ?. includes ( 'name' ) ;
27
+ if ( ! suggestion ) {
28
+ return `Hmpf. I'm afraid I don't have any suggestions for you.` ;
29
+ }
30
+
31
+ const usingAdvisedMethod = suggestion . queryMethod === used . method ;
32
+ const nameOption = suggestion . queryArgs [ 1 ] ?. name ;
33
+ const hasNameArg = nameOption && used . args ?. [ 1 ] ?. includes ( 'name' ) ;
16
34
17
- const color = usingAdvisedMethod ? 'bg-green-600' : colors [ suggestion . level ] ;
35
+ const level = levels [ suggestion . queryName ] ?? 3 ;
36
+ const color = usingAdvisedMethod ? 'bg-green-600' : colors [ level ] ;
18
37
19
38
const target = result ?. target || { } ;
20
39
21
40
let message ;
22
41
23
- if ( suggestion . level < used . level ) {
42
+ if ( level < used . level ) {
24
43
message = (
25
44
< p >
26
45
You're using < Code > { used . method } </ Code > , which falls under{ ' ' }
27
46
< Code > { messages [ used . level ] . heading } </ Code > . Upgrading to{ ' ' }
28
- < Code > { suggestion . method } </ Code > is recommended.
47
+ < Code > { suggestion . queryMethod } </ Code > is recommended.
29
48
</ p >
30
49
) ;
31
- } else if ( suggestion . level === 0 && suggestion . method !== used . method ) {
50
+ } else if ( level === 0 && suggestion . queryMethod !== used . method ) {
32
51
message = (
33
52
< p >
34
53
Nice! < Code > { used . method } </ Code > is a great selector! Using{ ' ' }
35
- < Code > { suggestion . method } </ Code > would still be preferable though.
54
+ < Code > { suggestion . queryMethod } </ Code > would still be preferable though.
36
55
</ p >
37
56
) ;
38
57
} else if ( target . tagName === 'INPUT' && ! target . getAttribute ( 'type' ) ) {
@@ -44,9 +63,9 @@ function ResultSuggestion({ data, suggestion, result, dispatch }) {
44
63
</ p >
45
64
) ;
46
65
} else if (
47
- suggestion . level === 0 &&
48
- suggestion . method === 'getByRole' &&
49
- ! data . name
66
+ level === 0 &&
67
+ suggestion . queryMethod === 'getByRole' &&
68
+ ! nameOption
50
69
) {
51
70
message = (
52
71
< p >
@@ -56,9 +75,9 @@ function ResultSuggestion({ data, suggestion, result, dispatch }) {
56
75
</ p >
57
76
) ;
58
77
} else if (
59
- suggestion . level === 0 &&
60
- suggestion . method === 'getByRole' &&
61
- data . name &&
78
+ level === 0 &&
79
+ suggestion . queryMethod === 'getByRole' &&
80
+ nameOption &&
62
81
! hasNameArg
63
82
) {
64
83
message = (
@@ -83,23 +102,23 @@ function ResultSuggestion({ data, suggestion, result, dispatch }) {
83
102
< div className = "space-y-4 text-sm" >
84
103
< div className = { [ 'text-white p-4 rounded space-y-2' , color ] . join ( ' ' ) } >
85
104
< div className = "font-bold text-xs" > suggested query</ div >
86
- { suggestion . expression && (
105
+ { suggestion . excerpt && (
87
106
< div className = "flex justify-between" >
88
107
< div
89
108
className = "font-mono cursor-pointer text-xs"
90
109
onClick = { ( ) =>
91
110
dispatch ( {
92
111
type : 'SET_QUERY' ,
93
- query : suggestion . expression ,
112
+ query : suggestion . snippet ,
94
113
} )
95
114
}
96
115
>
97
- > { suggestion . expression }
116
+ > { suggestion . excerpt }
98
117
< br />
99
118
</ div >
100
119
< CopyButton
101
120
title = "copy query"
102
- text = { suggestion . expression }
121
+ text = { suggestion . snippet }
103
122
variant = "white"
104
123
/>
105
124
</ div >
0 commit comments