Răsfoiți Sursa

优化 cypress 测试

Michael Wang 2 ani în urmă
părinte
comite
ef3313388d

+ 36 - 25
cypress/e2e/markbody-container.spec.cy.ts

@@ -6,40 +6,51 @@ describe("评卷页面-裁切图", () => {
 
   it("键盘选择鼠标分数成功", () => {
     cy.visit("/");
-    cy.wait(3000);
-    cy.get("body").type("1");
-    cy.get("body").trigger("click", { clientX: 200, clientY: 350 });
-    cy.get(".cursor-border").should("contain", "1");
+    cy.wait(1000)
+      .get(".mark-body-container")
+      .get("body")
+      .type("1")
+      .trigger("click", {
+        clientX: 200,
+        clientY: 350,
+      })
+      .get(".cursor-border")
+      .should("contain", "1");
   });
 
   it("键盘选择鼠标分数失败", () => {
     cy.visit("/");
-    cy.wait(3000);
-    cy.get("body").type("1.47");
-    cy.get("body").trigger("click", { clientX: 200, clientY: 350 });
-    cy.get(".cursor-border").should("contain", "1");
+    cy.wait(1000)
+      .get(".mark-body-container")
+      .get("body")
+      .type("1.47")
+      .trigger("click", {
+        clientX: 200,
+        clientY: 350,
+      })
+      .get(".cursor-border")
+      .should("contain", "1.4");
   });
 
   it("裁切图点击-分数增加", () => {
     cy.visit("/");
-    cy.wait(5000);
-    let oldTotal = "0";
-    cy.get(".total-score span span").then(($div) => {
-      oldTotal = $div.html();
-      // console.log($div, $div.text(), $div.html());
-    });
+    // 任务开始渲染了
+    cy.get(".single-image-container");
+    // 等待遮罩层消除
+    cy.get('[data-test="status-spin"]').should("not.exist");
+    cy.get(".total-score span span").invoke("html").as("oldTotal");
 
     const addScore = "2";
-    cy.get("body .mark-body-container").scrollTo(0, 0);
-    cy.get("body").type(addScore);
-    cy.get("body").click(200, 200);
-    cy.get("body").trigger("mousemove");
-    // 要给点时间页面计算
-    cy.wait(100);
-    cy.get(".cursor-border").should("contain", addScore);
-    // cy.wait(3000);
-    cy.get(".total-score span span").then(($div) =>
-      expect($div.html()).eq(+oldTotal + +addScore + "")
-    );
+    cy.get("body .mark-body-container")
+      .scrollTo(0, 0)
+      .get("body")
+      .type(addScore)
+      .click(200, 200)
+      // 要给点时间页面计算动画
+      .wait(500)
+      .get(".total-score span span")
+      .then(function ($div) {
+        expect($div.html()).eq(+this.oldTotal + +addScore + "");
+      });
   });
 });

+ 3 - 2
cypress/tsconfig.json

@@ -2,6 +2,7 @@
   "extends": "../tsconfig.json",
   "compilerOptions": {
     "isolatedModules": false,
-    "types": []
-  }
+    "types": ["cypress"]
+  },
+  "include": ["**/*.*"]
 }

+ 1 - 0
src/features/mark/Mark.vue

@@ -47,6 +47,7 @@
     <div
       style="height: 100vh"
       class="tw-text-8xl tw-flex tw-items-center tw-justify-center tw-text-red-500"
+      data-test="status-spin"
     >
       {{ store.getStatusValueName }}
     </div>

+ 1 - 1
tsconfig.json

@@ -26,7 +26,7 @@
     "src/*.vue",
     "*.js",
     "components.d.ts",
-    "cypress/**/*.ts",
+    // "cypress/**/*.ts",
     "cypress.config.ts"
   ]
 }