From 18e1212ae0372bab08cda968bd162cea6bbcbaaf Mon Sep 17 00:00:00 2001 From: Scott O'Hara Date: Tue, 18 Nov 2025 10:18:18 +1100 Subject: [PATCH] fix: oas 3.1 schema expand/collapse not working on initial render --- src/core/plugins/json-schema-2020-12/hooks.js | 4 +-- .../json-schema-2020-12/expansion.cy.js | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/core/plugins/json-schema-2020-12/hooks.js b/src/core/plugins/json-schema-2020-12/hooks.js index 0d84388ac3d..0b0ac4f1571 100644 --- a/src/core/plugins/json-schema-2020-12/hooks.js +++ b/src/core/plugins/json-schema-2020-12/hooks.js @@ -121,11 +121,11 @@ export const useIsExpanded = (name) => { ? JSONSchemaIsExpandedState.DeeplyExpanded : JSONSchemaIsExpandedState.Expanded ) - }, []) + }, [pathMutator]) const setCollapsed = useCallback((options = { deep: false }) => { pathMutator(JSONSchemaIsExpandedState.Collapsed, options) - }, []) + }, [pathMutator]) return { isExpanded, setExpanded, setCollapsed } } diff --git a/test/e2e-cypress/e2e/features/plugins/json-schema-2020-12/expansion.cy.js b/test/e2e-cypress/e2e/features/plugins/json-schema-2020-12/expansion.cy.js index 0e98cd1a99b..32a88509d13 100644 --- a/test/e2e-cypress/e2e/features/plugins/json-schema-2020-12/expansion.cy.js +++ b/test/e2e-cypress/e2e/features/plugins/json-schema-2020-12/expansion.cy.js @@ -17,4 +17,32 @@ describe("JSON Schema 2020-12 complex keywords expansion", () => { ) }) }) + + it("should collapse and expand accordion on initial render click", () => { + cy.visit("/pages/json-schema-2020-12-expansion/").then(() => { + cy.get(".json-schema-2020-12-accordion").should("exist") + cy.contains("p1") + .closest(".json-schema-2020-12") + .find(".json-schema-2020-12-accordion__icon--expanded") + .should("exist") + cy.contains("p1") + .closest(".json-schema-2020-12") + .find(".json-schema-2020-12-accordion") + .first() + .click() + cy.contains("p1") + .closest(".json-schema-2020-12") + .find(".json-schema-2020-12-accordion__icon--collapsed") + .should("exist") + cy.contains("p1") + .closest(".json-schema-2020-12") + .find(".json-schema-2020-12-accordion") + .first() + .click() + cy.contains("p1") + .closest(".json-schema-2020-12") + .find(".json-schema-2020-12-accordion__icon--expanded") + .should("exist") + }) + }) })