Skip to content

Commit

Permalink
Fix selector playground triggering keyboard shortcut (#5285)
Browse files Browse the repository at this point in the history
* don’t trigger shortcuts if typing into a text-like element

* refactor / cleanup
  • Loading branch information
chrisbreiding authored and jennifer-shehane committed Oct 7, 2019
1 parent 5549488 commit 7e97d96
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/driver/src/cypress.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -498,5 +498,6 @@ class $Cypress
## attaching these so they are accessible
## via the runner + integration spec helper
$Cypress.$ = $
$Cypress.dom = $dom

module.exports = $Cypress
27 changes: 20 additions & 7 deletions packages/reporter/cypress/integration/shortcuts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,50 @@ describe('controls', function () {
})
})

describe('shortcuts', function () {
it('stops tests', function () {
describe('shortcuts', () => {
it('stops tests', () => {
cy.get('body').then(() => {
expect(runner.emit).to.not.have.been.calledWith('runner:stop')
expect(runner.emit).not.to.have.been.calledWith('runner:stop')
})

cy.get('body').type('s').then(() => {
expect(runner.emit).to.have.been.calledWith('runner:stop')
})
})

it('resumes tests', function () {
it('resumes tests', () => {
cy.get('body').then(() => {
expect(runner.emit).to.not.have.been.calledWith('runner:restart')
expect(runner.emit).not.to.have.been.calledWith('runner:restart')
})

cy.get('body').type('r').then(() => {
expect(runner.emit).to.have.been.calledWith('runner:restart')
})
})

it('focuses on specs', function () {
it('focuses on specs', () => {
cy.get('body').then(() => {
expect(runner.emit).to.not.have.been.calledWith('focus:tests')
expect(runner.emit).not.to.have.been.calledWith('focus:tests')
})

cy.get('body').type('f').then(() => {
expect(runner.emit).to.have.been.calledWith('focus:tests')
})
})

it('does not run shortcut if typed into an input', () => {
cy.get('body')
.then(($body) => {
// this realistically happens with the selector playground, but
// need to add an input since this environment is isolated
$body.append('<input id="temp-input" />')
})
.get('#temp-input').type('r')
.then(() => {
expect(runner.emit).not.to.have.been.calledWith('runner:restart')
})
})

it('has shortcut in tooltips', () => {
cy.get('.focus-tests > button').trigger('mouseover')
cy.get('.tooltip').should('have.text', 'View All Tests F')
Expand Down
9 changes: 7 additions & 2 deletions packages/reporter/src/lib/shortcuts.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { $, dom } from '@packages/driver'
import events from './events'

class Shortcuts {
start (appState) {
this._appState = appState
start () {
document.addEventListener('keydown', this._handleKeyDownEvent)
}

stop () {
document.removeEventListener('keydown', this._handleKeyDownEvent)
}

_handleKeyDownEvent (event) {
// if typing into an input, textarea, etc, don't trigger any shortcuts
if (dom.isTextLike($(event.target))) return

switch (event.key) {
case 'r': events.emit('restart')
break
Expand Down
2 changes: 1 addition & 1 deletion packages/reporter/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Reporter extends Component {
}

componentDidMount () {
shortcuts.start(this.props.appState)
shortcuts.start()
EQ.init()
}
componentWillUnmount () {
Expand Down

4 comments on commit 7e97d96

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7e97d96 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/linux-x64/circle-develop-7e97d96d93540a6f7a1e97e540d697e9e4d9b822-161011/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.5.0/circle-develop-7e97d96d93540a6f7a1e97e540d697e9e4d9b822-161003/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7e97d96 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/win32-ia32/appveyor-develop-7e97d96d93540a6f7a1e97e540d697e9e4d9b822-27936765/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-ia32/appveyor-develop-7e97d96d93540a6f7a1e97e540d697e9e4d9b822-27936765/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7e97d96 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/win32-x64/appveyor-develop-7e97d96d93540a6f7a1e97e540d697e9e4d9b822-27936765/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-x64/appveyor-develop-7e97d96d93540a6f7a1e97e540d697e9e4d9b822-27936765/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7e97d96 Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/darwin-x64/circle-develop-7e97d96d93540a6f7a1e97e540d697e9e4d9b822-161020/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.5.0/circle-develop-7e97d96d93540a6f7a1e97e540d697e9e4d9b822-161021/cypress.tgz

Please sign in to comment.