tooltip.spec.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import OLTooltip from '@/features/ui/components/ol/ol-tooltip'
  2. describe('<OLTooltip />', 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. <OLTooltip id="abc" description={description}>
  18. <button onClick={clickHandler} onBlur={blurHandler}>
  19. {btnText}
  20. </button>
  21. </OLTooltip>
  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. it('hides the tooltip when Escape key is pressed', function () {
  33. const description = 'Press Escape to close'
  34. const btnText = 'Hover me!'
  35. cy.mount(
  36. <div
  37. style={{
  38. display: 'flex',
  39. alignItems: 'center',
  40. justifyContent: 'center',
  41. height: '100vh',
  42. }}
  43. >
  44. <OLTooltip id="esc" description={description}>
  45. <button>{btnText}</button>
  46. </OLTooltip>
  47. </div>
  48. )
  49. cy.findByRole('button', { name: btnText }).as('button')
  50. cy.get('@button').trigger('mouseover')
  51. cy.findByText(description)
  52. cy.get('@button').trigger('mouseout')
  53. cy.get('@button').focus()
  54. cy.findByText(description)
  55. cy.get('body').type('{esc}')
  56. cy.findByText(description).should('not.exist')
  57. })
  58. })