TestPlanTestCaseEdit.vue 13.3 KB
Newer Older
C
chenjianxing 已提交
1 2
<template>

C
chenjianxing 已提交
3 4
  <el-drawer
    :before-close="handleClose"
5 6
    :visible.sync="showDialog"
    :with-header="false"
7
    :modal-append-to-body="false"
C
chenjianxing 已提交
8
    size="100%"
C
chenjianxing 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    ref="drawer"
    v-loading="result.loading">

      <template v-slot:default="scope">
        <div class="container">

          <el-scrollbar>

            <el-header>

              <el-row type="flex" class="head-bar">

                <el-col :span="12">
                  <el-button plain size="mini"
                             icon="el-icon-back"
                             @click="cancel">{{$t('test_track.return')}}</el-button>
                </el-col>

                <el-col :span="12" class="head-right">
                <span class="head-right-tip" v-if="index + 1 == testCases.length">
                  {{$t('test_track.plan_view.pre_case')}} : {{testCases[index - 1] ? testCases[index - 1].name : ''}}
                </span>
                  <span class="head-right-tip" v-if="index + 1 != testCases.length">
                  {{$t('test_track.plan_view.next_case')}} : {{testCases[index + 1] ? testCases[index + 1].name : ''}}
                </span>

                  <el-button plain size="mini" icon="el-icon-arrow-up"
                             :disabled="index + 1 <= 1"
                             @click="handlePre()"/>
                  <span>  {{index + 1}}/{{testCases.length}} </span>
                  <el-button plain size="mini" icon="el-icon-arrow-down"
                             :disabled="index + 1 >= testCases.length"
                             @click="handleNext()"/>
                  <el-divider direction="vertical"></el-divider>

C
chenjianxing 已提交
44
                  <el-button type="primary" size="mini" @click="saveCase(false)">{{$t('test_track.save')}}</el-button>
C
chenjianxing 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
                </el-col>

              </el-row>

              <el-row style="margin-top: 0px;">
                <el-col>
                  <el-divider content-position="left">{{testCase.name}}</el-divider>
                </el-col>
              </el-row>

            </el-header>

            <div class="case_container">
              <el-row >
                <el-col :span="4" :offset="1">
                  <span class="cast_label">{{$t('test_track.case.priority')}}</span>
                  <span class="cast_item">{{testCase.priority}}</span>
                </el-col>
                <el-col :span="5">
                  <span class="cast_label">{{$t('test_track.case.case_type')}}</span>
                  <span class="cast_item" v-if="testCase.type == 'functional'">{{$t('commons.functional')}}</span>
                  <span class="cast_item" v-if="testCase.type == 'performance'">{{$t('commons.performance')}}</span>
                  <span class="cast_item" v-if="testCase.type == 'api'">{{$t('commons.api')}}</span>
                </el-col>
                <el-col :span="13">
                  <test-plan-test-case-status-button class="status-button"
                                                     @statusChange="statusChange"
                                                     :status="testCase.status"/>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="4" :offset="1">
                  <span class="cast_label">{{$t('test_track.case.method')}}</span>
                  <span v-if="testCase.method == 'manual'">{{$t('test_track.case.manual')}}</span>
                  <span v-if="testCase.method == 'auto'">{{$t('test_track.case.auto')}}</span>
                </el-col>
                <el-col :span="5">
                  <span class="cast_label">{{$t('test_track.case.module')}}</span>
                  <span class="cast_item">{{testCase.nodePath}}</span>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="20" :offset="1">
                  <div>
                    <span class="cast_label">{{$t('test_track.case.steps')}}</span>
                  </div>
                  <el-table
                    :data="testCase.steptResults"
                    class="tb-edit"
C
chenjianxing 已提交
96
                    size="mini"
C
chenjianxing 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
                    :border="true"
                    :default-sort = "{prop: 'num', order: 'ascending'}"
                    highlight-current-row>
                    <el-table-column :label="$t('test_track.case.number')" prop="num" min-width="5%"></el-table-column>
                    <el-table-column :label="$t('test_track.case.step_desc')" prop="desc" min-width="29%">
                      <template v-slot:default="scope">
                        <span>{{scope.row.desc}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column :label="$t('test_track.case.expected_results')" prop="result" min-width="28%">
                      <template v-slot:default="scope">
                        <span>{{scope.row.result}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column :label="$t('test_track.plan_view.actual_result')" min-width="29%">
                      <template v-slot:default="scope">
                        <el-input
                          size="mini"
                          type="textarea"
116
                          :autosize="{ minRows: 2, maxRows: 4}"
C
chenjianxing 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
                          :rows="2"
                          v-model="scope.row.actualResult"
                          :placeholder="$t('commons.input_content')"
                          clearable></el-input>
                        <span>{{scope.row.actualResult}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column :label="$t('test_track.plan_view.step_result')" min-width="9%">
                      <template v-slot:default="scope">
                        <el-select
                          v-model="scope.row.executeResult"
                          size="mini">
                          <el-option :label="$t('test_track.plan_view.pass')" value="Pass" style="color: #7ebf50;"></el-option>
                          <el-option :label="$t('test_track.plan_view.failure')" value="Failure" style="color: #e57471;"></el-option>
                          <el-option :label="$t('test_track.plan_view.blocking')" value="Blocking" style="color: #dda451;"></el-option>
                          <el-option :label="$t('test_track.plan_view.skip')" value="Skip" style="color: #919399;"></el-option>
                        </el-select>
                      </template>
                    </el-table-column>
                  </el-table>
                </el-col>
              </el-row>

C
chenjianxing 已提交
140
              <el-row v-if="testCase.issues">
C
chenjianxing 已提交
141 142
                <el-col :span="5" :offset="1">
                  <el-switch
C
chenjianxing 已提交
143 144 145
                    v-model="testCase.issues.hasIssues"
                    @change="issuesChange"
                    :active-text="$t('test_track.plan_view.submit_issues')">
C
chenjianxing 已提交
146 147 148 149
                  </el-switch>
                </el-col>
              </el-row>

C
chenjianxing 已提交
150
              <el-row v-if="testCase.issues && testCase.issues.hasIssues">
C
chenjianxing 已提交
151
                <el-col :span="20" :offset="1" class="step-edit">
C
chenjianxing 已提交
152
                  <ckeditor :editor="editor" v-model="testCase.issues.content"/>
C
chenjianxing 已提交
153 154 155
                </el-col>
              </el-row>

C
chenjianxing 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
              <el-row>
                <el-col :span="15" :offset="1">
                  <div>
                    <span class="cast_label">{{$t('commons.remark')}}:</span>
                    <span v-if="testCase.remark == null || testCase.remark == ''" style="color: darkgrey">{{$t('commons.not_filled')}}</span>
                  </div>
                  <div>
                    <el-input :rows="3"
                              type="textarea"
                              v-if="testCase.remark"
                              disabled
                              v-model="testCase.remark"></el-input>
                  </div>
                </el-col>
              </el-row>
C
chenjianxing 已提交
171 172
            </div>

C
chenjianxing 已提交
173 174 175 176 177
          </el-scrollbar>

        </div>

      </template>
C
chenjianxing 已提交
178 179

  </el-drawer>
C
chenjianxing 已提交
180

C
chenjianxing 已提交
181

C
chenjianxing 已提交
182 183 184
</template>

<script>
C
chenjianxing 已提交
185
  import TestPlanTestCaseStatusButton from '../../common/TestPlanTestCaseStatusButton';
C
chenjianxing 已提交
186
  import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
187 188

  export default {
189
    name: "TestPlanTestCaseEdit",
190 191
    components: {TestPlanTestCaseStatusButton},
    data() {
192
      return {
C
chenjianxing 已提交
193
        result: {},
194 195
        showDialog: false,
        testCase: {},
C
chenjianxing 已提交
196
        index: 0,
C
chenjianxing 已提交
197 198
        testCases: [],
        editor: ClassicEditor,
199 200 201 202 203
      };
    },
    props: {
      total: {
        type: Number
C
chenjianxing 已提交
204 205 206
      },
      searchParam: {
        type: Object
207 208 209 210 211 212 213 214
      }
    },
    methods: {
      handleClose(done) {
        this.showDialog = false;
      },
      cancel() {
        this.showDialog = false;
C
chenjianxing 已提交
215
        this.$emit('refreshTable');
216 217 218 219
      },
      statusChange(status) {
        this.testCase.status = status;
      },
C
chenjianxing 已提交
220
      saveCase(isContinuous) {
221 222 223 224
        let param = {};
        param.id = this.testCase.id;
        param.status = this.testCase.status;
        param.results = [];
C
chenjianxing 已提交
225 226

        for (let i = 0; i < this.testCase.steptResults.length; i++){
227
          let result = {};
C
chenjianxing 已提交
228 229 230 231 232 233 234
          result.actualResult = this.testCase.steptResults[i].actualResult;
          result.executeResult = this.testCase.steptResults[i].executeResult;
          if (result.actualResult && result.actualResult.length > 300) {
            this.$warning(this.$t('test_track.plan_view.actual_result')
              + this.$t('test_track.length_less_than') + '300');
            return;
          }
235
          param.results.push(result);
C
chenjianxing 已提交
236 237
        }

238
        param.results = JSON.stringify(param.results);
C
chenjianxing 已提交
239
        param.issues = JSON.stringify(this.testCase.issues);
240
        this.$post('/test/plan/case/edit', param, () => {
C
chenjianxing 已提交
241 242 243 244
          if (isContinuous) {
            this.updateTestCases(param);
            return;
          }
245
          this.$refs.drawer.closeDrawer();
C
chenjianxing 已提交
246
          this.$success(this.$t('commons.save_success'));
247 248 249 250
          this.$emit('refresh');
        });
      },
      handleNext() {
C
chenjianxing 已提交
251
        this.saveCase(true);
252 253 254 255
        this.index++;
        this.getTestCase(this.index);
      },
      handlePre() {
C
chenjianxing 已提交
256
        this.saveCase(true);
257 258
        this.index--;
        this.getTestCase(this.index);
C
chenjianxing 已提交
259
      },
260
      getTestCase(index) {
C
chenjianxing 已提交
261
        let testCase = this.testCases[index];
262 263 264 265
        let item = {};
        Object.assign(item, testCase);
        item.results = JSON.parse(item.results);
        item.steps = JSON.parse(item.steps);
C
chenjianxing 已提交
266 267
        if (item.issues) {
          item.issues = JSON.parse(item.issues);
C
chenjianxing 已提交
268
        } else {
C
chenjianxing 已提交
269 270
          item.issues = {};
          item.issues.hasIssues = false;
C
chenjianxing 已提交
271
        }
272 273 274 275 276 277 278
        item.steptResults = [];
        for (let i = 0; i < item.steps.length; i++){
          if(item.results[i]){
            item.steps[i].actualResult = item.results[i].actualResult;
            item.steps[i].executeResult = item.results[i].executeResult;
          }
          item.steptResults.push(item.steps[i]);
C
chenjianxing 已提交
279
        }
280
        this.testCase = item;
C
chenjianxing 已提交
281 282 283 284
      },
      openTestCaseEdit(testCase) {
        this.showDialog = true;
        this.initData(testCase);
C
chenjianxing 已提交
285 286 287 288 289 290 291
      },
      updateTestCases(testCase) {
        this.testCases.forEach(item => {
           if (testCase.id === item.id) {
             Object.assign(item, testCase);
           }
        });
C
chenjianxing 已提交
292 293 294 295 296 297 298 299 300 301 302
      },
      initData(testCase) {
        this.result = this.$post('/test/plan/case/list/all', this.searchParam, response => {
          this.testCases = response.data;
          for (let i = 0; i < this.testCases.length; i++) {
            if (this.testCases[i].id === testCase.id) {
              this.index = i;
              this.getTestCase(i);
            }
          }
        });
C
chenjianxing 已提交
303
      },
C
chenjianxing 已提交
304 305
      issuesChange() {
       if (this.testCase.issues.hasIssues) {
C
chenjianxing 已提交
306 307 308
          let desc = this.addPLabel('[' + this.$t('test_track.plan_view.operate_step') + ']');
          let result = this.addPLabel('[' + this.$t('test_track.case.expected_results') + ']');
          let executeResult = this.addPLabel('[' + this.$t('test_track.plan_view.actual_result') + ']');
C
chenjianxing 已提交
309
          this.testCase.steps.forEach(step => {
C
chenjianxing 已提交
310
            let stepPrefix = this.$t('test_track.plan_view.step') + step.num + ':';
C
chenjianxing 已提交
311 312 313 314
            desc += this.addPLabel(stepPrefix + (step.desc == undefined ? '' : step.desc));
            result += this.addPLabel(stepPrefix + (step.result == undefined ? '' : step.result));
            executeResult += this.addPLabel(stepPrefix + (step.executeResult == undefined ? '' : step.executeResult));
          });
C
chenjianxing 已提交
315
          this.testCase.issues.content = desc + this.addPLabel('') + result + this.addPLabel('') + executeResult + this.addPLabel('');
C
chenjianxing 已提交
316 317 318 319
        }
      },
      addPLabel(str) {
        return "<p>" + str + "</p>";
C
chenjianxing 已提交
320 321
      }
    }
322
  }
C
chenjianxing 已提交
323 324 325 326
</script>

<style scoped>

C
chenjianxing 已提交
327

C
chenjianxing 已提交
328
  .tb-edit .el-textarea {
C
chenjianxing 已提交
329 330
    display: none;
  }
C
chenjianxing 已提交
331
  .tb-edit .current-row .el-textarea {
C
chenjianxing 已提交
332 333
    display: block;
  }
C
chenjianxing 已提交
334
  .tb-edit .current-row .el-textarea+span {
C
chenjianxing 已提交
335 336 337
    display: none;
  }

C
chenjianxing 已提交
338 339 340
  .cast_label {
    color: dimgray;
  }
C
chenjianxing 已提交
341

342 343 344 345
  .status-button {
    padding-left: 4%;
  }

346 347 348 349 350 351 352 353
  .head-right {
    text-align: right;
  }

  .el-col {
    line-height: 50px;
  }

C
chenjianxing 已提交
354 355 356 357
  .step-edit >>> p {
    line-height: 16px;
  }

358 359
  .status-button {
    float: right;
C
chenjianxing 已提交
360 361 362 363
  }

  .head-right-tip {
    color: darkgrey;
364 365
  }

C
chenjianxing 已提交
366 367 368 369 370 371 372 373 374 375 376 377
  .el-scrollbar {
    height: 100%;
  }

  .container {
    height: 100vh;
  }

  .case_container > .el-row{
    margin-top: 1%;
  }

C
chenjianxing 已提交
378 379 380 381 382 383 384 385
  .el-switch >>> .el-switch__label {
    color: dimgray;
  }

  .el-switch >>> .el-switch__label.is-active {
    color: #409EFF;
  }

C
chenjianxing 已提交
386
</style>