TestPlanTestCaseList.vue 12.7 KB
Newer Older
C
chenjianxing 已提交
1
<template>
王振 已提交
2
  <el-card class="table-card" v-loading="result.loading">
C
chenjianxing 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
    <template v-slot:header>
      <ms-table-header :condition.sync="condition" @search="initTableData" :show-create="false">
        <template v-slot:title>
          <node-breadcrumb class="table-title" :node-names="selectNodeNames" @refresh="refresh"/>
        </template>
        <template v-slot:button>
          <ms-table-button v-if="!showMyTestCase" icon="el-icon-s-custom" :content="$t('test_track.plan_view.my_case')" @click="searchMyTestCase"/>
          <ms-table-button v-if="showMyTestCase" icon="el-icon-files" :content="$t('test_track.plan_view.all_case')" @click="searchMyTestCase"/>
          <ms-table-button icon="el-icon-connection" :content="$t('test_track.plan_view.relevance_test_case')" @click="$emit('openTestCaseRelevanceDialog')"/>
          <ms-table-button icon="el-icon-edit-outline" :content="$t('test_track.plan_view.change_execution_results')" @click="handleBatch('status')"/>
          <ms-table-button icon="el-icon-user" :content="$t('test_track.plan_view.change_executor')" @click="handleBatch('executor')"/>
          <ms-table-button v-if="!testPlan.reportId" icon="el-icon-document" :content="$t('创建测试报告')" @click="openTestReport"/>
          <ms-table-button v-if="testPlan.reportId" icon="el-icon-document" :content="$t('查看测试报告')" @click="openReport"/>
        </template>
      </ms-table-header>
    </template>
C
chenjianxing 已提交
19

C
chenjianxing 已提交
20 21
    <executor-edit ref="executorEdit" :select-ids="selectIds" @refresh="initTableData"/>
    <status-edit ref="statusEdit" :select-ids="selectIds" @refresh="initTableData"/>
C
chenjianxing 已提交
22

C
chenjianxing 已提交
23 24
    <el-table
      @select-all="handleSelectAll"
C
chenjianxing 已提交
25 26
      @filter-change="filter"
      @sort-change="sort"
C
chenjianxing 已提交
27 28 29
      @select="handleSelectionChange"
      row-key="id"
      :data="tableData">
C
chenjianxing 已提交
30

C
chenjianxing 已提交
31 32
      <el-table-column
        type="selection"></el-table-column>
33

C
chenjianxing 已提交
34 35 36 37 38 39 40 41
      <el-table-column
        prop="name"
        :label="$t('commons.name')"
        show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        prop="priority"
        :filters="priorityFilters"
C
chenjianxing 已提交
42
        column-key="priority"
C
chenjianxing 已提交
43 44 45 46 47
        :label="$t('test_track.case.priority')">
        <template v-slot:default="scope">
          <priority-table-item :value="scope.row.priority" ref="priority"/>
        </template>
      </el-table-column>
C
chenjianxing 已提交
48

C
chenjianxing 已提交
49 50 51
      <el-table-column
        prop="type"
        :filters="typeFilters"
C
chenjianxing 已提交
52
        column-key="type"
C
chenjianxing 已提交
53 54 55 56 57 58
        :label="$t('test_track.case.type')"
        show-overflow-tooltip>
        <template v-slot:default="scope">
          <type-table-item :value="scope.row.type"/>
        </template>
      </el-table-column>
C
chenjianxing 已提交
59

C
chenjianxing 已提交
60 61 62
      <el-table-column
        prop="method"
        :filters="methodFilters"
C
chenjianxing 已提交
63
        column-key="method"
C
chenjianxing 已提交
64 65 66 67 68 69
        :label="$t('test_track.case.method')"
        show-overflow-tooltip>
        <template v-slot:default="scope">
          <method-table-item :value="scope.row.method"/>
        </template>
      </el-table-column>
C
chenjianxing 已提交
70

C
chenjianxing 已提交
71
      <el-table-column
C
chenjianxing 已提交
72
        prop="executorName"
C
chenjianxing 已提交
73 74
        :label="$t('test_track.plan_view.executor')">
      </el-table-column>
C
chenjianxing 已提交
75

C
chenjianxing 已提交
76 77 78
      <el-table-column
        prop="status"
        :filters="statusFilters"
C
chenjianxing 已提交
79
        column-key="status"
C
chenjianxing 已提交
80 81 82 83 84
        :label="$t('test_track.plan_view.execute_result')">
        <template v-slot:default="scope">
          <status-table-item :value="scope.row.status"/>
        </template>
      </el-table-column>
C
chenjianxing 已提交
85

C
chenjianxing 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
      <el-table-column
        sortable
        prop="updateTime"
        :label="$t('commons.update_time')"
        show-overflow-tooltip>
        <template v-slot:default="scope">
          <span>{{ scope.row.updateTime | timestampFormatDate }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('commons.operating')">
        <template v-slot:default="scope">
          <ms-table-operator-button :tip="$t('commons.edit')" icon="el-icon-edit" @exec="handleEdit(scope.row)" />
          <ms-table-operator-button :tip="$t('test_track.plan_view.cancel_relevance')" icon="el-icon-unlock" type="danger" @exec="handleDelete(scope.row)"/>
        </template>
      </el-table-column>
    </el-table>
C
chenjianxing 已提交
103

C
chenjianxing 已提交
104 105
    <ms-table-pagination :change="search" :current-page.sync="currentPage" :page-size.sync="pageSize"
                         :total="total"/>
C
chenjianxing 已提交
106

C
chenjianxing 已提交
107 108 109 110 111 112 113
    <test-plan-test-case-edit
      ref="testPlanTestCaseEdit"
      :search-param="condition"
      @refresh="refresh"
      @refreshTable="search"/>

    <test-report-template-list @openReport="openReport" :plan-id="planId" ref="testReporTtemplateList"/>
C
chenjianxing 已提交
114
    <test-case-report-view :plan-id="planId" ref="testCaseReportView"/>
115

C
chenjianxing 已提交
116 117 118 119
    </el-card>
</template>

<script>
120 121
  import ExecutorEdit from './ExecutorEdit';
  import StatusEdit from './StatusEdit';
C
chenjianxing 已提交
122 123 124 125 126 127
  import TestPlanTestCaseEdit from "./TestPlanTestCaseEdit";
  import MsTipButton from '../../../../common/components/MsTipButton';
  import MsTablePagination from '../../../../common/pagination/TablePagination';
  import MsTableHeader from '../../../../common/components/MsTableHeader';
  import MsTableButton from '../../../../common/components/MsTableButton';
  import NodeBreadcrumb from '../../../common/NodeBreadcrumb';
C
chenjianxing 已提交
128

C
chenjianxing 已提交
129
  import {TokenKey} from '../../../../../../common/js/constants';
C
chenjianxing 已提交
130
  import {humpToLine, tableFilter} from '../../../../../../common/js/utils';
C
chenjianxing 已提交
131 132 133 134
  import PriorityTableItem from "../../../common/tableItems/planview/PriorityTableItem";
  import StatusTableItem from "../../../common/tableItems/planview/StatusTableItem";
  import TypeTableItem from "../../../common/tableItems/planview/TypeTableItem";
  import MethodTableItem from "../../../common/tableItems/planview/MethodTableItem";
C
chenjianxing 已提交
135
  import MsTableOperator from "../../../../common/components/MsTableOperator";
C
chenjianxing 已提交
136
  import MsTableOperatorButton from "../../../../common/components/MsTableOperatorButton";
C
chenjianxing 已提交
137 138
  import TestReportTemplateList from "./TestReportTemplateList";
  import TestCaseReportView from "./TestCaseReportView";
C
chenjianxing 已提交
139

C
v-slot  
Captain.B 已提交
140
  export default {
C
chenjianxing 已提交
141
      name: "TestPlanTestCaseList",
C
chenjianxing 已提交
142
      components: {
C
chenjianxing 已提交
143 144
        TestCaseReportView,
        TestReportTemplateList,
C
chenjianxing 已提交
145
        MsTableOperatorButton,
C
chenjianxing 已提交
146
        MsTableOperator,
C
chenjianxing 已提交
147 148 149 150
        MethodTableItem,
        TypeTableItem,
        StatusTableItem,
        PriorityTableItem, StatusEdit, ExecutorEdit, MsTipButton, MsTablePagination,
C
chenjianxing 已提交
151
        TestPlanTestCaseEdit, MsTableHeader, NodeBreadcrumb, MsTableButton},
C
chenjianxing 已提交
152 153 154 155
      data() {
        return {
          result: {},
          deletePath: "/test/case/delete",
C
chenjianxing 已提交
156 157
          condition: {},
          showMyTestCase: false,
C
chenjianxing 已提交
158 159
          tableData: [],
          currentPage: 1,
C
chenjianxing 已提交
160
          pageSize: 10,
C
chenjianxing 已提交
161
          total: 0,
C
chenjianxing 已提交
162
          selectIds: new Set(),
C
chenjianxing 已提交
163
          testPlan: {},
C
chenjianxing 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
          priorityFilters: [
            {text: 'P0', value: 'P0'},
            {text: 'P1', value: 'P1'},
            {text: 'P2', value: 'P2'}
          ],
          methodFilters: [
            {text: this.$t('test_track.case.manual'), value: 'manual'},
            {text: this.$t('test_track.case.auto'), value: 'auto'}
          ],
          typeFilters: [
            {text: this.$t('commons.functional'), value: 'functional'},
            {text: this.$t('commons.performance'), value: 'performance'},
            {text: this.$t('commons.api'), value: 'api'}
          ],
          statusFilters: [
            {text: this.$t('test_track.plan.plan_status_prepare'), value: 'Prepare'},
            {text: this.$t('test_track.plan_view.pass'), value: 'Pass'},
            {text: this.$t('test_track.plan_view.failure'), value: 'Failure'},
            {text: this.$t('test_track.plan_view.blocking'), value: 'Blocking'},
            {text: this.$t('test_track.plan_view.skip'), value: 'Skip'},
          ]
C
chenjianxing 已提交
185 186
        }
      },
C
chenjianxing 已提交
187 188 189
      props:{
        planId: {
          type: String
C
chenjianxing 已提交
190 191 192
        },
        selectNodeIds: {
          type: Array
C
chenjianxing 已提交
193 194 195
        },
        selectNodeNames: {
          type: Array
C
chenjianxing 已提交
196 197
        }
      },
C
chenjianxing 已提交
198 199
      watch: {
        planId() {
C
chenjianxing 已提交
200
          this.refreshTableAndPlan();
C
chenjianxing 已提交
201 202
        },
        selectNodeIds() {
C
chenjianxing 已提交
203
          this.search();
C
chenjianxing 已提交
204 205
        }
      },
C
chenjianxing 已提交
206
      mounted() {
C
chenjianxing 已提交
207
        this.refreshTableAndPlan();
C
chenjianxing 已提交
208 209
      },
      methods: {
C
chenjianxing 已提交
210
        initTableData() {
C
chenjianxing 已提交
211
          if (this.planId) {
C
chenjianxing 已提交
212 213 214
            this.condition.planId = this.planId;
            this.condition.nodeIds = this.selectNodeIds;
            this.result = this.$post(this.buildPagePath('/test/plan/case/list'), this.condition, response => {
C
chenjianxing 已提交
215 216 217
              let data = response.data;
              this.total = data.itemCount;
              this.tableData = data.listObject;
C
chenjianxing 已提交
218
              this.selectIds.clear();
C
chenjianxing 已提交
219
            });
C
chenjianxing 已提交
220 221
          }
        },
C
chenjianxing 已提交
222 223
        refresh() {
          this.condition = {};
C
chenjianxing 已提交
224
          this.selectIds.clear();
C
chenjianxing 已提交
225
          this.$emit('refresh');
C
chenjianxing 已提交
226
        },
C
chenjianxing 已提交
227 228 229 230 231 232 233 234 235 236
        refreshTableAndPlan() {
          this.getTestPlanById();
          this.initTableData();
        },
        refreshTestPlanRecent() {
          let param = {};
          param.id = this.planId;
          param.updateTime = Date.now();
          this.$post('/test/plan/edit', param);
        },
C
chenjianxing 已提交
237 238 239
        search() {
          this.initTableData();
        },
C
chenjianxing 已提交
240 241 242
        buildPagePath(path) {
          return path + "/" + this.currentPage + "/" + this.pageSize;
        },
243
        handleEdit(testCase, index) {
C
chenjianxing 已提交
244
          this.$refs.testPlanTestCaseEdit.openTestCaseEdit(testCase);
C
chenjianxing 已提交
245 246
        },
        handleDelete(testCase) {
C
chenjianxing 已提交
247
          this.$alert(this.$t('test_track.plan_view.confirm_cancel_relevance') + ' ' + testCase.name + "", '', {
C
chenjianxing 已提交
248 249 250 251 252 253 254 255 256 257
            confirmButtonText: this.$t('commons.confirm'),
            callback: (action) => {
              if (action === 'confirm') {
                this._handleDelete(testCase);
              }
            }
          });
        },
        _handleDelete(testCase) {
          let testCaseId = testCase.id;
C
chenjianxing 已提交
258
          this.$post('/test/plan/case/delete/' + testCaseId, {}, () => {
C
chenjianxing 已提交
259
            this.$emit("refresh");
C
chenjianxing 已提交
260
            this.$success(this.$t('commons.delete_success'));
C
chenjianxing 已提交
261
          });
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
        },
        handleSelectAll(selection) {
          if(selection.length > 0) {
            this.tableData.forEach(item => {
              this.selectIds.add(item.id);
            });
          } else {
            this.selectIds.clear();
          }
        },
        handleSelectionChange(selection, row) {
          if(this.selectIds.has(row.id)){
            this.selectIds.delete(row.id);
          } else {
            this.selectIds.add(row.id);
          }
        },
        handleBatch(type){
          if (this.selectIds.size < 1) {
C
chenjianxing 已提交
281
            this.$warning(this.$t('test_track.plan_view.select_manipulate'));
282 283 284 285 286 287 288
            return;
          }
          if (type === 'executor'){
            this.$refs.executorEdit.openExecutorEdit();
          } else if (type === 'status'){
            this.$refs.statusEdit.openStatusEdit();
          }
C
chenjianxing 已提交
289 290 291 292 293 294 295 296 297 298
        },
        searchMyTestCase() {
          this.showMyTestCase = !this.showMyTestCase;
          if (this.showMyTestCase) {
            let user =  JSON.parse(localStorage.getItem(TokenKey));
            this.condition.executor = user.id;
          } else {
            this.condition.executor = null;
          }
          this.initTableData();
C
chenjianxing 已提交
299
        },
C
chenjianxing 已提交
300
        openTestReport() {
C
chenjianxing 已提交
301 302 303 304 305 306
          this.$refs.testReporTtemplateList.open();
        },
        getTestPlanById() {
          if (this.planId) {
            this.$post('/test/plan/get/' + this.planId, {}, response => {
              this.testPlan = response.data;
C
chenjianxing 已提交
307
              this.refreshTestPlanRecent();
C
chenjianxing 已提交
308 309 310 311
            });
          }
        },
        openReport(id) {
C
uuid  
chenjianxing 已提交
312
          this.getTestPlanById();
C
chenjianxing 已提交
313 314 315 316
          if (!id) {
            id = this.testPlan.reportId;
          }
          this.$refs.testCaseReportView.open(id);
C
chenjianxing 已提交
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
        },
        filter(filters) {
          if (!this.condition.filters) {
            this.condition.filters = {};
          }
          for(let filter in filters) {
            if (filters[filter] && filters[filter].length > 0) {
              this.condition.filters[filter] = filters[filter];
            } else {
              this.condition.filters[filter] = null;
            }
          }
          this.initTableData();
        },
        sort(column) {
          column.prop = humpToLine(column.prop);
          if (column.order == 'descending') {
            column.order = 'desc';
          } else {
            column.order = 'asc';
          }
          if (!this.condition.orders) {
            this.condition.orders = [];
          }
          let hasProp = false;
          this.condition.orders.forEach(order => {
            if (order.name == column.prop) {
              order.type = column.order;
              hasProp = true;
              return;
            }
          });
          if (!hasProp) {
            this.condition.orders.push({name: column.prop, type: column.order});
          }
          this.initTableData();
C
chenjianxing 已提交
353 354 355 356 357 358 359
        }
      }
    }
</script>

<style scoped>

C
chenjianxing 已提交
360 361 362 363 364
  .search {
    margin-left: 10px;
    width: 240px;
  }

C
chenjianxing 已提交
365
</style>