Skip to content

Commit

Permalink
Support for the aliases.
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Jul 30, 2020
1 parent e722ebf commit 7393711
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
24 changes: 24 additions & 0 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2324,12 +2324,24 @@ declare namespace Cypress {
* @default false
*/
ctrlKey: boolean
/**
* Alias for the ctrl key
*
* @default false
*/
controlKey: boolean
/**
* Press alt key. It's option key in Mac.
*
* @default false
*/
altKey: boolean
/**
* Alias for the alt key.
*
* @default false
*/
optionKey: boolean
/**
* Press shift key
*
Expand All @@ -2342,6 +2354,18 @@ declare namespace Cypress {
* @default false
*/
metaKey: boolean
/**
* Alias for the meta key.
*
* @default false
*/
commandKey: boolean
/**
* Alias for the meta key.
*
* @default false
*/
cmdKey: boolean
}

interface ResolvedConfigOptions {
Expand Down
24 changes: 24 additions & 0 deletions packages/driver/cypress/integration/commands/actions/click_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,12 @@ describe('src/cy/commands/actions/click', () => {
// ctrl should be released
cy.get('#button').click()
cy.get('#result').should('not.contain', '{Ctrl}')

cy.get('#button').click({
controlKey: true,
})

cy.get('#result').should('contain', '{Ctrl}')
})

it('alt', () => {
Expand All @@ -909,6 +915,12 @@ describe('src/cy/commands/actions/click', () => {
// alt should be released
cy.get('#button').click()
cy.get('#result').should('not.contain', '{Alt}')

cy.get('#button').click({
optionKey: true,
})

cy.get('#result').should('contain', '{Alt}')
})

it('shift', () => {
Expand All @@ -933,6 +945,18 @@ describe('src/cy/commands/actions/click', () => {
// shift should be released
cy.get('#button').click()
cy.get('#result').should('not.contain', '{Meta}')

cy.get('#button').click({
commandKey: true,
})

cy.get('#result').should('contain', '{Meta}')

cy.get('#button').click({
cmdKey: true,
})

cy.get('#result').should('contain', '{Meta}')
})

it('multiple', () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/driver/src/cy/commands/actions/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = (Commands, Cypress, cy, state, config) => {
ctrlKey: false,
altKey: false,
shiftKey: false,
cmdKey: false,
...defaultOptions,
})

Expand All @@ -69,19 +70,19 @@ module.exports = (Commands, Cypress, cy, state, config) => {
}

const flagModifiers = (press) => {
if (options.ctrlKey) {
if (options.ctrlKey || options.controlKey) {
keyboard.flagModifier({ key: 'Control' }, press)
}

if (options.altKey) {
if (options.altKey || options.optionKey) {
keyboard.flagModifier({ key: 'Alt' }, press)
}

if (options.shiftKey) {
keyboard.flagModifier({ key: 'Shift' }, press)
}

if (options.metaKey) {
if (options.metaKey || options.commandKey || options.cmdKey) {
keyboard.flagModifier({ key: 'Meta' }, press)
}
}
Expand Down

0 comments on commit 7393711

Please sign in to comment.