@@ -3,13 +3,73 @@ import ReactDOM from "react-dom";
33import ExamplePairing from "./ExamplePairing";
44import examples from "@open-rpc/examples";
55import refParser from "json-schema-ref-parser";
6- import { OpenRPC } from "@open-rpc/meta-schema";
6+ import { OpenrpcDocument } from "@open-rpc/meta-schema";
7+
8+ it("renders handles no method", async () => {
9+ const div = document.createElement("div");
10+ ReactDOM.render(<ExamplePairing method={undefined} examplePosition={0}/>, div);
11+ expect(div.innerHTML).toBe("");
12+ ReactDOM.unmountComponentAtNode(div);
13+ });
14+
15+ it("renders handles no method examples", async () => {
16+ const div = document.createElement("div");
17+ ReactDOM.render(<ExamplePairing method={{} as any} examplePosition={0} />, div);
18+ expect(div.innerHTML).toBe("");
19+ ReactDOM.unmountComponentAtNode(div);
20+ });
21+
22+ it("renders handles no examplePosition", async () => {
23+ const div = document.createElement("div");
24+ const simpleMath = await refParser.dereference(examples.simpleMath) as OpenrpcDocument;
25+ ReactDOM.render(<ExamplePairing method={simpleMath.methods[0]} />, div);
26+ expect(div.innerHTML).toBe("");
27+ ReactDOM.unmountComponentAtNode(div);
28+ });
729
830it("renders examples", async () => {
931 const div = document.createElement("div");
10- const simpleMath = await refParser.dereference(examples.simpleMath) as OpenRPC ;
32+ const simpleMath = await refParser.dereference(examples.simpleMath) as OpenrpcDocument ;
1133 ReactDOM.render(<ExamplePairing method={simpleMath.methods[0]} examplePosition={0} />, div);
1234 expect(div.innerHTML.includes("2")).toBe(true);
1335 expect(div.innerHTML.includes("4")).toBe(true);
1436 ReactDOM.unmountComponentAtNode(div);
1537});
38+
39+ it("renders examples with params by-name", async () => {
40+ const div = document.createElement("div");
41+ ReactDOM.render(<ExamplePairing method={{
42+ examples: [
43+ {
44+ name: "fooExample",
45+ params: [
46+ {
47+ name: "foo",
48+ value: "bar",
49+ },
50+ ],
51+ result: {
52+ name: "exampleResultThing",
53+ value: "potato",
54+ },
55+ },
56+ ],
57+ name: "myMethod",
58+ paramStructure: "by-name",
59+ params: [{
60+ name: "foo",
61+ schema: {
62+ type: "string",
63+ },
64+ }],
65+ result: {
66+ name: "resultThing",
67+ schema: {
68+ type: "string",
69+ },
70+ },
71+ }} examplePosition={0} />, div);
72+ expect(div.innerHTML.includes("foo")).toBe(true);
73+ expect(div.innerHTML.includes("bar")).toBe(true);
74+ ReactDOM.unmountComponentAtNode(div);
75+ });
0 commit comments