textarea.spec.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // textarea.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. describe('textarea', () => {
  8. beforeEach(() => {
  9. cy.visit('http://localhost:6006/iframe.html?id=input--text-area-autosize&args=&viewMode=story');
  10. });
  11. it('autosize', () => {
  12. const idx = 0;
  13. cy.get('.semi-input-textarea').eq(idx).type("semi design");
  14. cy.document().then(document => {
  15. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  16. expect(window.getComputedStyle(textAreaDOM).overflow).to.equal('hidden');
  17. });
  18. cy.fixture("placeholder").then(placeholder => {
  19. cy.get('.semi-input-textarea').eq(idx).type(placeholder.medium);
  20. cy.document().then(document => {
  21. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  22. expect(textAreaDOM.scrollHeight).to.equal(textAreaDOM.clientHeight);
  23. });
  24. cy.get('.semi-input-textarea').eq(idx).clear().type(placeholder.long);
  25. cy.document().then(document => {
  26. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  27. expect(textAreaDOM.scrollHeight).to.equal(textAreaDOM.clientHeight);
  28. });
  29. });
  30. });
  31. it('autosize mini row', () => {
  32. const idx = 1;
  33. cy.get('.semi-input-textarea').eq(idx).clear();
  34. let minHeight = 0;
  35. cy.document().then(document => {
  36. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  37. minHeight = textAreaDOM.clientHeight;
  38. expect(textAreaDOM.scrollHeight).to.equal(minHeight);
  39. });
  40. cy.get('.semi-input-textarea').eq(idx).clear().type("111\n222\n333\n444");
  41. cy.document().then(document => {
  42. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  43. expect(textAreaDOM.scrollHeight).to.gt(minHeight);
  44. expect(textAreaDOM.scrollHeight).to.equal(textAreaDOM.clientHeight);
  45. });
  46. cy.get('.semi-input-textarea').eq(idx).clear().type("111\n222");
  47. cy.document().then(document => {
  48. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  49. expect(textAreaDOM.scrollHeight).to.equal(minHeight);
  50. });
  51. const idx2 = 2;
  52. cy.get('.semi-input-textarea').eq(idx2).clear();
  53. cy.document().then(document => {
  54. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx2];
  55. expect(window.getComputedStyle(textAreaDOM).overflow).to.equal('auto');
  56. });
  57. });
  58. it('autosize min and max rows', () => {
  59. const idx = 3;
  60. cy.get('.semi-input-textarea').eq(idx).clear();
  61. cy.document().then(document => {
  62. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  63. expect(window.getComputedStyle(textAreaDOM).overflow).to.equal('hidden');
  64. });
  65. [4, 5].forEach(idx => {
  66. cy.get('.semi-input-textarea').eq(idx).clear();
  67. cy.document().then(document => {
  68. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  69. expect(window.getComputedStyle(textAreaDOM).overflow).to.equal('auto');
  70. });
  71. let minHeight = 0;
  72. cy.document().then(document => {
  73. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  74. minHeight = textAreaDOM.clientHeight;
  75. expect(textAreaDOM.scrollHeight).to.equal(minHeight);
  76. });
  77. cy.get('.semi-input-textarea').eq(idx).clear().type("111\n222\n333");
  78. cy.document().then(document => {
  79. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  80. expect(textAreaDOM.scrollHeight).to.gt(minHeight);
  81. expect(textAreaDOM.scrollHeight).to.equal(textAreaDOM.clientHeight);
  82. });
  83. cy.get('.semi-input-textarea').eq(idx).clear().type("111\n222\n333\n444");
  84. cy.document().then(document => {
  85. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  86. expect(textAreaDOM.scrollHeight).to.gt(minHeight);
  87. expect(textAreaDOM.scrollHeight).to.gt(textAreaDOM.clientHeight);
  88. });
  89. cy.get('.semi-input-textarea').eq(idx).clear().type("111");
  90. cy.document().then(document => {
  91. const textAreaDOM = document.querySelectorAll(".semi-input-textarea")[idx];
  92. expect(textAreaDOM.scrollHeight).to.equal(minHeight);
  93. });
  94. });
  95. });
  96. it('autosize + textarea resize', () => {
  97. cy.visit('http://localhost:6006/iframe.html?id=input--text-auto-size-resize&viewMode=story');
  98. cy.get('button').contains('width=100').trigger('click');
  99. cy.wait(100);
  100. cy.document().then(document => {
  101. const textAreaDOM = document.querySelector(".semi-input-textarea");
  102. const { scrollHeight, clientHeight } = textAreaDOM;
  103. expect(scrollHeight).eq(clientHeight);
  104. });
  105. });
  106. });