MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / ApiTest

Function ApiTest

frontend/packages/common/src/components/postcat/ApiTest.tsx:34–289  ·  view source on GitHub ↗
({
  apiRef,
  apiInfo,
  loaded = true
}: {
  apiRef?: React.RefObject<ApiTestApiRef>
  apiInfo: ApiDetail
  loaded?: boolean
})

Source from the content-addressed store, hash-verified

32}
33
34export default function ApiTest({
35 apiRef,
36 apiInfo,
37 loaded = true
38}: {
39 apiRef?: React.RefObject<ApiTestApiRef>
40 apiInfo: ApiDetail
41 loaded?: boolean
42}) {
43 const [uri, setUri] = useState<string>('')
44 const [httpMethod, setHttpMethod] = useState<HTTPMethod>(HTTPMethod.POST)
45 const [testResponse, setTestResponse] = useState<TestResponse | null>(null)
46 // const { apiInfo, loaded } = useContext<Partial<ApiTabContextProps>>(ApiTabContext)
47 const testerApiRef = useRef<ApiRequestTesterApi>(null)
48 const [parent] = useAutoAnimate()
49 // const testApiInfo:ApiDetail = apiInfo
50 const [isLoading, setIsLoading] = useState<boolean>()
51 const [cancel, setCancel] = useState<boolean>()
52
53 // useEffect(() => {
54 // if (testApiInfo) {
55 // const data: SafeAny = testApiInfo
56 // const responseResult = {
57 // report: {
58 // general: {
59 // downloadRate: data.downloadRate,
60 // downloadSize: data.downloadSize,
61 // redirectTimes: data.redirectTimes,
62 // time: data.time,
63 // timingSummary: data.timingSummary
64 // },
65 // request: {
66 // headers: testApiInfo.requestParams.headerParams?.map((item) => ({
67 // value: item.paramAttr.example,
68 // key: item.name
69 // })),
70 // requestType: data.request.contentType,
71 // body: testApiInfo.requestParams.bodyParams,
72 // uri: testApiInfo.uri
73 // },
74 // response: {
75 // headers: data.headers.map((item: SafeAny) => ({ key: item.name, value: item.value })),
76 // body: data.body,
77 // contentType: data.contentType,
78 // httpCode: data.statusCode,
79 // responseType: data.responseType
80 // }
81 // }
82 // } as unknown as TestResponse
83 // setTestResponse(responseResult)
84 // setHttpMethod(testApiInfo.method)
85 // testerApiRef.current?.updateHeaderDataGrid((testApiInfo.requestParams.headerParams as HeaderParamsType[]) || [])
86 // const apiBodyType: TestApiBodyType = testApiInfo.requestParams.bodyParams[0]?.contentType as TestApiBodyType
87 // const contentType = apiBodyType === ApiBodyType.Raw ? 'application/json' : 'application/x-www-form-urlencoded'
88 // testerApiRef.current?.updateRequestBody({
89 // apiBodyType,
90 // contentType: contentType,
91 // data:

Callers

nothing calls this directly

Calls 1

syncUrlAndQueryFunction · 0.90

Tested by

no test coverage detected