Skip to content

Commit

Permalink
fix(realClick): only report secondary button being pressed with `butt…
Browse files Browse the repository at this point in the history
…on: right` (#271)
  • Loading branch information
Andarist committed Jun 14, 2022
1 parent 660025b commit 0f92778
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions cypress/integration/click.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ describe("cy.realClick", () => {
.realClick({ clickCount: 2 });
});

it("right click should only report secondary button being pressed", () => {
cy.get(".navbar-brand").then($navbarBrand => {
$navbarBrand.get(0).addEventListener('contextmenu', (ev) => {
ev.preventDefault()
expect(ev.buttons).to.eq(2)
})
})

cy.get('.navbar-brand').realClick({ button: 'right' })
});

describe("scroll behavior", () => {
function getScreenEdges() {
const cypressAppWindow = window.parent.document.querySelector("iframe")
Expand Down
5 changes: 3 additions & 2 deletions src/commands/realClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ScrollBehaviorOptions,
Position,
} from "../getCypressElementCoordinates";
import { mouseButtonNumbers } from "../mouseButtonNumbers";

export interface RealClickOptions {
/** Pointer type for realClick, if "pen" touch simulated */
Expand Down Expand Up @@ -74,7 +75,7 @@ export async function realClick(
x,
y,
clickCount: currentClick,
buttons: 1,
buttons: mouseButtonNumbers[options.button ?? "left"],
pointerType: options.pointer ?? "mouse",
button: options.button ?? "left",
});
Expand All @@ -84,7 +85,7 @@ export async function realClick(
x,
y,
clickCount: currentClick,
buttons: 1,
buttons: mouseButtonNumbers[options.button ?? "left"],
pointerType: options.pointer ?? "mouse",
button: options.button ?? "left",
});
Expand Down

0 comments on commit 0f92778

Please sign in to comment.