tooltip.spec.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // tooltip.spec.js created with Cypress
  2. //
  3. // Start writing your Cypress tests below!
  4. // If you're unfamiliar with how Cypress works,
  5. // check out the link below and learn how to write your first test:
  6. // https://on.cypress.io/writing-first-test
  7. /**
  8. * Cypress will default scroll element into view
  9. * @see https://docs.cypress.io/guides/core-concepts/interacting-with-elements#Scrolling
  10. */
  11. describe('tooltip', () => {
  12. it('leftTopOver autoAdjustOverflow', () => {
  13. const viewportWidth = 1200;
  14. const viewportHeight = 660;
  15. const triggerWidth = 200;
  16. const triggerHeight = 32;
  17. const leftTopPosition = { offset: { top: 0, left: 0 } };
  18. const rightBottomPosition = { offset: { top: -viewportHeight + triggerHeight, left: -viewportWidth + triggerWidth } };
  19. cy.visit('http://127.0.0.1:6006/iframe.html?id=tooltip--left-top-over-auto-adjust-overflow&args=&viewMode=story');
  20. cy.viewport(viewportWidth, viewportHeight);
  21. const dataSelector = `[data-cy=leftTopOver]`;
  22. cy.get(dataSelector).scrollIntoView(leftTopPosition);
  23. cy.get(dataSelector).click({ force: true });
  24. cy.get('[x-placement="leftTopOver"]').should('have.length', 1);
  25. cy.get(dataSelector).scrollIntoView(rightBottomPosition);
  26. cy.get('[x-placement="rightBottomOver"]').should('have.length', 1);
  27. });
  28. // TODO:
  29. // it('position with over autoAdjustOverflow', () => {
  30. // const viewportWidth = 600;
  31. // const viewportHeight = 400;
  32. // const overList = ['leftTopOver', 'rightTopOver', 'rightBottomOver', 'leftBottomOver'];
  33. // cy.visit('http://127.0.0.1:6006/iframe.html?id=tooltip--left-top-over-demo&args=&viewMode=story');
  34. // cy.viewport(viewportWidth, viewportHeight);
  35. // const dataSelector = `[data-cy=toggleVisible]`;
  36. // cy.get(dataSelector).click({ force: true });
  37. // for (let i=0; i<overList.length; i++){
  38. // const dataSelector = `[data-cy=`+ overList[i] + `]`;
  39. // cy.get(dataSelector).click({ force: true });
  40. // cy.get('[x-placement="'+ overList[overList.length - 1 - i] +'"]').should('have.length', 1);
  41. // }
  42. // });
  43. it('autoFocusHover', () => {
  44. cy.visit('http://127.0.0.1:6006/iframe.html?id=tooltip--auto-focus-content-demo&args=&viewMode=story');
  45. const dataSelector = `[data-cy=hover]`;
  46. const input = `[data-cy=hoverInput]`;
  47. cy.get(dataSelector).trigger('mouseover');
  48. cy.get(input).should('be.focused');
  49. });
  50. it.skip('autoFocusHoverNoMotion', () => {
  51. cy.visit('http://127.0.0.1:6006/iframe.html?id=tooltip--auto-focus-content-demo&args=&viewMode=story');
  52. const dataSelector = `[data-cy=hoverNoMotion]`;
  53. const input = `[data-cy=hoverNoMotionInput]`;
  54. cy.get(dataSelector).trigger('mouseover');
  55. cy.get(input).should('be.focused');
  56. });
  57. it('autoFocusClick', () => {
  58. cy.visit('http://127.0.0.1:6006/iframe.html?id=tooltip--auto-focus-content-demo&args=&viewMode=story');
  59. const dataSelector = `[data-cy=click]`;
  60. const input = `[data-cy=clickInput]`;
  61. cy.get(dataSelector).click({ force: true });
  62. cy.get(input).should('be.focused');
  63. });
  64. it('autoFocusClickNoMotion', () => {
  65. cy.visit('http://127.0.0.1:6006/iframe.html?id=tooltip--auto-focus-content-demo&args=&viewMode=story');
  66. const dataSelector = `[data-cy=clickNoMotion]`;
  67. const input = `[data-cy=clickNoMotionInput]`;
  68. cy.get(dataSelector).click({ force: true });
  69. cy.get(input).should('be.focused');
  70. });
  71. it('autoFocusControlled', () => {
  72. cy.visit('http://127.0.0.1:6006/iframe.html?id=tooltip--auto-focus-content-demo&args=&viewMode=story');
  73. const trigger = `[data-cy=controlled]`;
  74. const disableBtn = `[data-cy=controlledDisableBtn]`;
  75. const input = `[data-cy=controlledInput]`;
  76. // 校验受控功能
  77. cy.get(disableBtn).click({ force: true });
  78. cy.get(input).should('not.exist');
  79. cy.get(trigger).click({ force: true });
  80. cy.get(input).should('be.focused');
  81. });
  82. it('autoFocusControlledNoMotion', () => {
  83. cy.visit('http://127.0.0.1:6006/iframe.html?id=tooltip--auto-focus-content-demo&args=&viewMode=story');
  84. const trigger = `[data-cy=controlledNoMotion]`;
  85. const disableBtn = `[data-cy=controlledNoMotionDisableBtn]`;
  86. const input = `[data-cy=controlledNoMotionInput]`;
  87. // 校验受控功能
  88. cy.get(disableBtn).click({ force: true });
  89. cy.get(input).should('not.exist');
  90. cy.get(trigger).click({ force: true });
  91. cy.get(input).should('be.focused');
  92. });
  93. it.skip('adjustPosIfNeed', () => {
  94. const viewportWidth = 400;
  95. const viewportHeight = 200;
  96. const topAndLeft = ['topLeft', 'top', 'topRight', 'leftTop', 'left', 'leftBottom'];
  97. const bottomAndRight = ['bottomLeft', 'bottom', 'bottomRight', 'rightTop', 'right', 'rightBottom'];
  98. cy.visit('http://127.0.0.1:6006/iframe.html?id=tooltip--adjust-pos-if-need&args=&viewMode=story');
  99. cy.viewport(viewportWidth, viewportHeight);
  100. for (let i=0; i<topAndLeft.length; i++){
  101. const dataSelector = `[data-cy=`+ topAndLeft[i] + `]`;
  102. cy.get(dataSelector).click({ force: true });
  103. cy.get('[x-placement="'+ bottomAndRight[i] +'"]').should('have.length', 1);
  104. }
  105. for (let i=bottomAndRight.length-1; i>=0; i--){
  106. const dataSelector = `[data-cy=`+ bottomAndRight[i] + `]`;
  107. cy.get(dataSelector).click({ force: true });
  108. cy.get('[x-placement="'+ topAndLeft[i] +'"]').should('have.length', 1);
  109. }
  110. });
  111. it('test position in tblr, fine tune to other directions', () => {
  112. const viewportWidth = 1000;
  113. const viewportHeight = 800;
  114. cy.visit('http://127.0.0.1:6006/iframe.html?id=tooltip--adjust-pos-if-need-tblr&args=&viewMode=story');
  115. cy.viewport(viewportWidth, viewportHeight);
  116. cy.get('div .semi-tag').eq(0).click({ force: true });
  117. const posRow = ['top', 'bottom', 'left', 'right'];
  118. const posList1 = ['topLeft', 'topRight', 'bottomLeft', 'bottomRight'];
  119. const posList2 = ['leftTop', 'leftBottom', 'rightTop', 'rightBottom'];
  120. for (let i = 0; i < posList1.length; i++) {
  121. cy.get('div .semi-tag').contains(posRow[0] + ' to ' + posList1[i]).click({ force: true });
  122. cy.get('[x-placement="' + posList1[i] + '"]').should('have.length', 1);
  123. cy.get('div .semi-tag').contains(posRow[1] + ' to ' + posList1[i]).click({ force: true });
  124. cy.get('[x-placement="' + posList1[i] + '"]').should('have.length', 1);
  125. }
  126. for (let i = 0; i < posList2.length; i++) {
  127. cy.get('div .semi-tag').contains(posRow[2] + ' to ' + posList2[i]).click({ force: true });
  128. cy.get('[x-placement="' + posList2[i] + '"]').should('have.length', 1);
  129. cy.get('div .semi-tag').contains(posRow[3] + ' to ' + posList2[i]).click({ force: true });
  130. cy.get('[x-placement="' + posList2[i] + '"]').should('have.length', 1);
  131. }
  132. });
  133. });