Skip to content

Fix reportsDashboards edit spec flakiness with API intercepts - #2112

Merged
rishabh6788 merged 1 commit into
opensearch-project:mainfrom
sumukhswamy:fix/reports-edit-spec-main
Jul 27, 2026
Merged

Fix reportsDashboards edit spec flakiness with API intercepts#2112
rishabh6788 merged 1 commit into
opensearch-project:mainfrom
sumukhswamy:fix/reports-edit-spec-main

Conversation

@sumukhswamy

@sumukhswamy sumukhswamy commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes intermittent failures in the reportsDashboards integration test (02-edit.spec.js) caused by the edit page tests clicking and asserting UI state without waiting for the underlying API responses.

Changes:

  • Add REPORT_DEFINITION_API constant for the reportDefinitions endpoint pattern
  • Add setupEditIntercepts() — registers cy.intercept for GET and PUT on the report definition API
  • Add openEditPage() — clicks into the edit page and waits for @getReportDefinition before asserting
  • Add clickSaveChanges() — clicks Save and waits for @updateReportDefinition with status 200 assertion
  • Replace inline click sequences with the new helpers in all three test cases
  • Add .should('be.checked') assertions after radio button interactions

Root cause: Tests were clicking without waiting for API responses, causing the "before all" hook to fail when the edit page hadn't loaded yet.

Fixes: opensearch-project/dashboards-reporting#785

Test plan

  • reportsDashboards integration tests pass on 3.8.0 without-security

Add cy.intercept() helpers for the GET and PUT reportDefinitions API
calls so the edit page tests wait for network responses before
asserting UI state. The previous implementation clicked without
waiting, causing intermittent "before all" hook failures when the
edit page had not fully loaded.

Fixes: opensearch-project/dashboards-reporting#785
Signed-off-by: sumukhswamy <sumukhhs@amazon.com>
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Use proper origin value not full URL

BASE_PATH typically includes a scheme+host+path, but the origin header/param should
generally be just scheme+host (an origin, not a full URL with a path). Setting
origin to a value containing a path may cause the backend to reject the request or
fail origin validation. Confirm the expected format and use only the origin portion
of BASE_PATH.

cypress/integration/plugins/reports-dashboards/02-edit.spec.js [13-22]

 cy.intercept('PUT', REPORT_DEFINITION_API, (req) => {
-  req.headers['origin'] = BASE_PATH;
+  const originValue = new URL(BASE_PATH).origin;
+  req.headers['origin'] = originValue;
   if (
     req.body &&
     req.body.report_params &&
     req.body.report_params.core_params
   ) {
-    req.body.report_params.core_params.origin = BASE_PATH;
+    req.body.report_params.core_params.origin = originValue;
   }
 }).as('updateReportDefinition');
Suggestion importance[1-10]: 5

__

Why: Setting origin header to a full URL with path may indeed be incorrect, but without knowing the backend's validation logic, this is speculative; the suggestion is reasonable but its impact is uncertain.

Low
General
Use robust selector for radio input

Clicking the first trigger type div may not select the "On demand" radio in all UI
states, and the escaped selector #On\ demand targets an ID containing a space,
which is fragile. Verify the actual radio input ID/selector used by the component,
and prefer selecting the radio directly (or use [id="On demand"]) to avoid selector
parsing issues.

cypress/integration/plugins/reports-dashboards/02-edit.spec.js [114]

 cy.get('#reportDefinitionTriggerTypes > div:nth-child(1)').click({
   force: true,
 });
 
-cy.get('#On\\ demand').check({ force: true }).should('be.checked');
+cy.get('[id="On demand"]').check({ force: true }).should('be.checked');
Suggestion importance[1-10]: 3

__

Why: The existing escaped selector #On\\ demand works in Cypress, and the suggestion is a minor readability/robustness improvement without evidence of a real issue.

Low

@rishabh6788
rishabh6788 merged commit 04be670 into opensearch-project:main Jul 27, 2026
64 checks passed
rishabh6788 pushed a commit that referenced this pull request Jul 27, 2026
…#2118)

Add cy.intercept() helpers for the GET and PUT reportDefinitions API
calls so the edit page tests wait for network responses before
asserting UI state. The previous implementation clicked without
waiting, causing intermittent "before all" hook failures when the
edit page had not fully loaded.

Fixes: opensearch-project/dashboards-reporting#785


(cherry picked from commit 04be670)

Signed-off-by: sumukhswamy <sumukhhs@amazon.com>
Signed-off-by: opensearch-ci-bot <opensearch-infra@amazon.com>
Co-authored-by: Sumukh Swamy <sumukhhs@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AUTOCUT] Integration Test Failed for reportsDashboards-3.8.0

3 participants