Kaynağa Gözat

[更新] 触发测试

WuXinyu 7 yıl önce
ebeveyn
işleme
7501cca75f

+ 0 - 3
src/views/student/Code/ProjectDetail/Test/FunctionalTestDetail.vue

@@ -22,9 +22,6 @@
       <template slot="extraContent">
       <template slot="extraContent">
         <div class="tag">{{ displayUnixTime(testDetail.time) }}</div>
         <div class="tag">{{ displayUnixTime(testDetail.time) }}</div>
       </template>
       </template>
-      <template slot="action">
-        <a class="button is-primary"></a>
-      </template>
     </page-header>
     </page-header>
     <page-body>
     <page-body>
       <div v-for="item in testDetail.detail" :key="item.id" class="gap-section">
       <div v-for="item in testDetail.detail" :key="item.id" class="gap-section">

+ 1 - 1
src/views/student/Code/ProjectDetail/Test/UnitTestDetail.vue

@@ -10,7 +10,7 @@
             $route.params.projectId
             $route.params.projectId
           }/test`
           }/test`
         },
         },
-        { name: '页面测试' }
+        { name: '单元测试' }
       ]"
       ]"
     >
     >
       <template slot="title">
       <template slot="title">

+ 71 - 4
src/views/student/Code/ProjectDetail/TestDetail.vue

@@ -7,7 +7,7 @@
           class="test-item"
           class="test-item"
           :key="item.id"
           :key="item.id"
           :to="`${$route.path}/unit/${item.id}`"
           :to="`${$route.path}/unit/${item.id}`"
-          v-for="item in projectDetail.unitTestList"
+          v-for="item in unitTestList"
           tag="div"
           tag="div"
         >
         >
           <div><strong>UNIT TEST : #</strong> {{ item.id }}</div>
           <div><strong>UNIT TEST : #</strong> {{ item.id }}</div>
@@ -20,12 +20,22 @@
     </div>
     </div>
     <div class="column">
     <div class="column">
       <div class="page-section">
       <div class="page-section">
-        <h5 class="title is-5">页面测试:</h5>
+        <h5 class="test-title title is-5">
+          页面测试:
+          <div
+            v-if="functionTestList && functionTestList.length > 0"
+            :class="{ 'is-loading': testing }"
+            @click="makeTest"
+            class="button is-primary test-title__action"
+          >
+            触发测试
+          </div>
+        </h5>
         <router-link
         <router-link
           class="test-item"
           class="test-item"
           :key="item.id"
           :key="item.id"
           :to="`${$route.path}/functional/${item.id}`"
           :to="`${$route.path}/functional/${item.id}`"
-          v-for="item in projectDetail.functionTestList"
+          v-for="item in functionTestList"
           tag="div"
           tag="div"
         >
         >
           <div><strong>FUNCTIONAL TEST : #</strong> {{ item.id }}</div>
           <div><strong>FUNCTIONAL TEST : #</strong> {{ item.id }}</div>
@@ -42,6 +52,7 @@
 <script>
 <script>
 import PassTag from "@/views/student/Code/ProjectDetail/components/PassTag";
 import PassTag from "@/views/student/Code/ProjectDetail/components/PassTag";
 import timeMixins from "@/mixins/time";
 import timeMixins from "@/mixins/time";
+import { makeFunctionalTest } from "@/api/codehw";
 export default {
 export default {
   components: { PassTag },
   components: { PassTag },
   props: {
   props: {
@@ -53,7 +64,54 @@ export default {
       })
       })
     }
     }
   },
   },
-  mixins: [timeMixins]
+  computed: {
+    unitTestList() {
+      return this.sortTestList(this.projectDetail.unitTestList);
+    },
+    functionTestList() {
+      return this.sortTestList(this.projectDetail.functionTestList);
+    }
+  },
+  data() {
+    return {
+      testing: false
+    };
+  },
+  mixins: [timeMixins],
+  methods: {
+    async makeTest() {
+      const { functionTestList } = this;
+      if (functionTestList && functionTestList.length > 0) {
+        this.testing = true;
+        const { deployId } = functionTestList[0];
+        const { homeworkId, projectId } = this.$route.params;
+        const { data } = await makeFunctionalTest({
+          homeworkId,
+          projectId,
+          deployId
+        });
+        this.testing = false;
+        if (data.success) {
+          this.$toast.open({
+            message: `测试触发成功`,
+            type: "is-success"
+          });
+        } else {
+          this.$toast.open({
+            message: `测试触发失败`,
+            type: "is-danger"
+          });
+        }
+      }
+    },
+    sortTestList(list) {
+      console.log(list);
+      if (!list) return [];
+      const copyList = list.slice(0);
+      copyList.sort((a, b) => b.time - a.time);
+      return copyList;
+    }
+  }
 };
 };
 </script>
 </script>
 
 
@@ -65,6 +123,15 @@ export default {
   cursor: pointer;
   cursor: pointer;
 }
 }
 
 
+.test-title {
+  position: relative;
+  &__action {
+    position: absolute;
+    right: 0;
+    transform: translateY(-20%);
+  }
+}
+
 .test-item:hover,
 .test-item:hover,
 .test-item:nth-child(even):hover {
 .test-item:nth-child(even):hover {
   background-color: #dde3ef;
   background-color: #dde3ef;