Skip to content

Commit 0ab2d44

Browse files
authored
Merge pull request #450 from open-rpc/fix/method-expanded-guardds
fix: method expanded guards
2 parents e82dde0 + add4283 commit 0ab2d44

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/Methods/Methods.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,38 @@ it("doesnt render collapsed contents", () => {
6060
ReactDOM.unmountComponentAtNode(div);
6161
});
6262

63+
it("doesnt render collapsed contents with empty uiSchema", () => {
64+
const div = document.createElement("div");
65+
const schema = {
66+
methods: [
67+
{
68+
params: [{
69+
name: "foobarz",
70+
}],
71+
},
72+
],
73+
};
74+
ReactDOM.render(<Methods schema={schema as any} uiSchema={{}}/>, div);
75+
expect(div.innerHTML.includes("foobarz")).toBe(false);
76+
ReactDOM.unmountComponentAtNode(div);
77+
});
78+
79+
it("doesnt render collapsed contents with empty uiSchema.methods", () => {
80+
const div = document.createElement("div");
81+
const schema = {
82+
methods: [
83+
{
84+
params: [{
85+
name: "foobarz",
86+
}],
87+
},
88+
],
89+
};
90+
ReactDOM.render(<Methods schema={schema as any} uiSchema={{methods: {}}}/>, div);
91+
expect(div.innerHTML.includes("foobarz")).toBe(false);
92+
ReactDOM.unmountComponentAtNode(div);
93+
});
94+
6395
it("renders collapsed contents with defaultExpanded from uiSchema", () => {
6496
const div = document.createElement("div");
6597
const schema = {

src/Methods/Methods.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ class Methods extends Component<IProps> {
7272
id={method.name}
7373
key={i + method.name}
7474
TransitionProps={{ unmountOnExit: disableTransitionProps ? false : true }}
75-
defaultExpanded={uiSchema && (uiSchema.methods["ui:defaultExpanded"] === true || uiSchema.methods["ui:defaultExpanded"][method.name] === true)}
76-
>
75+
defaultExpanded={
76+
uiSchema &&
77+
uiSchema.methods &&
78+
(uiSchema.methods["ui:defaultExpanded"] === true ||
79+
(uiSchema.methods["ui:defaultExpanded"] && uiSchema.methods["ui:defaultExpanded"][method.name] === true)
80+
)
81+
}>
7782
<ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
7883
<Typography key={method.name} className={classes.heading}>{method.name}</Typography>
7984
<Typography key={method.summary} className={classes.secondaryHeading}>{method.summary}</Typography>

0 commit comments

Comments
 (0)