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") + }) + }) })