test(oas3): add regression coverage for #5460 media-type example switching#10888
Open
yogeshwaran-c wants to merge 1 commit into
Open
Conversation
…xample switching Adds unit and Cypress e2e tests that exercise the repro from swagger-api#5460: switching media types after picking a non-default example must refresh the displayed Example Value and snap the Examples dropdown to a key that exists under the new media type. The bug as reported against 3.23.0 was fixed by PR swagger-api#6837 (Jan 2021), which replaced the schema-equality branch in `Parameters.onChangeMediaType` with an unconditional body reset when the user has not edited the body. These tests pin that behavior so future refactors of the request-body / examples plumbing do not regress it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Regression test only — no production code changes.
Closes #5460
What is the current behavior?
#5460 reported (against v3.23.0) that switching between media types in an OAS3 `requestBody` whose `content` map has multiple media types — each with their own `examples` block — did not refresh the displayed Example Value when a non-default example was selected first. Specifically:
What is the new behavior?
The bug was fixed by PR #6837 (`e877580d`, Jan 2021). Before that fix, `Parameters.onChangeMediaType` only called `clearRequestBodyValue` when the two media types' schemas differed by `isMediaTypeSchemaPropertiesEqual`. In the repro both `application/json` and `application/xml` declare `schema: { type: object }`, so the previously-selected example's value stayed in `requestBodyValue` and kept rendering inside the Example Value pane. #6837 replaced that branch with an unconditional reset (`setRequestBodyValue({ value: undefined })`) when the user has not edited the body, which lets the new media type's sample take over.
This PR pins that behavior with three layers of coverage so future refactors of the request-body / examples plumbing don't silently regress it.
Coverage added
Unit test — `test/unit/components/examples-select.jsx`
Covers `ExamplesSelect.UNSAFE_componentWillReceiveProps`: when the `examples` Map changes from under the component and the previous `currentExampleKey` is no longer present, a synthetic `onSelect` is fired with the first key of the new examples Map. Also covers no-op cases (key still present, identical reference) and the initial `componentDidMount` synthetic select.
State-integration test — `test/unit/core/plugins/oas3/state-integration-5460.js`
Documents the contract between `setRequestContentType` and `setActiveExamplesMember`: the reducer for the former intentionally does not clear the latter, so the UI layer must reconcile the stale active-example key when `examples` change. Includes the synthetic-select dispatch path that updates the active example after a media-type switch.
Cypress e2e test — `test/e2e-cypress/e2e/bugs/5460.cy.js`
Walks the exact repro from the issue against `test/e2e-cypress/static/documents/bugs/5460.yaml` (the spec from the original report). Four cases:
How has this been tested?