tooltip.spec.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import '../../helpers/bootstrap-3'
  2. import Tooltip from '../../../../frontend/js/shared/components/tooltip'
  3. describe('<Tooltip />', function () {
  4. it('calls the bound handler and blur then hides text on click', function () {
  5. const clickHandler = cy.stub().as('clickHandler')
  6. const blurHandler = cy.stub().as('blurHandler')
  7. const description = 'foo'
  8. const btnText = 'Click me!'
  9. cy.mount(
  10. <div
  11. style={{
  12. display: 'flex',
  13. alignItems: 'center',
  14. justifyContent: 'center',
  15. height: '100vh',
  16. }}
  17. >
  18. <Tooltip id="abc" description={description}>
  19. <button onClick={clickHandler} onBlur={blurHandler}>
  20. {btnText}
  21. </button>
  22. </Tooltip>
  23. </div>
  24. )
  25. cy.findByRole('button', { name: btnText }).as('button')
  26. cy.get('@button').trigger('mouseover')
  27. cy.findByText(description)
  28. cy.get('@button').click()
  29. cy.get('@clickHandler').should('have.been.calledOnce')
  30. cy.get('@blurHandler').should('have.been.calledOnce')
  31. cy.findByText(description).should('not.exist')
  32. })
  33. })