@@ -2,6 +2,11 @@ import React from "react";
2
2
import ReactDOM from "react-dom" ;
3
3
import Methods , { IMethodPluginProps } from "./Methods" ;
4
4
import { OpenrpcDocument } from "@open-rpc/meta-schema" ;
5
+ import {
6
+ cleanup ,
7
+ fireEvent ,
8
+ render ,
9
+ } from "@testing-library/react" ;
5
10
6
11
it ( "renders without crashing" , ( ) => {
7
12
const div = document . createElement ( "div" ) ;
@@ -71,7 +76,7 @@ it("doesnt render collapsed contents with empty uiSchema", () => {
71
76
} ,
72
77
] ,
73
78
} ;
74
- ReactDOM . render ( < Methods schema = { schema as any } uiSchema = { { } } /> , div ) ;
79
+ ReactDOM . render ( < Methods schema = { schema as any } uiSchema = { { } } /> , div ) ;
75
80
expect ( div . innerHTML . includes ( "foobarz" ) ) . toBe ( false ) ;
76
81
ReactDOM . unmountComponentAtNode ( div ) ;
77
82
} ) ;
@@ -87,7 +92,7 @@ it("doesnt render collapsed contents with empty uiSchema.methods", () => {
87
92
} ,
88
93
] ,
89
94
} ;
90
- ReactDOM . render ( < Methods schema = { schema as any } uiSchema = { { methods : { } } } /> , div ) ;
95
+ ReactDOM . render ( < Methods schema = { schema as any } uiSchema = { { methods : { } } } /> , div ) ;
91
96
expect ( div . innerHTML . includes ( "foobarz" ) ) . toBe ( false ) ;
92
97
ReactDOM . unmountComponentAtNode ( div ) ;
93
98
} ) ;
@@ -208,7 +213,7 @@ it("renders schema plugin", () => {
208
213
209
214
ReactDOM . render (
210
215
< Methods schema = { schema as any } methodPlugins = { [ TestComponent ] } disableTransitionProps = { true } />
211
- , div ) ;
216
+ , div ) ;
212
217
expect ( div . innerHTML . includes ( "get_pet" ) ) . toBe ( true ) ;
213
218
expect ( div . innerHTML . includes ( "Plugin Test" ) ) . toBe ( true ) ;
214
219
ReactDOM . unmountComponentAtNode ( div ) ;
@@ -414,3 +419,29 @@ it("renders schema methods examples with schema.examples fallback", () => {
414
419
expect ( div . innerHTML . includes ( "bob" ) ) . toBe ( true ) ;
415
420
ReactDOM . unmountComponentAtNode ( div ) ;
416
421
} ) ;
422
+
423
+ it ( "can call onMethodToggle when a method is clicked" , ( done ) => {
424
+ const schema = {
425
+ methods : [
426
+ {
427
+ name : "foo" ,
428
+ params : [ {
429
+ name : "foobarz" ,
430
+ } ] ,
431
+ } ,
432
+ ] ,
433
+ } ;
434
+ const { getByText } = render (
435
+ < Methods
436
+ schema = { schema as any }
437
+ onMethodToggle = { ( method : string , expanded : boolean ) => {
438
+ expect ( method ) . toEqual ( "foo" ) ;
439
+ expect ( expanded ) . toEqual ( true ) ;
440
+ cleanup ( ) ;
441
+ done ( ) ;
442
+ } }
443
+ /> ,
444
+ ) ;
445
+ const node = getByText ( schema . methods [ 0 ] . name ) ;
446
+ fireEvent . click ( node ) ;
447
+ } ) ;
0 commit comments