Skip to content

Commit

Permalink
Fix a flaky test in revision history suite (#40359) (#40405)
Browse files Browse the repository at this point in the history
* Clean up test

* Fix race condition

* Wait for GET dashboard + for sidebar to close

* Add wait

* Add a sad comment

Co-authored-by: Anton Kulyk <kuliks.anton@gmail.com>
  • Loading branch information
metabase-bot[bot] and kulyk committed Mar 20, 2024
1 parent 9e81478 commit c971ad5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion e2e/support/helpers/e2e-ui-elements-helpers.js
Expand Up @@ -38,7 +38,7 @@ export function sidebar() {
}

export function rightSidebar() {
return cy.findAllByTestId("sidebar-right");
return cy.findByTestId("sidebar-right");
}

export function leftSidebar() {
Expand Down
42 changes: 26 additions & 16 deletions e2e/test/scenarios/collections/revision-history.cy.spec.js
Expand Up @@ -12,6 +12,8 @@ import {
questionInfoButton,
rightSidebar,
openQuestionsSidebar,
editDashboard,
sidebar,
} from "e2e/support/helpers";

const PERMISSIONS = {
Expand All @@ -34,12 +36,13 @@ describe("revision history", () => {

it("shouldn't render revision history steps when there was no diff (metabase#1926)", () => {
cy.createDashboard().then(({ body }) => {
visitAndEditDashboard(body.id);
visitDashboard(body.id);
editDashboard();
});

// Save the dashboard without any changes made to it (TODO: we should probably disable "Save" button in the first place)
saveDashboard();
cy.icon("pencil").click();
editDashboard();
saveDashboard();

openRevisionHistory();
Expand Down Expand Up @@ -71,20 +74,32 @@ describe("revision history", () => {
});

it("shouldn't create a rearrange revision when adding a card (metabase#6884)", () => {
cy.intercept("GET", "/api/dashboard/*").as("fetchDashboard");
cy.intercept("POST", "/api/card/*/query").as("cardQuery");

cy.createDashboard().then(({ body }) => {
visitAndEditDashboard(body.id);
visitDashboard(body.id);
editDashboard();
});

openQuestionsSidebar();
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Orders, Count").click();
sidebar().findByText("Orders, Count").click();
cy.wait("@cardQuery");
saveDashboard();

// this is dirty, but seems like the only reliable way
// to wait until SET_DASHBOARD_EDITING is dispatched,
// so it doesn't close the revisions sidebar
cy.wait("@fetchDashboard");
cy.wait(100);

openRevisionHistory();
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText(/added a card/)
.siblings("button")
.should("not.exist");
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText(/rearranged the cards/).should("not.exist");
rightSidebar().within(() => {
cy.findByText(/added a card/)
.siblings("button")
.should("not.exist");
cy.findByText(/rearranged the cards/).should("not.exist");
});
});

// skipped because it's super flaky in CI
Expand Down Expand Up @@ -185,11 +200,6 @@ function clickRevert(event_name, index = 0) {
cy.findAllByLabelText(event_name).eq(index).click();
}

function visitAndEditDashboard(id) {
visitDashboard(id);
cy.icon("pencil").click();
}

function openRevisionHistory() {
cy.intercept("GET", "/api/revision*").as("revisionHistory");
cy.get("main header").within(() => {
Expand Down

0 comments on commit c971ad5

Please sign in to comment.