123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- /**
- * 测试文件: History - 删除功能
- *
- * 测试场景:
- * 1. 成功删除未锁定的记录
- * 2. 尝试删除锁定的记录(应显示警告)
- * 3. 删除API失败的情况(网络错误/服务器错误)
- * 4. 取消删除操作
- */
- import { mockLoginSuccess } from '../../support/mock/handlers/user';
- import {
- mockFetchHistoryDataWithUnlocked,
- mockFetchHistoryDataWithLocked,
- mockDeleteStudySuccess,
- mockDeleteStudyFailure,
- DeleteStudy,
- FetchHistoryDataWithUnlocked,
- FetchHistoryDataWithLocked,
- } from '../../support/mock/handlers/worklist';
- import {
- mockI18nSuccess,
- mockGetLanguageListSuccess,
- mockAllRequiredAPIs,
- } from '../../support/mock/handlers/i18n';
- import { mockGetQuotaSuccess } from '../../support/mock/handlers/quota';
- import LoginPage from '../../support/pageObjects/LoginPage';
- import MainPage from '../../support/pageObjects/MainPage';
- import HistoryPage from '../../support/pageObjects/HistoryPage';
- describe('History - 删除功能测试', () => {
- const loginPage = new LoginPage();
- const mainPage = new MainPage();
- const historyPage = new HistoryPage();
- beforeEach(() => {
- // Mock多语言资源和必要的API
- mockI18nSuccess('zh_CN');
- mockGetLanguageListSuccess();
- mockAllRequiredAPIs('zh_CN');
- // Mock登录成功响应
- mockLoginSuccess();
- // Mock配额成功
- mockGetQuotaSuccess();
- // 登录系统
- loginPage.visit();
- loginPage.login('admin', '123456');
- // 等待页面渲染和路由跳转
- cy.wait(1500);
- // 验证登录成功:登录页面元素不再存在
- loginPage.getUsernameInput().should('not.exist');
- loginPage.getPasswordInput().should('not.exist');
- loginPage.getSubmitButton().should('not.exist');
- // ⚠️ 不在这里导航,让每个测试用例自己设置mock并导航
- });
- it('应该成功删除未锁定的记录', () => {
- // 设置History数据mock(未锁定)
- mockFetchHistoryDataWithUnlocked();
- mockDeleteStudySuccess();
- // 导航到History列表
- mainPage.clickHistorylistButton();
- cy.wait(FetchHistoryDataWithUnlocked);
- // 验证初始状态:2条记录
- historyPage.verifyRowCount(2);
- // 调试:点击前查看Redux state
- cy.window().its('store').invoke('getState').then(state => {
- cy.log('Before click - selectedIds:', state.historySelection?.selectedIds || []);
- });
- // 点击第一行(未锁定)选中
- historyPage.clickRowByIndex(0);
- // 等待React更新state
- cy.wait(500);
- // 调试:点击后查看Redux state
- cy.window().its('store').invoke('getState').then(state => {
- cy.log('After click - selectedIds:', state.historySelection?.selectedIds || []);
- });
- historyPage.verifyRowSelected(0);
- // 点击删除按钮
- historyPage.clickDeleteButton();
- // 等待 提示框出现
- cy.wait(1500);
- // 验证确认对话框出现
- historyPage.getDeleteConfirmModal();
- cy.contains('确认删除').should('be.visible');
- // 确认删除
- historyPage.confirmDeleteInModal();
- // 等待删除API调用
- cy.wait(DeleteStudy).then((interception) => {
- expect(interception.response?.statusCode).to.eq(200);
- expect(interception.response?.body.code).to.eq('0x000000');
- });
- // 验证删除后只剩1条记录(本地删除,无需等待列表刷新)
- historyPage.verifyRowCount(1);
- });
- it('尝试删除锁定的记录时应显示警告', () => {
- // 设置History数据mock(已锁定)
- mockFetchHistoryDataWithLocked();
- // 导航到History列表
- mainPage.clickHistorylistButton();
- cy.wait(FetchHistoryDataWithLocked);
- // 验证有2条记录
- historyPage.verifyRowCount(2);
- // 点击第一行(已锁定)选中
- historyPage.clickRowByIndex(0);
- historyPage.verifyRowSelected(0);
- // 点击删除按钮
- historyPage.clickDeleteButton();
- // 验证警告消息:锁定状态不可删除
- historyPage.verifyDeleteWarningMessage('锁定状态不可删除');
- // 验证没有弹出确认对话框(因为被提前拦截了)
- historyPage.verifyModalNotExist();
- // 验证记录仍然存在
- historyPage.verifyRowCount(2);
- });
- it('删除API失败时应显示错误提示', () => {
- // 设置History数据mock和失败的删除API
- mockFetchHistoryDataWithUnlocked();
- mockDeleteStudyFailure();
- // 导航到History列表
- mainPage.clickHistorylistButton();
- cy.wait(FetchHistoryDataWithUnlocked);
- // 验证有2条记录
- historyPage.verifyRowCount(2);
- // 点击第一行选中
- historyPage.clickRowByIndex(0);
- historyPage.verifyRowSelected(0);
- // 点击删除按钮
- historyPage.clickDeleteButton();
- // 验证确认对话框出现
- historyPage.getDeleteConfirmModal();
- // 确认删除
- historyPage.confirmDeleteInModal();
- // 等待删除API调用(失败)
- cy.wait(DeleteStudy).then((interception) => {
- expect(interception.response?.statusCode).to.eq(200);
- expect(interception.response?.body.code).to.not.eq('0x000000');
- });
- // 验证记录仍然存在(因为删除失败)
- historyPage.verifyRowCount(2);
- });
- it('取消删除操作时记录应保持不变', () => {
- // 设置History数据mock
- mockFetchHistoryDataWithUnlocked();
- // 导航到History列表
- mainPage.clickHistorylistButton();
- cy.wait(FetchHistoryDataWithUnlocked);
- // 验证有2条记录
- historyPage.verifyRowCount(2);
- // 点击第一行选中
- historyPage.clickRowByIndex(0);
- historyPage.verifyRowSelected(0);
- // 点击删除按钮
- historyPage.clickDeleteButton();
- // 验证确认对话框出现
- historyPage.getDeleteConfirmModal();
- // 取消删除
- historyPage.cancelDeleteInModal();
- // 验证对话框关闭
- historyPage.verifyModalNotExist();
- // 验证记录仍然存在
- historyPage.verifyRowCount(2);
- });
- it('未选中任何记录时点击删除应显示警告', () => {
- // 设置History数据mock
- mockFetchHistoryDataWithUnlocked();
- // 导航到History列表
- mainPage.clickHistorylistButton();
- cy.wait(FetchHistoryDataWithUnlocked);
- // 验证有2条记录
- historyPage.verifyRowCount(2);
- // 不选中任何记录,直接点击删除按钮
- historyPage.clickDeleteButton();
- // 验证警告消息:请先选择要删除的项目
- historyPage.verifyDeleteWarningMessage('请先选择要删除的项目');
- // 验证没有弹出确认对话框
- historyPage.verifyModalNotExist();
- // 验证记录仍然存在
- historyPage.verifyRowCount(2);
- });
- });
|