浏览代码

feat: add quota validation and testing

- Add quota mock handlers for success/failure scenarios
- Add e2e test for quota insufficient validation
- Implement quota check during exam entry process
dengdx 2 周之前
父节点
当前提交
7839b6dbd8
共有 2 个文件被更改,包括 69 次插入0 次删除
  1. 34 0
      cypress/e2e/security/quota.insufficient.cy.ts
  2. 35 0
      cypress/support/mock/handlers/quota.ts

+ 34 - 0
cypress/e2e/security/quota.insufficient.cy.ts

@@ -0,0 +1,34 @@
+import LoginPage from '../../support/pageObjects/LoginPage';
+import MainPage from '../../support/pageObjects/MainPage';
+import WorklistPage from '../../support/pageObjects/WorklistPage';
+import { mockGetQuotaFail } from '../../support/mock/handlers/quota';
+import { mockLoginSuccess } from '../../support/mock/handlers/user';
+
+describe('Security Page Navigation', () => {
+  const loginPage = new LoginPage();
+  const mainPage = new MainPage();
+  const worklistPage = new WorklistPage();
+
+  beforeEach(() => {
+    loginPage.visit();
+    loginPage.getUsernameInput().should('be.visible');
+    loginPage.getPasswordInput().should('be.visible');
+    loginPage.getSubmitButton().should('be.visible');
+  });
+
+it('进入检查时,应该检查到配额不足', () => {
+    mockGetQuotaFail();
+    
+    mockLoginSuccess();
+    loginPage.login('admin', '123456');
+    cy.wait('@loginSuccess');
+    cy.contains('登录成功').should('be.visible', { timeout: 10000 });
+
+    mainPage.clickPatientManagementButton();
+    mainPage.clickWorklistButton();
+    worklistPage.findTableAndDoubleClickFirstRow();
+    cy.wait(3000);
+
+    cy.contains('Quota check failed. Please contact support.').should('be.visible');
+  });
+});

+ 35 - 0
cypress/support/mock/handlers/quota.ts

@@ -0,0 +1,35 @@
+// Quota-related mock handlers
+// 封装获取配额成功的 mock
+export function mockGetQuotaSuccess() {
+  cy.intercept('GET', '/dr/api/v1/pub/quota', (req) => {
+    req.reply({
+      statusCode: 200,
+      body: {
+        code: "0x000000",
+        data: {
+          total: 50,
+          available: 50,
+          online: true,
+          overdue: false
+        },
+        description: "Success",
+        solution: ""
+      }
+    });
+  }).as('getQuotaSuccess');
+}
+
+// 封装获取配额失败的 mock
+export function mockGetQuotaFail() {
+  cy.intercept('GET', '/dr/api/v1/pub/quota', (req) => {
+    req.reply({
+      statusCode: 200, // 一般还是200,通过 code 区分失败
+      body: {
+        code: "0x000001",
+        description: "Failed to retrieve quota",
+        solution: "Please try again later",
+        data: {}
+      }
+    });
+  }).as('getQuotaFail');
+}