From 70a2117c40433123e79e17a3b479ef9493ddebec Mon Sep 17 00:00:00 2001 From: "rx.wu" Date: Tue, 30 Jan 2024 10:42:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E6=8C=87=E5=90=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/defaultSettings.ts | 4 +- src/components/TestCase/TestResult.jsx | 361 ++++++++++++++++++------- 2 files changed, 259 insertions(+), 106 deletions(-) diff --git a/config/defaultSettings.ts b/config/defaultSettings.ts index a1e15df..9b5014a 100644 --- a/config/defaultSettings.ts +++ b/config/defaultSettings.ts @@ -8,7 +8,6 @@ const Settings: LayoutSettings & { https?: boolean; logo?: string; apiUrl?: string; - wssUrl?: string; } = { navTheme: 'light', // 拂晓蓝 @@ -22,8 +21,7 @@ const Settings: LayoutSettings & { pwa: false, logo: '/logo.svg', iconfontUrl: '//at.alicdn.com/t/font_915840_kom9s5w2t6k.js', - apiUrl: '127.0.0.1:7777', - wssUrl: 'ws://127.0.0.1:7777', + apiUrl: 'api.pity.fun', https: false, }; diff --git a/src/components/TestCase/TestResult.jsx b/src/components/TestCase/TestResult.jsx index 6e0de8b..55fc94e 100755 --- a/src/components/TestCase/TestResult.jsx +++ b/src/components/TestCase/TestResult.jsx @@ -1,20 +1,20 @@ -import {Badge, Descriptions, Drawer, Row, Table, Tabs} from "antd"; -import React, {useEffect, useState} from "react"; -import SyntaxHighlighter from "react-syntax-highlighter"; -import {vs2015} from "react-syntax-highlighter/dist/cjs/styles/hljs"; -import TreeXmind from "@/components/G6/TreeXmind"; -import {queryXmindData} from "@/services/testcase"; -import auth from "@/utils/auth"; -import NoRecord from "@/components/NotFound/NoRecord"; -import {IconFont} from "@/components/Icon/IconFont"; -import JSONAceEditor from "@/components/CodeEditor/AceEditor/JSONAceEditor"; -import PityAceEditor from "@/components/CodeEditor/AceEditor"; +import { Badge, Descriptions, Drawer, Row, Table, Tabs } from 'antd'; +import React, { useEffect, useState } from 'react'; +import SyntaxHighlighter from 'react-syntax-highlighter'; +import { vs2015 } from 'react-syntax-highlighter/dist/cjs/styles/hljs'; +import TreeXmind from '@/components/G6/TreeXmind'; +import { queryXmindData } from '@/services/testcase'; +import auth from '@/utils/auth'; +import NoRecord from '@/components/NotFound/NoRecord'; +import { IconFont } from '@/components/Icon/IconFont'; +import JSONAceEditor from '@/components/CodeEditor/AceEditor/JSONAceEditor'; +import PityAceEditor from '@/components/CodeEditor/AceEditor'; const TabPane = Tabs.TabPane; const STATUS = { - 200: {color: '#67C23A', text: 'OK'}, - 401: {color: '#F56C6C', text: 'unauthorized'}, - 400: {color: '#F56C6C', text: 'Bad Request'}, + 200: { color: '#67C23A', text: 'OK' }, + 401: { color: '#F56C6C', text: 'unauthorized' }, + 400: { color: '#F56C6C', text: 'Bad Request' }, }; const resColumns = [ { @@ -28,24 +28,23 @@ const resColumns = [ key: 'value', }, ]; -export default ({response, caseName, width, modal, setModal, single = true}) => { - +export default ({ response, caseName, width, modal, setModal, single = true }) => { const [xmindData, setXmindData] = useState(null); const [xmindDataList, setXmindDataList] = useState([]); const [graph, setGraph] = useState({}); const [editor, setEditor] = useState(null); const getBrain = async (case_id = response.case_id, single = true) => { - const res = await queryXmindData({case_id}) + const res = await queryXmindData({ case_id }); if (auth.response(res)) { if (single) { - setXmindData(res.data) + setXmindData(res.data); } else { - const temp = Object.keys(response).map(k => res.data) - setXmindDataList(temp) + const temp = Object.keys(response).map((k) => res.data); + setXmindDataList(temp); } } - } + }; const getResponse = async () => { if (single) { @@ -57,14 +56,14 @@ export default ({response, caseName, width, modal, setModal, single = true}) => if (response[key].case_id !== undefined) { await getBrain(response[key].case_id, false); } - return + return; } } - } + }; useEffect(() => { - getResponse() - }, [response]) + getResponse(); + }, [response]); const toTable = (field, resp = response) => { if (resp[field] === null || resp[field] === undefined || resp[field] === '{}') { @@ -81,89 +80,123 @@ export default ({response, caseName, width, modal, setModal, single = true}) => { title: '断言信息', key: 'msg', - dataIndex: 'msg' + dataIndex: 'msg', }, { title: '状态', key: 'status', dataIndex: 'status', - render: text => + render: (text) => ( + + ), }, - ] + ]; const getSource = (res = response) => { if (res.asserts === undefined || !res.asserts) { return []; } - const temp = JSON.parse(res.asserts) + const temp = JSON.parse(res.asserts); const result = []; - Object.keys(temp).forEach(k => { - if (typeof temp[k].msg === "string") { + Object.keys(temp).forEach((k) => { + if (typeof temp[k].msg === 'string') { result.push({ status: temp[k].status, msg: temp[k].msg, - }) + }); } else { - temp[k].msg.forEach(v => { + temp[k].msg.forEach((v) => { result.push({ status: temp[k].status, msg: v, - }) - }) + }); + }); } - }) + }); return result; - } + }; return ( - [{caseName}] 执行详情} width={width || 1000} - open={modal} placement="right" - onClose={() => setModal(false)}> + + [{caseName}] 执行详情 + + } + width={width || 1000} + open={modal} + placement="right" + onClose={() => setModal(false)} + > - { - !single ? - { - Object.keys(response).map((name, index) => - - 基本信息} key="1"> + {!single ? ( + + {Object.keys(response).map((name, index) => ( + + + + + 基本信息 + + } + key="1" + > - + {response[name].request_method} - - {response[name].status_code}{' '} - {STATUS[response[name].status_code] ? STATUS[response[name].status_code].text : ''} - + + {response[name].status_code}{' '} + {STATUS[response[name].status_code] + ? STATUS[response[name].status_code].text + : ''} + - - {response[name].cost} - + + {response[name].cost} + {response[name].url} - { - response[name].request_data ? + {response[name].request_data ? ( + {response[name].request_data} - : - } + + ) : ( + + )} - 断言} key="3"> + + + 断言 + + } + key="3" + > pagination={false} /> - 执行日志} key="2"> + + + 执行日志 + + } + key="2" + > {/* */} {/**/} - Request Headers} key="5"> + + + Request Headers + + } + key="5" + >
pagination={false} /> - Cookie} key="6"> + + + Cookie + + } + key="6" + >
pagination={false} /> - Response Headers} key="7"> + + + Response Headers + + } + key="7" + >
pagination={false} /> - Response} key="4"> + + + Response + + } + key="4" + > - 脑图} key="8"> + + + 脑图 + + } + key="8" + >
- +
-
) - } - : - 基本信息} key="1"> + + ))} + + ) : ( + + + + 基本信息 + + } + key="1" + > - - - - {response.request_method} + + {response.request_method} - - {response.cost} + + {response.cost} {response.url} - { - response.request_data ? + {response.request_data ? ( + {response.request_data} - : - } + + ) : ( + + )} - 断言} key="3"> + + + 断言 + + } + key="3" + >
pagination={false} /> - 执行日志} key="2"> + + + 执行日志 + + } + key="2" + > {/* */} {/**/} - Request Headers} key="5"> + + + Request Headers + + } + key="5" + >
pagination={false} /> - Cookie} key="6"> + + + Cookie + + } + key="6" + >
pagination={false} /> - Response Headers} key="7"> + + + Response Headers + + } + key="7" + >
pagination={false} /> - Response} key="4"> + + + Response + + } + key="4" + > - 脑图} key="8"> + + + 脑图 + + } + key="8" + >
- +
- } + )} - ) - -} + ); +};