popover.spec.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { beVisible, haveAttribute, html, notBeVisible, notHaveAttribute, test } from '../../../utils'
  2. test.skip('button toggles panel',
  3. [html`
  4. <div x-data x-popover>
  5. <button x-popover:button>Toggle</button>
  6. <ul x-popover:panel>
  7. Dialog Contents!
  8. </ul>
  9. </div>
  10. `],
  11. ({ get }) => {
  12. get('ul').should(notBeVisible())
  13. get('button').click()
  14. get('ul').should(beVisible())
  15. get('button').click()
  16. get('ul').should(notBeVisible())
  17. },
  18. )
  19. test.skip('has accessibility attributes',
  20. [html`
  21. <div x-data x-popover>
  22. <button x-popover:button>Toggle</button>
  23. <ul x-popover:panel>
  24. Dialog Contents!
  25. </ul>
  26. </div>
  27. `],
  28. ({ get }) => {
  29. get('button').should(haveAttribute('aria-expanded', 'false'))
  30. get('button').should(notHaveAttribute('aria-controls'))
  31. get('button').click()
  32. get('button').should(haveAttribute('aria-expanded', 'true'))
  33. get('button').should(haveAttribute('aria-controls', 'alpine-popover-panel-1'))
  34. },
  35. )
  36. test.skip('escape closes panel',
  37. [html`
  38. <div x-data x-popover>
  39. <button x-popover:button>Toggle</button>
  40. <ul x-popover:panel>
  41. Dialog Contents!
  42. </ul>
  43. </div>
  44. `],
  45. ({ get }) => {
  46. get('ul').should(notBeVisible())
  47. get('button').click()
  48. get('ul').should(beVisible())
  49. get('body').type('{esc}')
  50. get('ul').should(notBeVisible())
  51. },
  52. )
  53. test.skip('clicking outside closes panel',
  54. [html`
  55. <div>
  56. <div x-data x-popover>
  57. <button x-popover:button>Toggle</button>
  58. <ul x-popover:panel>
  59. Dialog Contents!
  60. </ul>
  61. </div>
  62. <h1>Click away to me</h1>
  63. </div>
  64. `],
  65. ({ get }) => {
  66. get('ul').should(notBeVisible())
  67. get('button').click()
  68. get('ul').should(beVisible())
  69. get('h1').click()
  70. get('ul').should(notBeVisible())
  71. },
  72. )
  73. test.skip('focusing away closes panel',
  74. [html`
  75. <div>
  76. <div x-data x-popover>
  77. <button x-popover:button>Toggle</button>
  78. <ul x-popover:panel>
  79. Dialog Contents!
  80. </ul>
  81. </div>
  82. <a href="#">Focus Me</a>
  83. </div>
  84. `],
  85. ({ get }) => {
  86. get('ul').should(notBeVisible())
  87. get('button').click()
  88. get('ul').should(beVisible())
  89. cy.focused().tab()
  90. get('ul').should(notBeVisible())
  91. },
  92. )
  93. test.skip('focusing away doesnt close panel if focusing inside a group',
  94. [html`
  95. <div x-data>
  96. <div x-popover:group>
  97. <div x-data x-popover id="1">
  98. <button x-popover:button>Toggle 1</button>
  99. <ul x-popover:panel>
  100. Dialog 1 Contents!
  101. </ul>
  102. </div>
  103. <div x-data x-popover id="2">
  104. <button x-popover:button>Toggle 2</button>
  105. <ul x-popover:panel>
  106. Dialog 2 Contents!
  107. </ul>
  108. </div>
  109. </div>
  110. <a href="#">Focus Me</a>
  111. </div>
  112. `],
  113. ({ get }) => {
  114. get('#1 ul').should(notBeVisible())
  115. get('#2 ul').should(notBeVisible())
  116. get('#1 button').click()
  117. get('#1 ul').should(beVisible())
  118. get('#2 ul').should(notBeVisible())
  119. cy.focused().tab()
  120. get('#1 ul').should(beVisible())
  121. get('#2 ul').should(notBeVisible())
  122. cy.focused().tab()
  123. get('#1 ul').should(notBeVisible())
  124. get('#2 ul').should(notBeVisible())
  125. },
  126. )