TestDetail.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <div class="columns is-desktop">
  3. <div class="column">
  4. <div v-if="detailLoading"><page-section-loading show /></div>
  5. <div v-else class="page-section">
  6. <h5 class="title is-5">单元测试:</h5>
  7. <div v-if="!(unitTestList && unitTestList.length > 0)">
  8. <strong>当前暂无单元测试数据</strong>
  9. </div>
  10. <router-link
  11. class="test-item"
  12. :key="item.id"
  13. :to="`${$route.path}/unit/${item.id}`"
  14. v-for="item in unitTestList"
  15. tag="div"
  16. >
  17. <div><strong>UNIT TEST : #</strong> {{ item.id }}</div>
  18. <pass-tag v-if="item.status == 1" :pass="item.passAll" />
  19. <b-tag v-else type="is-warning">RUNNING</b-tag>
  20. <span style="padding-left: 10px">{{
  21. displayUnixTime(item.time)
  22. }}</span>
  23. </router-link>
  24. </div>
  25. </div>
  26. <div class="column">
  27. <div v-if="detailLoading"><page-section-loading show /></div>
  28. <div v-else class="page-section">
  29. <h5 class="test-title title is-5">
  30. 页面测试:
  31. <div
  32. :class="{ 'is-loading': testing }"
  33. @click="makeTest"
  34. :disabled="
  35. !(
  36. projectDetail.latestDeploy &&
  37. projectDetail.latestDeploy.status == 'SUCCESS'
  38. )
  39. "
  40. class="button is-primary test-title__action"
  41. >
  42. 触发测试
  43. </div>
  44. </h5>
  45. <div v-if="!(functionTestList && functionTestList.length > 0)">
  46. <strong>当前暂无页面测试数据</strong>
  47. </div>
  48. <router-link
  49. class="test-item"
  50. :key="item.id"
  51. :to="`${$route.path}/functional/${item.id}`"
  52. v-for="item in functionTestList"
  53. tag="div"
  54. >
  55. <div><strong>FUNCTIONAL TEST : #</strong> {{ item.id }}</div>
  56. <pass-tag v-if="item.status == 1" :pass="item.passAll" />
  57. <b-tag v-else type="is-warning">RUNNING</b-tag>
  58. <span style="padding-left: 10px">{{
  59. displayUnixTime(item.time)
  60. }}</span>
  61. </router-link>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import PassTag from "@/views/student/Code/ProjectDetail/components/PassTag";
  68. import timeMixins from "@/mixins/time";
  69. import { makeFunctionalTest } from "@/api/codehw";
  70. import PageSectionLoading from "@/components/PageBody/PageSectionLoading/index";
  71. import BTag from "buefy/src/components/tag/Tag";
  72. export default {
  73. components: {
  74. BTag,
  75. PageSectionLoading,
  76. PassTag
  77. },
  78. props: {
  79. projectDetail: {
  80. type: Object,
  81. default: () => ({
  82. unitTestList: [],
  83. functionTestList: []
  84. })
  85. },
  86. detailLoading: {
  87. type: Boolean,
  88. default: false
  89. }
  90. },
  91. computed: {
  92. unitTestList() {
  93. return this.sortTestList(this.projectDetail.unitTestList);
  94. },
  95. functionTestList() {
  96. return this.sortTestList(this.projectDetail.functionTestList);
  97. }
  98. },
  99. data() {
  100. return {
  101. testing: false
  102. };
  103. },
  104. mixins: [timeMixins],
  105. methods: {
  106. async makeTest() {
  107. if (
  108. !(
  109. this.projectDetail.latestDeploy &&
  110. this.projectDetail.latestDeploy.status == "SUCCESS"
  111. )
  112. ) {
  113. return;
  114. }
  115. this.testing = true;
  116. const deployId = this.projectDetail.latestDeploy.id;
  117. const { homeworkId, projectId } = this.$route.params;
  118. const { data } = await makeFunctionalTest({
  119. homeworkId,
  120. projectId,
  121. deployId
  122. });
  123. this.testing = false;
  124. if (data.success) {
  125. this.$toast.open({
  126. message: `测试触发成功`,
  127. type: "is-success"
  128. });
  129. } else {
  130. this.$toast.open({
  131. message: `测试触发失败`,
  132. type: "is-danger"
  133. });
  134. }
  135. },
  136. sortTestList(list) {
  137. console.log(list);
  138. if (!list) return [];
  139. const copyList = list.slice(0);
  140. copyList.sort((a, b) => b.time - a.time);
  141. return copyList;
  142. }
  143. }
  144. };
  145. </script>
  146. <style lang="scss" scoped>
  147. @import "../../../../assets/scss/app";
  148. .test-item {
  149. padding: $default-margin $default-margin-between;
  150. margin: 0 -#{$default-margin-between};
  151. cursor: pointer;
  152. }
  153. .test-title {
  154. position: relative;
  155. &__action {
  156. position: absolute;
  157. right: 0;
  158. transform: translateY(-20%);
  159. }
  160. }
  161. .test-item:hover,
  162. .test-item:nth-child(even):hover {
  163. background-color: #dde3ef;
  164. }
  165. .test-item:nth-child(even) {
  166. background-color: rgba(244, 247, 252, 0.6);
  167. }
  168. </style>