@@ -47,202 +47,6 @@ it("renders examples", async () => {
47
47
ReactDOM . unmountComponentAtNode ( div ) ;
48
48
} ) ;
49
49
50
- it ( "renders examples with only schema examples" , async ( ) => {
51
- const div = document . createElement ( "div" ) ;
52
- const testDoc : OpenrpcDocument = {
53
- info : {
54
- title : "test" ,
55
- version : "0.0.0" ,
56
- } ,
57
- methods : [
58
- {
59
- name : "test-method" ,
60
- params : [ {
61
- name : "testparam1" ,
62
- schema : {
63
- examples : [ "bob" ] ,
64
- type : "string" ,
65
- } ,
66
- } ] ,
67
- result : {
68
- name : "test-method-result" ,
69
- schema : {
70
- examples : [ "potato" ] ,
71
- type : "string" ,
72
- } ,
73
- } ,
74
- } ,
75
- ] ,
76
- openrpc : "1.0.0" ,
77
- } ;
78
-
79
- const method = testDoc . methods [ 0 ] as MethodObject ;
80
- ReactDOM . render (
81
- < ExamplePairings
82
- method = { method }
83
- examples = { method . examples as ExamplePairingObject [ ]
84
- } />
85
- , div ) ;
86
- expect ( div . innerHTML . includes ( "potato" ) ) . toBe ( true ) ;
87
- expect ( div . innerHTML . includes ( "bob" ) ) . toBe ( true ) ;
88
- ReactDOM . unmountComponentAtNode ( div ) ;
89
- } ) ;
90
-
91
- it ( "renders examples with only schema examples with no params" , async ( ) => {
92
- const div = document . createElement ( "div" ) ;
93
- const testDoc : OpenrpcDocument = {
94
- info : {
95
- title : "test" ,
96
- version : "0.0.0" ,
97
- } ,
98
- methods : [
99
- {
100
- name : "test-method" ,
101
- params : [ ] ,
102
- result : {
103
- name : "test-method-result" ,
104
- schema : {
105
- examples : [ "potato" ] ,
106
- type : "string" ,
107
- } ,
108
- } ,
109
- } ,
110
- ] ,
111
- openrpc : "1.0.0" ,
112
- } ;
113
-
114
- const method = testDoc . methods [ 0 ] as MethodObject ;
115
- ReactDOM . render (
116
- < ExamplePairings
117
- method = { method }
118
- examples = { method . examples as ExamplePairingObject [ ]
119
- } />
120
- , div ) ;
121
- expect ( div . innerHTML . includes ( "potato" ) ) . toBe ( true ) ;
122
- expect ( div . innerHTML . includes ( "bob" ) ) . toBe ( false ) ;
123
- ReactDOM . unmountComponentAtNode ( div ) ;
124
- } ) ;
125
-
126
- it ( "renders examples with multiple param schema examples and no method" , async ( ) => {
127
- const div = document . createElement ( "div" ) ;
128
- const testDoc : OpenrpcDocument = {
129
- info : {
130
- title : "test" ,
131
- version : "0.0.0" ,
132
- } ,
133
- methods : [
134
- {
135
- name : "test-method" ,
136
- params : [
137
- {
138
- name : "testparam1" ,
139
- schema : {
140
- examples : [ "bob" ] ,
141
- type : "string" ,
142
- } ,
143
- } ,
144
- {
145
- name : "testparam2" ,
146
- schema : {
147
- examples : [ "bob2" ] ,
148
- type : "string" ,
149
- } ,
150
- } ,
151
- ] ,
152
- result : {
153
- name : "test-method-result" ,
154
- schema : {
155
- examples : [ "potato" ] ,
156
- type : "string" ,
157
- } ,
158
- } ,
159
- } ,
160
- ] ,
161
- openrpc : "1.0.0" ,
162
- } ;
163
-
164
- const method = testDoc . methods [ 0 ] as MethodObject ;
165
- ReactDOM . render (
166
- < ExamplePairings method = { method } />
167
- , div ) ;
168
- expect ( div . innerHTML . includes ( "bob" ) ) . toBe ( true ) ;
169
- expect ( div . innerHTML . includes ( "bob2" ) ) . toBe ( true ) ;
170
- ReactDOM . unmountComponentAtNode ( div ) ;
171
- } ) ;
172
-
173
- it ( "renders examples with only schema examples and no method" , async ( ) => {
174
- const div = document . createElement ( "div" ) ;
175
- const testDoc : OpenrpcDocument = {
176
- info : {
177
- title : "test" ,
178
- version : "0.0.0" ,
179
- } ,
180
- methods : [
181
- {
182
- name : "test-method" ,
183
- params : [ {
184
- name : "testparam1" ,
185
- schema : {
186
- examples : [ "bob" ] ,
187
- type : "string" ,
188
- } ,
189
- } ] ,
190
- result : {
191
- name : "test-method-result" ,
192
- schema : {
193
- examples : [ "potato" ] ,
194
- type : "string" ,
195
- } ,
196
- } ,
197
- } ,
198
- ] ,
199
- openrpc : "1.0.0" ,
200
- } ;
201
- const method = testDoc . methods [ 0 ] as MethodObject ;
202
- ReactDOM . render (
203
- < ExamplePairings
204
- examples = { method . examples as ExamplePairingObject [ ]
205
- } />
206
- , div ) ;
207
- ReactDOM . unmountComponentAtNode ( div ) ;
208
- } ) ;
209
-
210
- it ( "renders examples with only schema examples and no method with number" , async ( ) => {
211
- const div = document . createElement ( "div" ) ;
212
- const testDoc : OpenrpcDocument = {
213
- info : {
214
- title : "test" ,
215
- version : "0.0.0" ,
216
- } ,
217
- methods : [
218
- {
219
- name : "test-method" ,
220
- params : [ {
221
- name : "testparam1" ,
222
- schema : {
223
- examples : [ 10101 ] ,
224
- type : "number" ,
225
- } ,
226
- } ] ,
227
- result : {
228
- name : "test-method-result" ,
229
- schema : {
230
- examples : [ "potato" ] ,
231
- type : "string" ,
232
- } ,
233
- } ,
234
- } ,
235
- ] ,
236
- openrpc : "1.0.0" ,
237
- } ;
238
- const method = testDoc . methods [ 0 ] as MethodObject ;
239
- ReactDOM . render (
240
- < ExamplePairings
241
- examples = { method . examples as ExamplePairingObject [ ]
242
- } />
243
- , div ) ;
244
- ReactDOM . unmountComponentAtNode ( div ) ;
245
- } ) ;
246
50
it ( "renders examples with only schema examples and no method with multiple number examples" , async ( ) => {
247
51
const div = document . createElement ( "div" ) ;
248
52
const testDoc : OpenrpcDocument = {
@@ -284,18 +88,19 @@ it("renders examples with only schema examples and no method with multiple numbe
284
88
it ( "renders examples and can switch between them" , async ( ) => {
285
89
const simpleMath = await refParser . dereference ( examples . simpleMath as any ) as OpenrpcDocument ;
286
90
const method = simpleMath . methods [ 0 ] as MethodObject ;
287
- const { getByText } = render (
91
+ const { getByText, getByTestId , getAllByTestId } = render (
288
92
< ExamplePairings
289
93
method = { method }
290
94
examples = { method . examples as ExamplePairingObject [ ]
291
95
} /> ,
292
96
) ;
293
- const node = getByText ( "simpleMathAdditionTwo" ) ;
294
- fireEvent . click ( node ) ;
295
- const secondExampleMenuItem = getByText ( "simpleMathAdditionFour" ) ;
296
- fireEvent . click ( secondExampleMenuItem ) ;
297
- const example8 = getByText ( "8" ) ;
298
- expect ( example8 ) . toBeDefined ( ) ;
97
+ const node = getByTestId ( 'example-pairing-select' ) ;
98
+ fireEvent . change ( node , { target : { value : '1' } } ) ;
99
+ let options = getAllByTestId ( 'example-pairing-option' ) ;
100
+ if ( ! options || ! options [ 1 ] ) {
101
+ throw new Error ( "Expected two options" ) ;
102
+ }
103
+ expect ( ( options [ 1 ] as HTMLOptionElement ) . selected ) . toBeTruthy ( ) ;
299
104
cleanup ( ) ;
300
105
} ) ;
301
106
0 commit comments