Skip to content

test(oas3): add regression coverage for #5460 media-type example switching#10888

Open
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/oas3-example-not-updated-on-media-type-switch
Open

test(oas3): add regression coverage for #5460 media-type example switching#10888
yogeshwaran-c wants to merge 1 commit into
swagger-api:masterfrom
yogeshwaran-c:fix/oas3-example-not-updated-on-media-type-switch

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

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:

  1. Select example `bar_json` under `application/json`.
  2. Switch media type to `application/xml`. → Examples dropdown updates, but the rendered Example Value pane keeps showing the JSON example.
  3. Switch to `text/plain`. → Still shows the JSON; should show `Hello, world!`.

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:

    1. `json/bar_json` → `application/xml`: Example Value pane shows XML, not the JSON object.
    2. `json/bar_json` → `text/plain`: Example Value pane shows `Hello, world!`.
    3. Examples dropdown auto-snaps to `foo_xml` when the previous `bar_json` key disappears.
    4. Full repro path `json/bar_json` → xml → text/plain in one go.

How has this been tested?

  • `npx jest --config ./config/jest/jest.unit.config.js test/unit/components/examples-select.jsx test/unit/core/plugins/oas3/state-integration-5460.js` — 8/8 passing.
  • `npx cypress run --spec test/e2e-cypress/e2e/bugs/5460.cy.js` — 4/4 passing on current master.
  • `npm run build` and `npm run test:artifact` both succeed.
  • `npx eslint --max-warnings 0` clean on all three new test files.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Displayed example not updated sometimes when switching between media types

1 participant