tooltip.spec.tsx 1.1 KB

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