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

C
chenjianxing 已提交
3

C
chenjianxing 已提交
4 5
  <el-drawer
    :before-close="handleClose"
6 7
    :visible.sync="showDialog"
    :with-header="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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
                    :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"
                          :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>

              <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 已提交
154 155
            </div>

C
chenjianxing 已提交
156 157 158 159 160
          </el-scrollbar>

        </div>

      </template>
C
chenjianxing 已提交
161 162

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

C
chenjianxing 已提交
164

C
chenjianxing 已提交
165 166 167
</template>

<script>
C
chenjianxing 已提交
168
  import TestPlanTestCaseStatusButton from '../../common/TestPlanTestCaseStatusButton';
169 170

  export default {
171
    name: "TestPlanTestCaseEdit",
172 173
    components: {TestPlanTestCaseStatusButton},
    data() {
174
      return {
C
chenjianxing 已提交
175
        result: {},
176 177
        showDialog: false,
        testCase: {},
C
chenjianxing 已提交
178 179
        index: 0,
        testCases: []
180 181 182 183 184
      };
    },
    props: {
      total: {
        type: Number
C
chenjianxing 已提交
185 186 187
      },
      searchParam: {
        type: Object
188 189 190 191 192 193 194 195
      }
    },
    methods: {
      handleClose(done) {
        this.showDialog = false;
      },
      cancel() {
        this.showDialog = false;
C
chenjianxing 已提交
196
        this.$emit('refreshTable');
197 198 199 200
      },
      statusChange(status) {
        this.testCase.status = status;
      },
C
chenjianxing 已提交
201
      saveCase(isContinuous) {
202 203 204 205 206 207 208 209 210 211 212 213
        let param = {};
        param.id = this.testCase.id;
        param.status = this.testCase.status;
        param.results = [];
        this.testCase.steptResults.forEach(item => {
          let result = {};
          result.actualResult = item.actualResult;
          result.executeResult = item.executeResult;
          param.results.push(result);
        });
        param.results = JSON.stringify(param.results);
        this.$post('/test/plan/case/edit', param, () => {
C
chenjianxing 已提交
214 215 216 217
          if (isContinuous) {
            this.updateTestCases(param);
            return;
          }
218
          this.$refs.drawer.closeDrawer();
C
chenjianxing 已提交
219
          this.$message.success(this.$t('commons.save_success'));
220 221 222 223
          this.$emit('refresh');
        });
      },
      handleNext() {
C
chenjianxing 已提交
224
        this.saveCase(true);
225 226 227 228
        this.index++;
        this.getTestCase(this.index);
      },
      handlePre() {
C
chenjianxing 已提交
229
        this.saveCase(true);
230 231
        this.index--;
        this.getTestCase(this.index);
C
chenjianxing 已提交
232
      },
233
      getTestCase(index) {
C
chenjianxing 已提交
234
        let testCase = this.testCases[index];
235 236 237 238 239 240 241 242 243 244 245
        let item = {};
        Object.assign(item, testCase);
        item.results = JSON.parse(item.results);
        item.steps = JSON.parse(item.steps);
        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 已提交
246
        }
247
        this.testCase = item;
C
chenjianxing 已提交
248 249 250 251
      },
      openTestCaseEdit(testCase) {
        this.showDialog = true;
        this.initData(testCase);
C
chenjianxing 已提交
252 253 254 255 256 257 258
      },
      updateTestCases(testCase) {
        this.testCases.forEach(item => {
           if (testCase.id === item.id) {
             Object.assign(item, testCase);
           }
        });
C
chenjianxing 已提交
259 260 261 262 263 264 265 266 267 268 269
      },
      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 已提交
270 271
      }
    }
272
  }
C
chenjianxing 已提交
273 274 275 276
</script>

<style scoped>

C
chenjianxing 已提交
277

C
chenjianxing 已提交
278
  .tb-edit .el-textarea {
C
chenjianxing 已提交
279 280
    display: none;
  }
C
chenjianxing 已提交
281
  .tb-edit .current-row .el-textarea {
C
chenjianxing 已提交
282 283
    display: block;
  }
C
chenjianxing 已提交
284
  .tb-edit .current-row .el-textarea+span {
C
chenjianxing 已提交
285 286 287
    display: none;
  }

C
chenjianxing 已提交
288 289 290
  .cast_label {
    color: dimgray;
  }
C
chenjianxing 已提交
291

292 293 294 295
  .status-button {
    padding-left: 4%;
  }

296 297 298 299 300 301 302 303 304 305
  .head-right {
    text-align: right;
  }

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

  .status-button {
    float: right;
C
chenjianxing 已提交
306 307 308 309
  }

  .head-right-tip {
    color: darkgrey;
310 311
  }

C
chenjianxing 已提交
312 313 314 315 316 317 318 319 320 321 322 323
  .el-scrollbar {
    height: 100%;
  }

  .container {
    height: 100vh;
  }

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

C
chenjianxing 已提交
324
</style>