@@ -2,6 +2,11 @@ import React from "react";
22import ReactDOM from "react-dom" ;
33import Methods , { IMethodPluginProps } from "./Methods" ;
44import { OpenrpcDocument } from "@open-rpc/meta-schema" ;
5+ import {
6+ cleanup ,
7+ fireEvent ,
8+ render ,
9+ } from "@testing-library/react" ;
510
611it ( "renders without crashing" , ( ) => {
712 const div = document . createElement ( "div" ) ;
@@ -71,7 +76,7 @@ it("doesnt render collapsed contents with empty uiSchema", () => {
7176 } ,
7277 ] ,
7378 } ;
74- ReactDOM . render ( < Methods schema = { schema as any } uiSchema = { { } } /> , div ) ;
79+ ReactDOM . render ( < Methods schema = { schema as any } uiSchema = { { } } /> , div ) ;
7580 expect ( div . innerHTML . includes ( "foobarz" ) ) . toBe ( false ) ;
7681 ReactDOM . unmountComponentAtNode ( div ) ;
7782} ) ;
@@ -87,7 +92,7 @@ it("doesnt render collapsed contents with empty uiSchema.methods", () => {
8792 } ,
8893 ] ,
8994 } ;
90- ReactDOM . render ( < Methods schema = { schema as any } uiSchema = { { methods : { } } } /> , div ) ;
95+ ReactDOM . render ( < Methods schema = { schema as any } uiSchema = { { methods : { } } } /> , div ) ;
9196 expect ( div . innerHTML . includes ( "foobarz" ) ) . toBe ( false ) ;
9297 ReactDOM . unmountComponentAtNode ( div ) ;
9398} ) ;
@@ -208,7 +213,7 @@ it("renders schema plugin", () => {
208213
209214 ReactDOM . render (
210215 < Methods schema = { schema as any } methodPlugins = { [ TestComponent ] } disableTransitionProps = { true } />
211- , div ) ;
216+ , div ) ;
212217 expect ( div . innerHTML . includes ( "get_pet" ) ) . toBe ( true ) ;
213218 expect ( div . innerHTML . includes ( "Plugin Test" ) ) . toBe ( true ) ;
214219 ReactDOM . unmountComponentAtNode ( div ) ;
@@ -414,3 +419,29 @@ it("renders schema methods examples with schema.examples fallback", () => {
414419 expect ( div . innerHTML . includes ( "bob" ) ) . toBe ( true ) ;
415420 ReactDOM . unmountComponentAtNode ( div ) ;
416421} ) ;
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