123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- /**
- * HistoryPage - History列表页面的Page Object Model
- * 用于History界面的元素选择器和操作方法
- */
- class HistoryPage {
- /**
- * 获取表格
- */
- getTable() {
- return cy.get('table');
- }
- /**
- * 双击表格第一行
- */
- findTableAndDoubleClickFirstRow() {
- cy.get('table').within(() => {
- cy.get('tbody tr[data-testid="row-0"]')
- .scrollIntoView()
- .should('be.visible')
- .dblclick({ force: true });
- });
- }
- /**
- * 点击指定索引的行
- * @param index 行索引(从0开始)
- */
- clickRowByIndex(index: number) {
- cy.get('table').within(() => {
- cy.get(`tbody tr[data-testid="row-${index}"]`)
- .scrollIntoView()
- .should('be.visible')
- .click({ force: true });
- });
- }
- /**
- * 验证指定行被选中(黄色高亮)
- * @param index 行索引(从0开始)
- */
- verifyRowSelected(index: number) {
- cy.get('table').within(() => {
- cy.get(`tbody tr[data-testid="row-${index}"]`)
- .should('be.visible')
- .should('have.class', 'bg-yellow-500');
- });
- }
- /**
- * 点击删除按钮
- */
- clickDeleteButton() {
- cy.get('[data-testid="delete-button"]').click();
- }
- /**
- * 获取删除确认对话框
- */
- getDeleteConfirmModal() {
- return cy.get('.ant-modal-confirm').should('be.visible');
- }
- /**
- * 在对话框中确认删除
- */
- confirmDeleteInModal() {
- cy.get('[data-testid="modal-confirm-delete"]').click();
- }
- /**
- * 在对话框中取消删除
- */
- cancelDeleteInModal() {
- cy.get('[data-testid="modal-cancel-delete"]').click();
- }
- /**
- * 验证删除成功提示消息
- */
- verifyDeleteSuccessMessage() {
- cy.contains('删除成功').should('be.visible');
- }
- /**
- * 验证删除警告消息
- * @param expectedMessage 期望的警告消息文本
- */
- verifyDeleteWarningMessage(expectedMessage: string) {
- cy.contains(expectedMessage).should('be.visible');
- }
- /**
- * 验证删除错误消息
- */
- verifyDeleteErrorMessage() {
- cy.contains('删除失败').should('be.visible');
- }
- /**
- * 验证表格行数
- * @param expectedCount 期望的行数
- */
- verifyRowCount(expectedCount: number) {
- cy.get('table tbody tr').should('have.length.at.least', expectedCount);
- }
- /**
- * 验证对话框不存在
- */
- verifyModalNotExist() {
- cy.get('.ant-modal-confirm').should('not.exist');
- }
- // ============ 日期范围验证方法 ============
- /**
- * 验证表格为空(无数据)
- */
- verifyTableEmpty() {
- cy.get('table tbody').should('not.exist');
- // 或者验证空状态提示
- cy.contains('暂无数据').should('be.visible');
- }
- /**
- * 验证表格中显示的 study 日期在指定范围内
- * @param startDate 开始日期
- * @param endDate 结束日期
- */
- verifyStudyDatesWithinRange(startDate: Date, endDate: Date) {
- cy.get('table tbody tr').each(($row) => {
- // 获取表格中的日期列(假设日期在特定列)
- cy.wrap($row)
- .find('td')
- .then(($cells) => {
- // 查找包含日期的单元格(通常是 StudyStartDatetime 列)
- const dateText = $cells
- .toArray()
- .map((cell) => cell.textContent)
- .find((text) => text && /\d{4}-\d{2}-\d{2}/.test(text || ''));
- if (dateText) {
- const studyDate = new Date(dateText);
- expect(studyDate.getTime()).to.be.gte(startDate.getTime());
- expect(studyDate.getTime()).to.be.lte(endDate.getTime());
- }
- });
- });
- }
- /**
- * 获取表格中第一行的检查日期
- */
- getFirstRowStudyDate() {
- return cy
- .get('table tbody tr')
- .first()
- .find('td')
- .then(($cells) => {
- // 查找包含日期的单元格
- const dateText = $cells
- .toArray()
- .map((cell) => cell.textContent)
- .find((text) => text && /\d{4}-\d{2}-\d{2}/.test(text || ''));
- return dateText ? new Date(dateText) : null;
- });
- }
- /**
- * 验证表格中所有行的日期都是今天
- */
- verifyAllStudyDatesAreToday() {
- const today = new Date();
- today.setHours(0, 0, 0, 0);
- const tomorrow = new Date(today);
- tomorrow.setDate(tomorrow.getDate() + 1);
- this.verifyStudyDatesWithinRange(today, tomorrow);
- }
- /**
- * 验证表格中所有行的日期在最近7天内
- */
- verifyAllStudyDatesWithinLast7Days() {
- const today = new Date();
- today.setHours(23, 59, 59, 999);
- const sevenDaysAgo = new Date(today);
- sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
- sevenDaysAgo.setHours(0, 0, 0, 0);
- this.verifyStudyDatesWithinRange(sevenDaysAgo, today);
- }
- /**
- * 验证表格至少有指定数量的行
- * @param minCount 最小行数
- */
- verifyTableHasMinRows(minCount: number) {
- cy.get('table tbody tr').should('have.length.at.least', minCount);
- }
- /**
- * 验证表格显示指定数量的行
- * @param count 期望的行数
- */
- verifyTableHasExactRows(count: number) {
- if (count === 0) {
- this.verifyTableEmpty();
- } else {
- cy.get('table tbody tr').should('have.length', count);
- }
- }
- /**
- * 获取表格中所有 study 的 StudyID
- */
- getAllStudyIds() {
- return cy.get('table tbody tr').then(($rows) => {
- const studyIds: string[] = [];
- $rows.each((index, row) => {
- const studyId = Cypress.$(row).attr('data-testid')?.replace('row-', '');
- if (studyId) {
- studyIds.push(studyId);
- }
- });
- return studyIds;
- });
- }
- /**
- * 验证指定的 StudyID 在表格中
- * @param studyId StudyID
- */
- verifyStudyIdExists(studyId: string) {
- cy.get('table tbody').contains(studyId).should('be.visible');
- }
- /**
- * 验证指定的 StudyID 不在表格中
- * @param studyId StudyID
- */
- verifyStudyIdNotExists(studyId: string) {
- cy.get('table tbody').contains(studyId).should('not.exist');
- }
- }
- export default HistoryPage;
|