WorklistPage.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. class WorklistPage {
  2. getTable() {
  3. return cy.get('table');
  4. }
  5. findTableAndDoubleClickFirstRow() {
  6. cy.get('table').within(() => {
  7. cy.get('tbody tr[data-testid="row-0"]')
  8. .scrollIntoView()
  9. .should('be.visible')
  10. .dblclick({ force: true });
  11. });
  12. }
  13. /**
  14. * 获取表头(排除第一列选择框)
  15. */
  16. getTableHeaders() {
  17. return cy.get('table thead th').not(':first');
  18. }
  19. /**
  20. * 获取所有表头
  21. */
  22. getAllTableHeaders() {
  23. return cy.get('table thead th');
  24. }
  25. /**
  26. * 获取特定列
  27. * @param columnName 列名文本
  28. */
  29. getColumn(columnName: string) {
  30. return cy.get('table thead th').contains(columnName);
  31. }
  32. /**
  33. * 验证列存在
  34. * @param columnName 列名文本
  35. */
  36. columnExists(columnName: string) {
  37. return this.getTableHeaders().contains(columnName).should('exist');
  38. }
  39. /**
  40. * 验证列不存在
  41. * @param columnName 列名文本
  42. */
  43. columnNotExists(columnName: string) {
  44. return this.getTableHeaders().contains(columnName).should('not.exist');
  45. }
  46. /**
  47. * 获取列宽
  48. * @param columnName 列名文本
  49. */
  50. getColumnWidth(columnName: string) {
  51. return cy
  52. .get('table thead th')
  53. .contains(columnName)
  54. .invoke('width');
  55. }
  56. /**
  57. * 验证列的顺序
  58. * @param expectedOrder 期望的列名顺序数组
  59. */
  60. verifyColumnOrder(expectedOrder: string[]) {
  61. this.getTableHeaders().then(($headers) => {
  62. expectedOrder.forEach((columnName, index) => {
  63. cy.wrap($headers.eq(index)).should('contain', columnName);
  64. });
  65. });
  66. }
  67. /**
  68. * 获取表头数量
  69. */
  70. getHeaderCount() {
  71. return this.getTableHeaders().its('length');
  72. }
  73. /**
  74. * 点击指定索引的行
  75. * @param index 行索引(从0开始)
  76. */
  77. clickRowByIndex(index: number) {
  78. cy.get('table').within(() => {
  79. cy.get(`tbody tr[data-testid="row-${index}"]`)
  80. .scrollIntoView()
  81. .should('be.visible')
  82. .click({ force: true });
  83. });
  84. }
  85. /**
  86. * 验证指定行被选中(黄色高亮)
  87. * @param index 行索引(从0开始)
  88. */
  89. verifyRowSelected(index: number) {
  90. cy.get('table').within(() => {
  91. cy.get(`tbody tr[data-testid="row-${index}"]`)
  92. .should('be.visible')
  93. .should('have.class', 'bg-yellow-500');
  94. });
  95. }
  96. /**
  97. * 点击删除按钮
  98. */
  99. clickDeleteButton() {
  100. cy.get('[data-testid="delete-button"]').click();
  101. }
  102. /**
  103. * 获取删除确认对话框
  104. */
  105. getDeleteConfirmModal() {
  106. return cy.get('.ant-modal-confirm').should('be.visible');
  107. }
  108. /**
  109. * 在对话框中确认删除
  110. */
  111. confirmDeleteInModal() {
  112. cy.get('[data-testid="modal-confirm-delete"]').click();
  113. }
  114. /**
  115. * 在对话框中取消删除
  116. */
  117. cancelDeleteInModal() {
  118. cy.get('[data-testid="modal-cancel-delete"]').click();
  119. }
  120. /**
  121. * 验证删除成功提示消息
  122. */
  123. verifyDeleteSuccessMessage() {
  124. cy.contains('删除成功').should('be.visible');
  125. }
  126. /**
  127. * 验证删除警告消息
  128. * @param expectedMessage 期望的警告消息文本
  129. */
  130. verifyDeleteWarningMessage(expectedMessage: string) {
  131. cy.contains(expectedMessage).should('be.visible');
  132. }
  133. /**
  134. * 验证删除错误消息
  135. */
  136. verifyDeleteErrorMessage() {
  137. cy.contains('删除失败').should('be.visible');
  138. }
  139. /**
  140. * 验证表格行数
  141. * @param expectedCount 期望的行数
  142. */
  143. verifyRowCount(expectedCount: number) {
  144. cy.get('table tbody tr').should('have.length.at.least', expectedCount);
  145. }
  146. /**
  147. * 验证对话框不存在
  148. */
  149. verifyModalNotExist() {
  150. cy.get('.ant-modal-confirm').should('not.exist');
  151. }
  152. }
  153. export default WorklistPage;