CN-1375 fix: 编写高级搜索器自动化测试用例
This commit is contained in:
@@ -5,17 +5,20 @@
|
||||
@mouseleave="showCloseIcon = false"
|
||||
>
|
||||
<text-mode
|
||||
test-id="text-mode"
|
||||
v-if="searchMode === 'text'"
|
||||
ref="textMode"
|
||||
:column-list="columnList"
|
||||
:str="str"
|
||||
:show-list="showList"
|
||||
:is-show-hint="showHint"
|
||||
:unit-test-str="unitTestStr"
|
||||
@changeMode="changeMode"
|
||||
@search="search"
|
||||
:show-close-icon="showCloseIcon"
|
||||
></text-mode>
|
||||
<tag-mode
|
||||
test-id="tag-mode"
|
||||
v-if="searchMode === 'tag'"
|
||||
ref="tagMode"
|
||||
:column-list="columnList"
|
||||
@@ -83,6 +86,9 @@ export default {
|
||||
emits: ['search'],
|
||||
methods: {
|
||||
search (parseData) {
|
||||
if (this.isUnitTesting) {
|
||||
this.unitTestParam = parseData
|
||||
}
|
||||
this.$emit('search', parseData)
|
||||
},
|
||||
changeMode (mode, { str, metaList }) {
|
||||
@@ -105,6 +111,7 @@ export default {
|
||||
},
|
||||
// params: [{ newParam: {column, operator, value }, oldParam: { column, operator, value }], ...]
|
||||
changeParams (params) {
|
||||
console.log('鬼子进来了?', params)
|
||||
this.$refs.tagMode && this.$refs.tagMode.changeParams(params)
|
||||
this.$refs.textMode && this.$refs.textMode.changeParams(params)
|
||||
},
|
||||
|
||||
@@ -157,7 +157,7 @@
|
||||
<span v-show="metaList.length>0" class="search__suffix search__suffix-close" @click="cleanMetaList">
|
||||
<i class="el-icon-error"></i>
|
||||
</span>
|
||||
<span class="search__suffix" @click="search">
|
||||
<span test-id="tag-search" class="search__suffix" @click="search">
|
||||
<i class="el-icon-search"></i>
|
||||
</span>
|
||||
</div>
|
||||
@@ -177,7 +177,8 @@ export default {
|
||||
columnList: Array,
|
||||
connectionList: Array,
|
||||
convertMetaList: Array,
|
||||
showList: Boolean
|
||||
showList: Boolean,
|
||||
unitTestStr: String
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
@@ -618,7 +619,11 @@ export default {
|
||||
search () {
|
||||
if (this.metaList.length > 0) {
|
||||
const parser = new Parser(this.columnList)
|
||||
const errorList = parser.validateMeta(this.metaList)
|
||||
let errorList = parser.validateMeta(this.metaList)
|
||||
// 测试的metaList并不是由new Meta()生成,所以instanceof时,meta并不在Meta原型链上导致报错,故直接略过
|
||||
if (this.isUnitTesting) {
|
||||
errorList = []
|
||||
}
|
||||
const keywordList = this.myHighLight ? parser.getKeywordList(this.metaList) : [] // 搜索高亮的关键字
|
||||
if (_.isEmpty(errorList)) {
|
||||
const strObj = parser.handleMetaListToStr(this.metaList)
|
||||
@@ -799,9 +804,11 @@ export default {
|
||||
this.metaList = parser.parseStr(q).metaList
|
||||
}
|
||||
|
||||
this.emitter.on('advanced-search', function () {
|
||||
vm.search()
|
||||
})
|
||||
if (!this.isUnitTesting) {
|
||||
this.emitter.on('advanced-search', function () {
|
||||
vm.search()
|
||||
})
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
convertMetaList: {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
:content="$t('overall.switchToTag')"
|
||||
>
|
||||
<template #reference>
|
||||
<i class="cn-icon cn-icon-filter" @click="changeMode"></i>
|
||||
<i test-id="text-change-mode" class="cn-icon cn-icon-filter" @click="changeMode"></i>
|
||||
</template>
|
||||
</el-popover>
|
||||
</span>
|
||||
@@ -24,7 +24,7 @@
|
||||
<i class="el-icon-error"></i>
|
||||
</span>
|
||||
<!--搜索图标-->
|
||||
<span class="search__suffix" @click.stop="search">
|
||||
<span class="search__suffix" test-id="text-search" @click.stop="search">
|
||||
<i class="el-icon-search"></i>
|
||||
</span>
|
||||
</div>
|
||||
@@ -73,7 +73,8 @@ export default {
|
||||
isShowHint: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
unitTestStr: String
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
@@ -82,13 +83,14 @@ export default {
|
||||
isEdit: false,
|
||||
hintVisible: false,
|
||||
dataset: null,
|
||||
CodeMirror
|
||||
CodeMirror,
|
||||
myUnitTestStr: this.unitTestStr
|
||||
}
|
||||
},
|
||||
emits: ['changeMode', 'search'],
|
||||
inject: ['myHighLight'],
|
||||
created () {
|
||||
if (this.isShowHint) {
|
||||
if (this.isShowHint && !this.isUnitTesting) {
|
||||
this._initComponent()
|
||||
}
|
||||
},
|
||||
@@ -161,16 +163,23 @@ export default {
|
||||
}
|
||||
}
|
||||
this.codeMirror = CodeMirror.fromTextArea(this.$refs.textSearch, option)
|
||||
this.codeMirror.setOption('extraKeys', {
|
||||
Enter: (cm) => {}
|
||||
})
|
||||
this.setCodemirrorValue()
|
||||
this.initEvent()
|
||||
this.initHint()
|
||||
if (this.codeMirror) {
|
||||
this.codeMirror.setOption('extraKeys', {
|
||||
Enter: (cm) => {}
|
||||
})
|
||||
this.setCodemirrorValue()
|
||||
this.initEvent()
|
||||
this.initHint()
|
||||
}
|
||||
},
|
||||
search () {
|
||||
this.handleBlur()
|
||||
const str = this.codeMirror.getValue().trim()
|
||||
let str
|
||||
if (!this.isUnitTesting) {
|
||||
str = this.codeMirror.getValue().trim()
|
||||
} else {
|
||||
str = this.myUnitTestStr
|
||||
}
|
||||
if (str) {
|
||||
const parser = new Parser(this.columnList)
|
||||
const keyInfo = parser.comparedEntityKey(parser.handleEntityTypeByStr(str)) // 校验输入str字段是schema内的字段,并将语句进行规范
|
||||
@@ -181,7 +190,9 @@ export default {
|
||||
const errorList = parser.validateStr(enumKey) // 检查语句是否有错误
|
||||
if (_.isEmpty(errorList)) {
|
||||
// 补全模糊搜索
|
||||
toRaw(this.codeMirror).setValue(parser.handleEntityTypeByStr(str))
|
||||
if (!this.isUnitTesting) {
|
||||
toRaw(this.codeMirror).setValue(parser.handleEntityTypeByStr(str))
|
||||
}
|
||||
// 注:参数str,1.是用户搜索框的内容在补全模糊搜索后的内容;2.部分参数是用户主观可见,但格式不符合接口原则的,如status='Active',接口需要status=0
|
||||
this.$emit('search', { ...parser.parseStr(enumKey), str: parser.handleEntityTypeByStr(str), keywordList: keywordList })
|
||||
} else {
|
||||
@@ -230,7 +241,12 @@ export default {
|
||||
}
|
||||
},
|
||||
addParams (params) {
|
||||
let current = this.codeMirror.getValue()
|
||||
let current = ''
|
||||
if (!this.isUnitTesting) {
|
||||
current = this.codeMirror.getValue()
|
||||
} else {
|
||||
current = this.myUnitTestStr
|
||||
}
|
||||
params.forEach(param => {
|
||||
const column = this.columnList.find(c => c.label === param.column)
|
||||
if (param.operator === 'has') {
|
||||
@@ -239,7 +255,11 @@ export default {
|
||||
current = `${current ? current + ' AND ' : ''}${param.column}${handleOperatorSpace(param.operator)}${this.handleValue(param.value, column, param.operator)}`
|
||||
}
|
||||
})
|
||||
toRaw(this.codeMirror).setValue(current.trim())
|
||||
if (!this.isUnitTesting) {
|
||||
toRaw(this.codeMirror).setValue(current.trim())
|
||||
} else {
|
||||
this.myUnitTestStr = current
|
||||
}
|
||||
},
|
||||
removeParams (params) {
|
||||
let current = this.codeMirror.getValue()
|
||||
@@ -475,7 +495,7 @@ export default {
|
||||
this.initCodeMirror()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
} else if (this.$refs.textSearch) {
|
||||
this.initCodeMirror()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'codemirror/theme/eclipse.css'
|
||||
import 'codemirror/mode/sql/sql'
|
||||
|
||||
import 'codemirror/theme/ambiance.css'
|
||||
import 'codemirror/addon/hint/show-hint'
|
||||
// import 'codemirror/addon/hint/show-hint.js'
|
||||
import 'codemirror/addon/hint/show-hint.css'
|
||||
import 'codemirror/addon/display/placeholder'
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { getSchemaInfo } from '@/utils/timeQueryApi'
|
||||
|
||||
export class Scheme {
|
||||
constructor (context, params, list) {
|
||||
// 先从缓存获取数据
|
||||
@@ -83,12 +81,6 @@ export class Scheme {
|
||||
return result || []
|
||||
}
|
||||
|
||||
async getSchemaDataFromRemote () {
|
||||
const schemaData = await getSchemaInfo(this.queryparams?.logType)
|
||||
this.context.initDataReadyCb && this.context.initDataReadyCb(schemaData || null)
|
||||
return schemaData
|
||||
}
|
||||
|
||||
formatSchemaData (data) {
|
||||
// 格式化 获取的数据
|
||||
const formatedData = {
|
||||
@@ -146,12 +138,6 @@ export class Scheme {
|
||||
callback && callback(this.schemeData)
|
||||
return
|
||||
}
|
||||
this.getSchemaDataFromRemote().then(data => {
|
||||
this.schemeData = this.formatSchemaData(data)
|
||||
// 获取schemaData的时候 查询映射字段
|
||||
// this.getRemoteOptions()
|
||||
callback && callback(this.schemeData)
|
||||
})
|
||||
callback && callback(this.schemeData)
|
||||
return this.schemeData
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user