Skip to content

Commit

Permalink
新增后置条件
Browse files Browse the repository at this point in the history
  • Loading branch information
wuranxu committed Dec 19, 2021
1 parent d3eac4c commit 86af445
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 20 deletions.
Binary file removed src/assets/bg7.gif
Binary file not shown.
5 changes: 3 additions & 2 deletions src/components/TestCase/Constructor/ConstructorCopy.jsx
Expand Up @@ -2,7 +2,7 @@ import {Col, Row, TreeSelect} from "antd";
import {connect} from 'umi';
import {useEffect} from "react";

const CopyTreeSelect = ({construct, dispatch}) => {
const CopyTreeSelect = ({construct, dispatch, suffix=true}) => {

const {constructorData, searchConstructor, constructorType} = construct;

Expand All @@ -18,7 +18,8 @@ const CopyTreeSelect = ({construct, dispatch}) => {
dispatch({
type: 'construct/getConstructorTree',
payload: {
constructor_type: constructorType
constructor_type: constructorType,
suffix,
}
})
}
Expand Down
22 changes: 19 additions & 3 deletions src/components/TestCase/ConstructorModal.jsx
Expand Up @@ -13,7 +13,18 @@ import PythonConstructor from "@/components/TestCase/Constructor/PythonConstruct
const {Meta} = Card;
const {Step} = Steps;

const ConstructorModal = ({modal, form, setModal, caseId, dispatch, construct, width, fetchData, record}) => {
const ConstructorModal = ({
modal,
form,
setModal,
caseId,
dispatch,
construct,
width,
fetchData,
record,
suffix = false
}) => {

const {currentStep, totalStep, constructorType, testCaseConstructorData} = construct;

Expand Down Expand Up @@ -76,12 +87,16 @@ const ConstructorModal = ({modal, form, setModal, caseId, dispatch, construct, w
payload: {
...params,
id: record.id,
suffix,
}
})
} else {
result = await dispatch({
type: 'construct/insert',
payload: params
payload: {
...params,
suffix,
}
})
}
if (result) {
Expand Down Expand Up @@ -192,7 +207,8 @@ const ConstructorModal = ({modal, form, setModal, caseId, dispatch, construct, w


return (
<Drawer title="数据构造器" width={width || 1100} visible={modal} onClose={() => setModal(false)} footer={null}>
<Drawer title={suffix ? '后置条件' : '前置条件'} width={width || 1100} visible={modal} onClose={() => setModal(false)}
footer={null}>
<>
<Row>
<Col span={6}/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/TestCase/TestResult.jsx
Expand Up @@ -116,7 +116,7 @@ export default ({response, caseName, width, modal, setModal, single = true}) =>
onClose={() => setModal(false)}>
<Row gutter={[8, 8]}>
{
!single ? <Tabs style={{width: '100%'}}>
!single ? <Tabs style={{width: '100%', minHeight: 460}}>
{
Object.keys(response).map((name, index) => <TabPane tab={name} key={index.toString()}>
<Tabs style={{width: '100%'}} tabPosition="left">
Expand Down Expand Up @@ -212,7 +212,7 @@ export default ({response, caseName, width, modal, setModal, single = true}) =>
</Tabs>
</TabPane>)
}
</Tabs> : <Tabs style={{width: '100%'}} tabPosition="left">
</Tabs> : <Tabs style={{width: '100%', minHeight: 460}} tabPosition="left">
<TabPane tab={<span><IconFont type="icon-yongliliebiao"/>基本信息</span>} key="1">
<Descriptions column={2} bordered size="middle">
<Descriptions.Item label="测试结果">
Expand Down
90 changes: 77 additions & 13 deletions src/pages/ApiTest/TestCaseComponent.jsx
Expand Up @@ -72,7 +72,11 @@ const TestCaseComponent = ({loading, dispatch, user, testcase, gconfig}) => {
const [bodyType, setBodyType] = useState(0);
const [headers, setHeaders] = useState([]);
const [formData, setFormData] = useState([]);
const [suffix, setSuffix] = useState(false);

const getConstructor = sfx => {
return constructors.filter(item => item.suffix === sfx)
}

const fetchTestCaseInfo = () => {
if (case_id) {
Expand Down Expand Up @@ -368,7 +372,7 @@ const TestCaseComponent = ({loading, dispatch, user, testcase, gconfig}) => {
<ConstructorModal width={1100} modal={constructorModal} setModal={e => {
dispatch({type: 'testcase/save', payload: {constructorModal: e}})
}} caseId={case_id} form={constructorForm} record={constructRecord}
fetchData={fetchTestCaseInfo}/>
fetchData={fetchTestCaseInfo} suffix={suffix}/>
{
editing ? <TestCaseEditor directoryId={directory_id} form={form} body={body} setBody={setBody}
headers={headers} setHeaders={setHeaders} onSubmit={onSubmit}/> :
Expand All @@ -393,7 +397,9 @@ const TestCaseComponent = ({loading, dispatch, user, testcase, gconfig}) => {
<Dropdown overlay={menu}>
<Button type="primary" style={{marginLeft: 8, borderRadius: 16}}
loading={loading.effects['testcase/onExecuteTestCase']}
onClick={e => {e.stopPropagation()}}><PlayCircleOutlined/> 运行<DownOutlined/></Button>
onClick={e => {
e.stopPropagation()
}}><PlayCircleOutlined/> 运行<DownOutlined/></Button>
</Dropdown>
</div>}>
<Descriptions size='small' column={4}>
Expand Down Expand Up @@ -430,6 +436,11 @@ const TestCaseComponent = ({loading, dispatch, user, testcase, gconfig}) => {
type: 'testcase/save',
payload: {activeKey: key}
})
if (key === '4') {
setSuffix(true);
} else {
setSuffix(false);
}
if (key === '5' && envList.length > 0) {
dispatch({
type: 'testcase/save',
Expand Down Expand Up @@ -460,11 +471,12 @@ const TestCaseComponent = ({loading, dispatch, user, testcase, gconfig}) => {
</TabPane>
<TabPane key="1"
tab={<Badge size="small" style={{backgroundColor: '#52c41a'}} offset={[11, 6]}
count={constructors.length}><IconFont type="icon-DependencyGraph_16x"/>数据构造器</Badge>}>
count={getConstructor(false).length}><IconFont
type="icon-DependencyGraph_16x"/>前置条件</Badge>}>
{
constructors.length === 0 ?
getConstructor(false).length === 0 ?
<NoRecord height={180}
desc={<div>没有数据构造器, 这不 <a onClick={onCreateConstructor}>添加一个</a>?</div>}/> :
desc={<div>还没有前置条件, 这不 <a onClick={onCreateConstructor}>添加一个</a>?</div>}/> :
<Row gutter={12}>
<Col span={16}>
<Row>
Expand All @@ -474,7 +486,7 @@ const TestCaseComponent = ({loading, dispatch, user, testcase, gconfig}) => {
}} onClick={onCreateConstructor}><PlusOutlined/>添加</Button>
</Col>
</Row>
<SortedTable columns={columns} dataSource={constructors}
<SortedTable columns={columns} dataSource={getConstructor(false)}
setDataSource={
data => {
dispatch({
Expand All @@ -494,12 +506,13 @@ const TestCaseComponent = ({loading, dispatch, user, testcase, gconfig}) => {
<Card style={{height: 400, overflow: 'auto'}} hoverable bordered={false}>
<Timeline>
{
constructors.map((item, index) => item.enable ? <Timeline.Item key={index}>
<div key={index}><Badge count={index + 1} key={index}
style={{backgroundColor: '#a6d3ff'}}/> 名称: {item.type === 0 ?
<a key={item.name}>{item.name}</a> : item.name}</div>
{getDesc(item)}
</Timeline.Item> : null)
getConstructor(false).map((item, index) => item.enable ?
<Timeline.Item key={index}>
<div key={index}><Badge count={index + 1} key={index}
style={{backgroundColor: '#a6d3ff'}}/> 名称: {item.type === 0 ?
<a key={item.name}>{item.name}</a> : item.name}</div>
{getDesc(item)}
</Timeline.Item> : null)
}
</Timeline>
</Card>
Expand All @@ -523,7 +536,58 @@ const TestCaseComponent = ({loading, dispatch, user, testcase, gconfig}) => {
count={asserts.length}><IconFont type="icon-duanyan"/>断言</Badge>}>
<TestCaseAssert asserts={asserts} caseId={case_id}/>
</TabPane>
<TabPane key="4" tab={<span><IconFont type="icon-qingliwuliuliang"/>数据清理器</span>}/>
<TabPane key="4"
tab={<Badge size="small" style={{backgroundColor: '#52c41a'}} offset={[11, 6]}
count={getConstructor(true).length}><IconFont
type="icon-qingliwuliuliang"/>后置条件</Badge>}>
{
getConstructor(true).length === 0 ?
<NoRecord height={180}
desc={<div>还没有后置条件, 这不 <a onClick={onCreateConstructor}>添加一个</a>?</div>}/> :
<Row gutter={12}>
<Col span={16}>
<Row>
<Col span={24}>
<Button type="dashed" block style={{
marginBottom: 16,
}} onClick={onCreateConstructor}><PlusOutlined/>添加</Button>
</Col>
</Row>
<SortedTable columns={columns} dataSource={getConstructor(true)}
setDataSource={
data => {
dispatch({
type: 'testcase/save',
payload: {constructors: data}
})
}}
loading={loading.effects['construct/delete'] || loading.effects['construct/update']}
dragCallback={async newData => {
return await dispatch({
type: 'construct/orderConstructor',
payload: newData.map((v, index) => ({id: v.id, index}))
})
}}/>
</Col>
<Col span={8}>
<Card style={{height: 400, overflow: 'auto'}} hoverable bordered={false}>
<Timeline>
{
getConstructor(true).map((item, index) => item.enable ?
<Timeline.Item key={index}>
<div key={index}><Badge count={index + 1} key={index}
style={{backgroundColor: '#a6d3ff'}}/> 名称: {item.type === 0 ?
<a key={item.name}>{item.name}</a> : item.name}</div>
{getDesc(item)}
</Timeline.Item> : null)
}
</Timeline>
</Card>
</Col>
</Row>

}
</TabPane>
</Tabs>
</Col>
</Row>
Expand Down

0 comments on commit 86af445

Please sign in to comment.