popover.spec.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Start writing your Cypress tests below!
  2. // If you're unfamiliar with how Cypress works,
  3. // check out the link below and learn how to write your first test:
  4. // https://on.cypress.io/writing-first-test
  5. describe('popover', () => {
  6. it('trigger=click + keyboard', () => {
  7. cy.visit('http://localhost:6006/iframe.html?id=popover--a-11-y-keyboard&args=&viewMode=story');
  8. cy.get('[data-cy=click]').click();
  9. cy.get('[data-cy=click]').type('{downArrow}');
  10. cy.get('[data-cy=pop-focusable-first]').should('be.focused');
  11. cy.get('[data-cy=pop-focusable-first]').type('{esc}');
  12. cy.get('[data-cy=click]').should('be.focused');
  13. cy.get('[data-cy=click]').click();
  14. cy.get('[data-cy=click]').type('{upArrow}');
  15. cy.get('[data-cy=pop-focusable-last]').should('be.focused');
  16. });
  17. /**
  18. * electron failed
  19. * @see https://github.com/cypress-io/cypress/issues/20878
  20. */
  21. it.skip('trigger=hover + keyboard', () => {
  22. cy.visit('http://localhost:6006/iframe.html?id=popover--a-11-y-keyboard&args=&viewMode=story');
  23. cy.get('[data-cy=hover]').trigger('focus');
  24. cy.get('[data-cy=hover]').type('{downArrow}');
  25. cy.get('[data-cy=pop-focusable-first]').should('be.focused');
  26. cy.get('[data-cy=pop-focusable-first]').type('{esc}');
  27. cy.get('[data-cy=hover]').trigger('focus');
  28. cy.get('[data-cy=hover]').type('{upArrow}');
  29. cy.get('[data-cy=pop-focusable-last]').should('be.focused');
  30. });
  31. /**
  32. * electron failed
  33. * @see https://github.com/cypress-io/cypress/issues/20878
  34. */
  35. it.skip('trigger=focus + keyboard', () => {
  36. cy.visit('http://localhost:6006/iframe.html?id=popover--a-11-y-keyboard&args=&viewMode=story');
  37. cy.get('[data-cy=focus]').trigger('focus');
  38. cy.get('[data-cy=focus]').type('{downArrow}');
  39. cy.get('[data-cy=pop-focusable-first]').should('be.focused');
  40. cy.get('[data-cy=pop-focusable-first]').type('{esc}');
  41. cy.get('[data-cy=focus]').trigger('focus');
  42. cy.get('[data-cy=focus]').type('{upArrow}');
  43. cy.get('[data-cy=pop-focusable-last]').should('be.focused');
  44. });
  45. /**
  46. * electron failed
  47. * @see https://github.com/cypress-io/cypress/issues/20878
  48. */
  49. it.skip('trigger=custom + keyboard', () => {
  50. cy.visit('http://localhost:6006/iframe.html?id=popover--a-11-y-keyboard&args=&viewMode=story');
  51. cy.get('[data-cy=custom]').trigger('click');
  52. cy.get('[data-cy=custom]').type('{downArrow}');
  53. cy.get('[data-cy=pop-focusable-first]').should('be.focused');
  54. cy.get('[data-cy=pop-focusable-first]').type('{esc}');
  55. cy.get('[data-cy=custom]').trigger('click');
  56. cy.get('[data-cy=custom]').type('{upArrow}');
  57. cy.get('[data-cy=pop-focusable-last]').should('be.focused');
  58. });
  59. it('trigger=click + focus guard', () => {
  60. cy.visit('http://localhost:6006/iframe.html?id=popover--a-11-y-keyboard&args=&viewMode=story');
  61. cy.get('[data-cy=click]').click();
  62. cy.get('[data-cy=click]').type('{upArrow}');
  63. cy.get('[data-cy=pop]').trigger('keydown', { eventConstructor: 'KeyboardEvent', key: 'Tab' });
  64. cy.get('[data-cy=pop-focusable-first]').should('be.focused');
  65. cy.get('[data-cy=pop]').trigger('keydown', { eventConstructor: 'KeyboardEvent', key: 'Tab', shiftKey: true });
  66. cy.get('[data-cy=pop-focusable-last]').should('be.focused');
  67. });
  68. it('trigger=click + init focus', () => {
  69. cy.visit('http://localhost:6006/iframe.html?id=popover--a-11-y-keyboard&args=&viewMode=story');
  70. cy.get('[data-cy=initial-focus]').click({ force: true });
  71. cy.get('[data-cy=initial-focus-input]').should('be.focused');
  72. });
  73. it('trigger=click + closeOnEsc=false', () => {
  74. cy.visit('http://localhost:6006/iframe.html?id=popover--a-11-y-keyboard&args=&viewMode=story');
  75. cy.get('[data-cy=closeOnEsc-false]').click({ force: true });
  76. cy.get('[data-cy=closeOnEsc-false]').type('{esc}');
  77. cy.get('[data-cy=pop]').should('be.visible');
  78. });
  79. it('trigger=click + returnFocusOnClose=false', () => {
  80. cy.visit('http://localhost:6006/iframe.html?id=popover--a-11-y-keyboard&args=&viewMode=story');
  81. cy.get('[data-cy=returnFocusOnClose-false]').click({ force: true });
  82. cy.get('[data-cy=returnFocusOnClose-false]').type('{downArrow}');
  83. cy.get('[data-cy=pop-focusable-first]').type('{esc}', { force: true });
  84. cy.get('[data-cy=returnFocusOnClose-false]').should('not.be.focused');
  85. });
  86. it('click select option in popover ', () => {
  87. cy.visit('http://localhost:6006/iframe.html?id=popover--fix-nested-popover&args=&viewMode=story');
  88. cy.get('[data-cy=fix-nested-popover] .semi-tag').click();
  89. cy.get('[data-cy=select-in-popover] .semi-select').click();
  90. cy.get('[data-cy=select-in-popover] .semi-select').click();
  91. cy.get('.semi-select-option').contains('西瓜视频').click();
  92. cy.get('[data-cy=select-in-popover] .semi-select').should('be.visible');
  93. cy.get('.semi-select-option-list ').should('be.not.exist');
  94. });
  95. });