Skip to content

Commit

Permalink
try fixing the flakiness of tooltip tests
Browse files Browse the repository at this point in the history
autofocusing an input seems to not work, causing the tooltip not to show, in some runs of tests on the CI pipeline. It's not reproducible locally, both using cypress open and cypress run.
  • Loading branch information
alirezamirian authored Dec 19, 2023
1 parent 0a341d8 commit 80eae00
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions packages/jui/src/Tooltip/Tooltip.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ describe("TooltipTrigger", () => {
workaroundHoverIssue();
cy.get("button").first().realHover();

cy.get("[role=tooltip]") // waiting for tooltip to appear
cy.findByRole("tooltip") // waiting for tooltip to appear
.realMouseMove(10, 10); // moving mouse out of the trigger and onto the tooltip.
cy.get("[role=tooltip]").should("not.exist"); //tooltip should be closed
cy.findByRole("tooltip").should("not.exist"); //tooltip should be closed
});

it("allows user to click links in a tooltip, if any", () => {
Expand All @@ -34,9 +34,9 @@ describe("TooltipTrigger", () => {
workaroundHoverIssue();
cy.get("button").realHover();

cy.get("[role=tooltip]") // waiting for tooltip to appear
cy.findByRole("tooltip") // waiting for tooltip to appear
.realMouseMove(10, 10); // moving mouse out of the trigger and onto the tooltip.
cy.get("[role=tooltip]"); //tooltip should not be closed
cy.findByRole("tooltip"); //tooltip should not be closed
});

it("doesn't show the tooltip if tooltip is disabled", () => {
Expand All @@ -51,18 +51,18 @@ describe("TooltipTrigger", () => {
cy.mount(<Default />);
workaroundHoverIssue();
cy.get("button").first().realHover();
cy.get("[role=tooltip]"); // waiting for tooltip to appear
cy.findByRole("tooltip"); // waiting for tooltip to appear
cy.get("button").click();
cy.get("[role=tooltip]").should("not.exist"); // tooltip should not be closed
cy.findByRole("tooltip").should("not.exist"); // tooltip should not be closed
});

it("doesn't close the tooltip on click, if the trigger is an input", () => {
cy.mount(<OnInput />);
workaroundHoverIssue();
cy.get("input").first().realHover();
cy.get("[role=tooltip]"); // waiting for tooltip to appear
cy.findByRole("tooltip"); // waiting for tooltip to appear
cy.get("input").click();
cy.get("[role=tooltip]"); // tooltip should not be closed
cy.findByRole("tooltip"); // tooltip should not be closed
});
});

Expand All @@ -78,9 +78,9 @@ describe("PositionedTooltipTrigger", () => {
</PositionedTooltipTrigger>
);
cy.get("input").first().focus();
cy.get("[role=tooltip]").should("exist");
cy.findByRole("tooltip").should("exist");
cy.get("input").first().blur();
cy.get("[role=tooltip]").should("not.exist");
cy.findByRole("tooltip").should("not.exist");
});

it("closes the tooltip when the tooltip is disabled while being open", () => {
Expand All @@ -102,9 +102,15 @@ describe("PositionedTooltipTrigger", () => {
);
};
cy.mount(<Example />);
cy.get("[role=tooltip]").should("exist");
cy.get("input").then((input) => {
// autofocus doesn't seem to work sometimes on CI runs, for some reason.
if (!input.is(":focused")) {
cy.get("input").focus();
}
});
cy.findByRole("tooltip").should("exist");
cy.realType("a");
cy.get("[role=tooltip]").should("not.exist");
cy.findByRole("tooltip").should("not.exist");
});
});

Expand Down

0 comments on commit 80eae00

Please sign in to comment.