HistoryPage.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /**
  2. * HistoryPage - History列表页面的Page Object Model
  3. * 用于History界面的元素选择器和操作方法
  4. */
  5. class HistoryPage {
  6. /**
  7. * 获取表格
  8. */
  9. getTable() {
  10. return cy.get('table');
  11. }
  12. /**
  13. * 双击表格第一行
  14. */
  15. findTableAndDoubleClickFirstRow() {
  16. cy.get('table').within(() => {
  17. cy.get('tbody tr[data-testid="row-0"]')
  18. .scrollIntoView()
  19. .should('be.visible')
  20. .dblclick({ force: true });
  21. });
  22. }
  23. /**
  24. * 点击指定索引的行
  25. * @param index 行索引(从0开始)
  26. */
  27. clickRowByIndex(index: number) {
  28. cy.get('table').within(() => {
  29. cy.get(`tbody tr[data-testid="row-${index}"]`)
  30. .scrollIntoView()
  31. .should('be.visible')
  32. .click({ force: true });
  33. });
  34. }
  35. /**
  36. * 验证指定行被选中(黄色高亮)
  37. * @param index 行索引(从0开始)
  38. */
  39. verifyRowSelected(index: number) {
  40. cy.get('table').within(() => {
  41. cy.get(`tbody tr[data-testid="row-${index}"]`)
  42. .should('be.visible')
  43. .should('have.class', 'bg-yellow-500');
  44. });
  45. }
  46. /**
  47. * 点击删除按钮
  48. */
  49. clickDeleteButton() {
  50. cy.get('[data-testid="delete-button"]').click();
  51. }
  52. /**
  53. * 获取删除确认对话框
  54. */
  55. getDeleteConfirmModal() {
  56. return cy.get('.ant-modal-confirm').should('be.visible');
  57. }
  58. /**
  59. * 在对话框中确认删除
  60. */
  61. confirmDeleteInModal() {
  62. cy.get('[data-testid="modal-confirm-delete"]').click();
  63. }
  64. /**
  65. * 在对话框中取消删除
  66. */
  67. cancelDeleteInModal() {
  68. cy.get('[data-testid="modal-cancel-delete"]').click();
  69. }
  70. /**
  71. * 验证删除成功提示消息
  72. */
  73. verifyDeleteSuccessMessage() {
  74. cy.contains('删除成功').should('be.visible');
  75. }
  76. /**
  77. * 验证删除警告消息
  78. * @param expectedMessage 期望的警告消息文本
  79. */
  80. verifyDeleteWarningMessage(expectedMessage: string) {
  81. cy.contains(expectedMessage).should('be.visible');
  82. }
  83. /**
  84. * 验证删除错误消息
  85. */
  86. verifyDeleteErrorMessage() {
  87. cy.contains('删除失败').should('be.visible');
  88. }
  89. /**
  90. * 验证表格行数
  91. * @param expectedCount 期望的行数
  92. */
  93. verifyRowCount(expectedCount: number) {
  94. cy.get('table tbody tr').should('have.length.at.least', expectedCount);
  95. }
  96. /**
  97. * 验证对话框不存在
  98. */
  99. verifyModalNotExist() {
  100. cy.get('.ant-modal-confirm').should('not.exist');
  101. }
  102. // ============ 日期范围验证方法 ============
  103. /**
  104. * 验证表格为空(无数据)
  105. */
  106. verifyTableEmpty() {
  107. cy.get('table tbody').should('not.exist');
  108. // 或者验证空状态提示
  109. cy.contains('暂无数据').should('be.visible');
  110. }
  111. /**
  112. * 验证表格中显示的 study 日期在指定范围内
  113. * @param startDate 开始日期
  114. * @param endDate 结束日期
  115. */
  116. verifyStudyDatesWithinRange(startDate: Date, endDate: Date) {
  117. cy.get('table tbody tr').each(($row) => {
  118. // 获取表格中的日期列(假设日期在特定列)
  119. cy.wrap($row)
  120. .find('td')
  121. .then(($cells) => {
  122. // 查找包含日期的单元格(通常是 StudyStartDatetime 列)
  123. const dateText = $cells
  124. .toArray()
  125. .map((cell) => cell.textContent)
  126. .find((text) => text && /\d{4}-\d{2}-\d{2}/.test(text || ''));
  127. if (dateText) {
  128. const studyDate = new Date(dateText);
  129. expect(studyDate.getTime()).to.be.gte(startDate.getTime());
  130. expect(studyDate.getTime()).to.be.lte(endDate.getTime());
  131. }
  132. });
  133. });
  134. }
  135. /**
  136. * 获取表格中第一行的检查日期
  137. */
  138. getFirstRowStudyDate() {
  139. return cy
  140. .get('table tbody tr')
  141. .first()
  142. .find('td')
  143. .then(($cells) => {
  144. // 查找包含日期的单元格
  145. const dateText = $cells
  146. .toArray()
  147. .map((cell) => cell.textContent)
  148. .find((text) => text && /\d{4}-\d{2}-\d{2}/.test(text || ''));
  149. return dateText ? new Date(dateText) : null;
  150. });
  151. }
  152. /**
  153. * 验证表格中所有行的日期都是今天
  154. */
  155. verifyAllStudyDatesAreToday() {
  156. const today = new Date();
  157. today.setHours(0, 0, 0, 0);
  158. const tomorrow = new Date(today);
  159. tomorrow.setDate(tomorrow.getDate() + 1);
  160. this.verifyStudyDatesWithinRange(today, tomorrow);
  161. }
  162. /**
  163. * 验证表格中所有行的日期在最近7天内
  164. */
  165. verifyAllStudyDatesWithinLast7Days() {
  166. const today = new Date();
  167. today.setHours(23, 59, 59, 999);
  168. const sevenDaysAgo = new Date(today);
  169. sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
  170. sevenDaysAgo.setHours(0, 0, 0, 0);
  171. this.verifyStudyDatesWithinRange(sevenDaysAgo, today);
  172. }
  173. /**
  174. * 验证表格至少有指定数量的行
  175. * @param minCount 最小行数
  176. */
  177. verifyTableHasMinRows(minCount: number) {
  178. cy.get('table tbody tr').should('have.length.at.least', minCount);
  179. }
  180. /**
  181. * 验证表格显示指定数量的行
  182. * @param count 期望的行数
  183. */
  184. verifyTableHasExactRows(count: number) {
  185. if (count === 0) {
  186. this.verifyTableEmpty();
  187. } else {
  188. cy.get('table tbody tr').should('have.length', count);
  189. }
  190. }
  191. /**
  192. * 获取表格中所有 study 的 StudyID
  193. */
  194. getAllStudyIds() {
  195. return cy.get('table tbody tr').then(($rows) => {
  196. const studyIds: string[] = [];
  197. $rows.each((index, row) => {
  198. const studyId = Cypress.$(row).attr('data-testid')?.replace('row-', '');
  199. if (studyId) {
  200. studyIds.push(studyId);
  201. }
  202. });
  203. return studyIds;
  204. });
  205. }
  206. /**
  207. * 验证指定的 StudyID 在表格中
  208. * @param studyId StudyID
  209. */
  210. verifyStudyIdExists(studyId: string) {
  211. cy.get('table tbody').contains(studyId).should('be.visible');
  212. }
  213. /**
  214. * 验证指定的 StudyID 不在表格中
  215. * @param studyId StudyID
  216. */
  217. verifyStudyIdNotExists(studyId: string) {
  218. cy.get('table tbody').contains(studyId).should('not.exist');
  219. }
  220. }
  221. export default HistoryPage;