Skip to content

Commit c7af671

Browse files
committed
完成回归测试的逻辑
1 parent bba906c commit c7af671

File tree

2 files changed

+76
-15
lines changed

2 files changed

+76
-15
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
</ul>
161161
</span>
162162

163-
<a class="hint--top save-tool" data-hint="回归测试,TODO 做成列表上方的文字按钮" href="javascript:void(0)" @click="test(true)">
163+
<a class="hint--top save-tool" data-hint="回归测试,TODO 做成列表上方的文字按钮" href="javascript:void(0)" @click="test()">
164164
<svg class="icon">
165165
<use xlink:href="svg/icon.svg#save"></use>
166166
</svg>

js/main.js

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
historys: [],
130130
history: {name: '请求0'},
131131
remotes: [],
132-
testList: [],
132+
tests: [],
133133
isDelayShow: false,
134134
isSaveShow: false,
135135
isExportShow: false,
@@ -1172,29 +1172,53 @@
11721172
2.逐个发送请求
11731173
3.对比同一用例的先后两次请求结果,如果不一致,就在列表中标记对应的用例(× 蓝黄红色下载(点击下载两个文件) √)。
11741174
4.如果这次请求结果正确,就把请求结果保存到和公司开发环境服务器的APIJSON Server,并取消标记
1175+
1176+
compare: 新的请求与上次请求的对比结果
1177+
0-相同,无颜色;
1178+
1-对象新增字段或数组新增值,绿色;
1179+
2-值改变,蓝色;
1180+
3-对象缺少字段,黄色;
1181+
4-类型改变,红色;
11751182
*/
11761183
test: function () {
11771184
var baseUrl = App.getBaseUrl()
1178-
var testList = App.testList || []
11791185
var list = App.remotes || []
11801186
var item
1187+
alert('test list.length = ' + list.length)
11811188
for (var i = 0; i < list.length; i ++) {
11821189
item = list[i]
11831190
if (item == null || item.name == null) {
11841191
continue
11851192
}
1193+
if (item.userId != App.User.id || item.url == '/logout') {
1194+
console.log('test item.userId != User.id || item.url == /logout >> continue')
1195+
continue
1196+
}
1197+
console.log('test item = ' + JSON.stringify(item, null, ' '))
1198+
11861199
App.restore(item)
11871200
App.onChange(false)
1188-
App.request(baseUrl + item.url, item.request, function (url, res, err) {
1189-
App.onResponse(url, res, err)
11901201

1191-
if (res.data != item.response) {
1192-
item.compare = 4
1193-
alert('res.data != item.response')
1202+
const index = i; //请求异步
1203+
App.request(baseUrl + item.url, JSON.parse(item.request), function (url, res, err) {
1204+
App.onResponse(url, res, err)
1205+
console.log('test App.request >> res.data = ' + JSON.stringify(res.data, null, ' '))
1206+
1207+
var response = JSON.stringify(res.data)
1208+
1209+
var it = list[index] //请求异步
1210+
it.compare = it.response == response ? 0 : 4
1211+
console.log('i = ' + index + '; item.name = ' + it.name + '; item.compare = ' + it.compare)
1212+
if (it.compare > 0) {
1213+
alert('i = ' + index + '; item.name = ' + it.name + '; item.compare = ' + it.compare
1214+
+ '; it.response = \n' + it.response
1215+
+ '\n\n\n res.data = \n' + response
1216+
)
11941217
}
11951218

1196-
testList.push(res.data)
1197-
App.testList = testList
1219+
var tests = App.tests || {}
1220+
tests[it.id] = response
1221+
App.tests = tests
11981222
App.isRemoteShow = true
11991223
})
12001224
}
@@ -1206,14 +1230,51 @@
12061230

12071231
handleTest: function (right, index, item) {
12081232
if (right) {
1209-
var testList = App.testList || []
1210-
item.response = testList[index]
1233+
var tests = App.tests || {}
1234+
item.response = tests[item.id]
12111235
}
12121236
item.compare = 0
1213-
var list = App.remotes || []
1214-
list[index] = item
1237+
Vue.set(App.remotes, index, item);
1238+
1239+
if (right) {
1240+
var baseUrl = App.getBaseUrl()
1241+
vUrl.value = baseUrl + '/put'
1242+
1243+
vInput.value = JSON.stringify({
1244+
Document: {
1245+
id: item.id,
1246+
response: item.response
1247+
},
1248+
tag: 'Document'
1249+
})
1250+
1251+
App.showRemote(false)
1252+
App.onChange(false)
1253+
App.send(function (url, res, err) {
1254+
App.onResponse(url, res, err)
1255+
1256+
var rpObj = res.data
1257+
if (rpObj != null && rpObj.code === 200) {
1258+
App.showRemote(true)
1259+
1260+
App.request(baseUrl + '/post', {
1261+
TestRecord: {
1262+
userId: App.User.id, //TODO 权限问题? item.userId,
1263+
documentId: item.id,
1264+
response: item.response
1265+
},
1266+
tag: 'TestRecord'
1267+
},
1268+
function (url, res, err) {}
1269+
)
1270+
1271+
}
1272+
1273+
})
1274+
1275+
}
12151276
}
1216-
// APIJSON >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1277+
// APIJSON >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
12171278

12181279
},
12191280
watch: {

0 commit comments

Comments
 (0)