refactor(接口测试): 添加断言组件是否启用全局

This commit is contained in:
fit2-zhao 2024-03-13 18:43:21 +08:00 committed by Craftsman
parent d6f93ca8e1
commit 941ebbb7b9
4 changed files with 47 additions and 13 deletions

View File

@ -1,17 +1,30 @@
<template>
<div class="ms-assertion">
<a-dropdown trigger="hover" @select="handleSelect">
<a-button class="w-[84px]" type="outline">
<div class="flex flex-row items-center gap-[8px]">
<icon-plus />
<span>{{ t('ms.assertion.button') }}</span>
</div>
</a-button>
<template #content>
<a-doption v-for="item in assertOptionSource" :key="item.value" :value="item.value">{{ item.label }}</a-doption>
</template>
</a-dropdown>
<div class="mb-[8px] flex items-center justify-between">
<a-dropdown trigger="hover" @select="handleSelect">
<a-button class="w-[84px]" type="outline">
<div class="flex flex-row items-center gap-[8px]">
<icon-plus />
<span>{{ t('ms.assertion.button') }}</span>
</div>
</a-button>
<template #content>
<a-doption v-for="item in assertOptionSource" :key="item.value" :value="item.value">{{
item.label
}}</a-doption>
</template>
</a-dropdown>
<div v-if="props.isDefinition && innerConfig" class="flex items-center">
<a-switch v-model:model-value="innerConfig.enableGlobal" size="small" type="line" />
<div class="ml-[8px] text-[var(--color-text-1)]">{{ t('ms.assertion.openGlobal') }}</div>
<a-tooltip :content="t('ms.assertion.openGlobalTip')" position="left">
<icon-question-circle
class="ml-[4px] text-[var(--color-text-brand)] hover:text-[rgb(var(--primary-5))]"
size="16"
/>
</a-tooltip>
</div>
</div>
<div v-if="showBody" class="ms-assertion-body w-full">
<a-scrollbar
:style="{
@ -114,6 +127,7 @@
<script lang="ts" setup>
import { defineModel } from 'vue';
import { useVModel } from '@vueuse/core';
import { cloneDeep } from 'lodash-es';
import { VueDraggable } from 'vue-draggable-plus';
@ -131,7 +145,7 @@
import { useI18n } from '@/hooks/useI18n';
import { ExecuteConditionProcessor } from '@/models/apiTest/common';
import { ExecuteAssertionConfig , ExecuteConditionProcessor} from '@/models/apiTest/common';
import { RequestConditionScriptLanguage, ResponseAssertionType, ResponseBodyAssertionType } from '@/enums/apiEnum';
import { ExecuteAssertion, MsAssertionItem } from './type';
@ -145,6 +159,19 @@
const focusKey = ref<string>('');
//
const assertions = defineModel<any[]>('params', { default: [] });
const props = defineProps<{
isDefinition?: boolean; //
assertionConfig?: ExecuteAssertionConfig; //
}>();
const emit = defineEmits<{
(e: 'update:assertionConfig', params: ExecuteAssertionConfig): void;
(e: 'change'): void;
}>();
const innerConfig = useVModel(props, 'assertionConfig', emit);
const activeIds = ref('');
// Itemkey
const activeKey = ref<string>('');

View File

@ -5,4 +5,7 @@ export default {
'ms.assertion.document': 'Document',
'ms.assertion.regular': 'Regular',
'ms.assertion.script': 'Script',
'ms.assertion.openGlobal': 'Implement the Global Declaration',
'ms.assertion.openGlobalTip':
'It is enabled by default. If it is disabled, the global assertion will not be executed when running this interface.',
};

View File

@ -22,4 +22,6 @@ export default {
'ms.assertion.typeChecking': '类型校验',
'ms.assertion.addChild': '添加子字段',
'ms.assertion.validateChild': '添加子校验',
'ms.assertion.openGlobal': '启用全局断言',
'ms.assertion.openGlobalTip': '默认开启,关闭则运行该接口时不执行全局断言',
};

View File

@ -245,6 +245,8 @@
<assertion
v-else-if="requestVModel.activeTab === RequestComposition.ASSERTION"
v-model:params="requestVModel.children[0].assertionConfig.assertions"
:is-definition="props.isDefinition"
:assertion-config="requestVModel.children[0].assertionConfig"
/>
<auth
v-else-if="requestVModel.activeTab === RequestComposition.AUTH"