dsh-postapi 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +139 -2
- package/cordis.patch.yml +3 -0
- package/dist/client.js +5651 -0
- package/docs/DETAIL.md +27 -0
- package/docs/apifox-design-spec.md +101 -0
- package/docs/apifox-research/analysis.md +254 -0
- package/docs/apifox-ui-delivery.md +150 -0
- package/docs/apifox-visual-parity-spec.md +353 -0
- package/docs/feature-matrix.md +112 -0
- package/docs/flow-reference/sequence-reference.html +163 -0
- package/docs/interface-contract-v2.md +175 -0
- package/docs/interface-contract.md +105 -0
- package/docs/nav-layout-v2-spec.md +107 -0
- package/docs/preview.svg +9 -0
- package/docs/probe-client.legacy.js +31 -0
- package/docs/rootcause-sidebar-vanish.md +95 -0
- package/docs/rootcause.md +86 -0
- package/docs/sidebar-notes.md +153 -0
- package/docs/ui-audit.md +197 -0
- package/docs/ui-notes.md +98 -0
- package/docs/v2-delivery.md +99 -0
- package/icon.svg +4 -0
- package/index.js +5 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +73 -4
- package/src/client/index.js +132 -0
- package/src/client/jsx-shim.js +9 -0
- package/src/client/pages/__tests__/heights.test.js +135 -0
- package/src/client/pages/components/AssertTable.jsx +122 -0
- package/src/client/pages/components/BodyEditor.jsx +91 -0
- package/src/client/pages/components/EmptyState.jsx +52 -0
- package/src/client/pages/components/FolderTree.jsx +109 -0
- package/src/client/pages/components/JsonEditor.jsx +45 -0
- package/src/client/pages/components/ParamTable.jsx +226 -0
- package/src/client/pages/components/ResponsePanel.jsx +278 -0
- package/src/client/pages/components/ScriptPanel.jsx +99 -0
- package/src/client/pages/components/StatusPill.jsx +35 -0
- package/src/client/pages/components/__tests__/apifox-ui.test.js +291 -0
- package/src/client/pages/components/__tests__/pages-a.test.js +392 -0
- package/src/client/pages/components/__tests__/tree.test.js +379 -0
- package/src/client/pages/components/headerPresets.js +63 -0
- package/src/client/pages/debug.jsx +576 -0
- package/src/client/pages/design-tokens.css +2604 -0
- package/src/client/pages/doc.jsx +552 -0
- package/src/client/pages/env.jsx +378 -0
- package/src/client/pages/flow.jsx +349 -0
- package/src/client/pages/history.jsx +238 -0
- package/src/client/pages/import.jsx +396 -0
- package/src/client/pages/mock.jsx +316 -0
- package/src/client/pages/overview.jsx +348 -0
- package/src/client/pages/schema.jsx +317 -0
- package/src/client/pages/search.jsx +216 -0
- package/src/client/pages/sequence.jsx +344 -0
- package/src/client/pages/settings.jsx +205 -0
- package/src/client/pages/test.jsx +470 -0
- package/src/client/pages/theme.js +27 -0
- package/src/client/pages-entry.js +20 -0
- package/src/client/shell/ApiTitle.js +19 -0
- package/src/client/shell/Body.js +492 -0
- package/src/client/shell/definition.js +57 -0
- package/src/client/shell/locales.js +185 -0
- package/src/client/shell/menu.js +174 -0
- package/src/client/shell/registry.js +530 -0
- package/src/host/bridge.js +407 -0
- package/src/host/codegen.js +356 -0
- package/src/host/import-export.js +1044 -0
- package/src/host/index.js +102 -0
- package/src/host/mock-server.js +303 -0
- package/src/host/request.js +336 -0
- package/src/host/script-sandbox.js +272 -0
- package/src/host/storage.js +803 -0
- package/src/host/test-runner.js +126 -0
- package/src/host/variables.js +108 -0
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
// test.jsx — 自动化测试页(Apifox 工作台:左用例/场景树 + 右断言表 + 运行结果行)
|
|
2
|
+
// 自注册:模块求值期入队 __postapiQueue
|
|
3
|
+
// 数据:api.storage.getProject / saveProjectSettings(契约 §3 无 testCase 专用 CRUD,
|
|
4
|
+
// 用例与场景存 project.settings.testCases / testScenarios;读取兼容 project 顶层同名键)
|
|
5
|
+
// 运行:api.test.runCase / api.test.runScenario(契约 §5 POST /test/runCase / runScenario)
|
|
6
|
+
// 视觉基线:docs/apifox-design-spec.md —— .pp-tree-row / .pp-table / .pp-result-row / .pp-pill
|
|
7
|
+
import React, { useEffect, useRef, useState } from 'react'
|
|
8
|
+
import { applyTheme } from './theme.js'
|
|
9
|
+
import { EmptyState } from './components/EmptyState.jsx'
|
|
10
|
+
|
|
11
|
+
;(window.__postapiQueue = window.__postapiQueue || []).push(['test', TestPage]) // 注册表就绪前入队
|
|
12
|
+
|
|
13
|
+
const OPS = ['eq', 'neq', 'gt', 'lt', 'contains', 'notContains', 'exists', 'notExists', 'regex']
|
|
14
|
+
const SOURCES = ['status', 'body', 'header', 'time']
|
|
15
|
+
|
|
16
|
+
const MOCK_CASES = [
|
|
17
|
+
{
|
|
18
|
+
id: 'tc_1001', name: '订单列表返回 200', endpointId: 'ep_1001',
|
|
19
|
+
assertions: [{ source: 'status', path: '', op: 'eq', value: '200', message: '状态码应为 200' }],
|
|
20
|
+
extractors: [], lastResult: null,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'tc_1002', name: '创建订单返回 orderId', endpointId: 'ep_1002',
|
|
24
|
+
assertions: [{ source: 'body', path: 'data.orderId', op: 'exists', value: '', message: 'body 应含 orderId' }],
|
|
25
|
+
extractors: [{ name: 'orderId', path: 'data.orderId' }], lastResult: null,
|
|
26
|
+
},
|
|
27
|
+
]
|
|
28
|
+
const MOCK_SCENARIOS = [
|
|
29
|
+
{
|
|
30
|
+
id: 'ts_1001', name: '下单主流程', lastRun: null,
|
|
31
|
+
steps: [
|
|
32
|
+
{ id: 'stp_01', name: '创建订单', endpointId: 'ep_1002', override: {}, extract: [{ name: 'orderId', path: 'data.orderId' }] },
|
|
33
|
+
{ id: 'stp_02', name: '查询订单', endpointId: 'ep_1001', override: {}, extract: [] },
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
/** 结果汇总:passed 计数 + 失败明细(runCase 用 results、runScenario 用 steps)。 */
|
|
39
|
+
export function summarizeResult(res) {
|
|
40
|
+
const results = res && Array.isArray(res.results) ? res.results : []
|
|
41
|
+
const steps = res && Array.isArray(res.steps) ? res.steps : []
|
|
42
|
+
const rows = results.length > 0 ? results : steps
|
|
43
|
+
const passedCount = rows.filter((r) => r && r.passed === true).length
|
|
44
|
+
return {
|
|
45
|
+
passed: res && res.passed !== undefined ? res.passed === true : passedCount === rows.length && rows.length > 0,
|
|
46
|
+
total: rows.length,
|
|
47
|
+
passedCount,
|
|
48
|
+
failedCount: rows.length - passedCount,
|
|
49
|
+
durationMs: res && res.durationMs !== undefined ? res.durationMs : 0,
|
|
50
|
+
error: (res && res.error) || '',
|
|
51
|
+
rows,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 断言列表规整:补齐 source/path/op/value/message,非法项丢弃。 */
|
|
56
|
+
export function normalizeAssertions(list) {
|
|
57
|
+
return (Array.isArray(list) ? list : [])
|
|
58
|
+
.filter((a) => a && typeof a === 'object')
|
|
59
|
+
.map((a) => ({
|
|
60
|
+
source: SOURCES.includes(a.source) ? a.source : 'status',
|
|
61
|
+
path: String(a.path || ''),
|
|
62
|
+
op: OPS.includes(a.op) ? a.op : 'eq',
|
|
63
|
+
value: String(a.value === undefined || a.value === null ? '' : a.value),
|
|
64
|
+
message: String(a.message || ''),
|
|
65
|
+
}))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 从项目对象取用例/场景:顶层优先,回落 settings 子键(落盘通道)。 */
|
|
69
|
+
export function casesOf(project) {
|
|
70
|
+
const p = project && typeof project === 'object' ? project : {}
|
|
71
|
+
const settings = p.settings && typeof p.settings === 'object' ? p.settings : {}
|
|
72
|
+
const src = Array.isArray(p.testCases) ? p.testCases : (Array.isArray(settings.testCases) ? settings.testCases : [])
|
|
73
|
+
return src.filter((c) => c && typeof c === 'object')
|
|
74
|
+
}
|
|
75
|
+
export function scenariosOf(project) {
|
|
76
|
+
const p = project && typeof project === 'object' ? project : {}
|
|
77
|
+
const settings = p.settings && typeof p.settings === 'object' ? p.settings : {}
|
|
78
|
+
const src = Array.isArray(p.testScenarios) ? p.testScenarios : (Array.isArray(settings.testScenarios) ? settings.testScenarios : [])
|
|
79
|
+
return src.filter((s) => s && typeof s === 'object')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function errText(err) {
|
|
83
|
+
return err && err.message ? err.message : String(err)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function TestPage(props) {
|
|
87
|
+
const rootRef = useRef(null)
|
|
88
|
+
const api = (props && props.api) || (typeof window !== 'undefined' ? window.__postapiApi : undefined)
|
|
89
|
+
const storage = api && api.storage
|
|
90
|
+
const [projects, setProjects] = useState([{ id: 'proj_demo01', name: '订单中心' }])
|
|
91
|
+
const [projectId, setProjectId] = useState('proj_demo01')
|
|
92
|
+
const [project, setProject] = useState({ endpoints: [] })
|
|
93
|
+
const [cases, setCases] = useState(MOCK_CASES)
|
|
94
|
+
const [scenarios, setScenarios] = useState(MOCK_SCENARIOS)
|
|
95
|
+
const [isMock, setIsMock] = useState(true)
|
|
96
|
+
const [error, setError] = useState('')
|
|
97
|
+
const [notice, setNotice] = useState('')
|
|
98
|
+
const [tab, setTab] = useState('cases')
|
|
99
|
+
const [activeCaseId, setActiveCaseId] = useState(MOCK_CASES[0].id)
|
|
100
|
+
const [activeScenarioId, setActiveScenarioId] = useState(MOCK_SCENARIOS[0].id)
|
|
101
|
+
const [result, setResult] = useState(null)
|
|
102
|
+
const [running, setRunning] = useState(false)
|
|
103
|
+
|
|
104
|
+
useEffect(() => applyTheme(rootRef.current), [])
|
|
105
|
+
|
|
106
|
+
const loadProject = async (id) => {
|
|
107
|
+
if (!storage || typeof storage.getProject !== 'function') {
|
|
108
|
+
setIsMock(true)
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const loaded = await storage.getProject(id)
|
|
113
|
+
if (loaded) {
|
|
114
|
+
setProject(loaded)
|
|
115
|
+
setCases(casesOf(loaded))
|
|
116
|
+
setScenarios(scenariosOf(loaded))
|
|
117
|
+
setIsMock(false)
|
|
118
|
+
}
|
|
119
|
+
} catch (err) {
|
|
120
|
+
setError('加载项目失败:' + errText(err))
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
const boot = async () => {
|
|
126
|
+
if (storage && typeof storage.listProjects === 'function') {
|
|
127
|
+
try {
|
|
128
|
+
const list = await storage.listProjects()
|
|
129
|
+
if (Array.isArray(list) && list.length > 0) {
|
|
130
|
+
setProjects(list)
|
|
131
|
+
setProjectId(list[0].id)
|
|
132
|
+
await loadProject(list[0].id)
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
setError('加载项目列表失败:' + errText(err))
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
setIsMock(true)
|
|
140
|
+
}
|
|
141
|
+
boot()
|
|
142
|
+
}, [])
|
|
143
|
+
|
|
144
|
+
const endpoints = Array.isArray(project.endpoints) ? project.endpoints : []
|
|
145
|
+
const activeCase = cases.find((c) => c.id === activeCaseId) || null
|
|
146
|
+
const activeScenario = scenarios.find((s) => s.id === activeScenarioId) || null
|
|
147
|
+
|
|
148
|
+
const patchCase = (patch) => {
|
|
149
|
+
setCases(cases.map((c) => (c.id === activeCaseId ? { ...c, ...patch } : c)))
|
|
150
|
+
setNotice('')
|
|
151
|
+
}
|
|
152
|
+
const patchAssertion = (i, patch) => {
|
|
153
|
+
const next = normalizeAssertions(activeCase && activeCase.assertions)
|
|
154
|
+
next[i] = { ...next[i], ...patch }
|
|
155
|
+
patchCase({ assertions: next })
|
|
156
|
+
}
|
|
157
|
+
const addAssertion = () => patchCase({
|
|
158
|
+
assertions: normalizeAssertions(activeCase && activeCase.assertions)
|
|
159
|
+
.concat([{ source: 'status', path: '', op: 'eq', value: '', message: '' }]),
|
|
160
|
+
})
|
|
161
|
+
const removeAssertion = (i) => patchCase({
|
|
162
|
+
assertions: normalizeAssertions(activeCase && activeCase.assertions).filter((_, idx) => idx !== i),
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const patchScenario = (patch) => {
|
|
166
|
+
setScenarios(scenarios.map((s) => (s.id === activeScenarioId ? { ...s, ...patch } : s)))
|
|
167
|
+
setNotice('')
|
|
168
|
+
}
|
|
169
|
+
const patchStep = (i, patch) => {
|
|
170
|
+
const steps = (activeScenario && Array.isArray(activeScenario.steps) ? activeScenario.steps : []).slice()
|
|
171
|
+
steps[i] = { ...steps[i], ...patch }
|
|
172
|
+
patchScenario({ steps })
|
|
173
|
+
}
|
|
174
|
+
const moveStep = (i, dir) => {
|
|
175
|
+
const steps = (activeScenario && Array.isArray(activeScenario.steps) ? activeScenario.steps : []).slice()
|
|
176
|
+
const j = i + dir
|
|
177
|
+
if (j < 0 || j >= steps.length) return
|
|
178
|
+
const tmp = steps[i]
|
|
179
|
+
steps[i] = steps[j]
|
|
180
|
+
steps[j] = tmp
|
|
181
|
+
patchScenario({ steps })
|
|
182
|
+
}
|
|
183
|
+
const addStep = () => {
|
|
184
|
+
const steps = (activeScenario && Array.isArray(activeScenario.steps) ? activeScenario.steps : []).concat([
|
|
185
|
+
{ id: 'stp_' + Date.now().toString(36), name: '新步骤', endpointId: (endpoints[0] && endpoints[0].id) || '', override: {}, extract: [] },
|
|
186
|
+
])
|
|
187
|
+
patchScenario({ steps })
|
|
188
|
+
}
|
|
189
|
+
const removeStep = (i) => {
|
|
190
|
+
const steps = (activeScenario && Array.isArray(activeScenario.steps) ? activeScenario.steps : []).filter((_, idx) => idx !== i)
|
|
191
|
+
patchScenario({ steps })
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const persist = async () => {
|
|
195
|
+
if (!storage || typeof storage.saveProjectSettings !== 'function') {
|
|
196
|
+
setError('当前桥未提供持久化入口(saveProjectSettings),用例与场景仅停留在页面内')
|
|
197
|
+
return false
|
|
198
|
+
}
|
|
199
|
+
setError('')
|
|
200
|
+
try {
|
|
201
|
+
// saveProjectSettings 为局部合并,写两个子键不会冲掉 mockPort/proxyUrl 等既有设置。
|
|
202
|
+
await storage.saveProjectSettings(projectId, {
|
|
203
|
+
...(project.settings || {}),
|
|
204
|
+
testCases: cases,
|
|
205
|
+
testScenarios: scenarios,
|
|
206
|
+
})
|
|
207
|
+
setNotice('已保存用例与场景(落在 project.settings.testCases / testScenarios)')
|
|
208
|
+
return true
|
|
209
|
+
} catch (err) {
|
|
210
|
+
setError('保存用例与场景失败:' + errText(err))
|
|
211
|
+
return false
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const runCase = async () => {
|
|
216
|
+
if (!activeCase) return
|
|
217
|
+
if (!api || !api.test || typeof api.test.runCase !== 'function') {
|
|
218
|
+
setError('当前桥未提供 api.test.runCase(契约 §5 POST /test/runCase)')
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
setRunning(true)
|
|
222
|
+
setError('')
|
|
223
|
+
setResult(null)
|
|
224
|
+
try {
|
|
225
|
+
const res = await api.test.runCase(projectId, activeCase.id)
|
|
226
|
+
setResult({ kind: 'case', name: activeCase.name, ...summarizeResult(res) })
|
|
227
|
+
} catch (err) {
|
|
228
|
+
setError('运行用例失败:' + errText(err))
|
|
229
|
+
} finally {
|
|
230
|
+
setRunning(false)
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const runScenario = async () => {
|
|
235
|
+
if (!activeScenario) return
|
|
236
|
+
if (!api || !api.test || typeof api.test.runScenario !== 'function') {
|
|
237
|
+
setError('当前桥未提供 api.test.runScenario(契约 §5 POST /test/runScenario)')
|
|
238
|
+
return
|
|
239
|
+
}
|
|
240
|
+
setRunning(true)
|
|
241
|
+
setError('')
|
|
242
|
+
setResult(null)
|
|
243
|
+
try {
|
|
244
|
+
const res = await api.test.runScenario(projectId, activeScenario.id)
|
|
245
|
+
setResult({ kind: 'scenario', name: activeScenario.name, ...summarizeResult(res) })
|
|
246
|
+
} catch (err) {
|
|
247
|
+
setError('运行场景失败:' + errText(err))
|
|
248
|
+
} finally {
|
|
249
|
+
setRunning(false)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const caseAssertions = normalizeAssertions(activeCase && activeCase.assertions)
|
|
254
|
+
|
|
255
|
+
// 运行结果:汇总行用 .pp-pill 三档胶囊,明细行用 .pp-result-row
|
|
256
|
+
const resultPanel = (emptyHint) => (
|
|
257
|
+
<div className="pp-pane">
|
|
258
|
+
<div className="pp-card-title">运行结果</div>
|
|
259
|
+
{result ? (
|
|
260
|
+
<div>
|
|
261
|
+
<div className="pp-toolbar-inline">
|
|
262
|
+
<span className={result.passed ? 'pp-pill pp-pill-ok' : 'pp-pill pp-pill-bad'}>
|
|
263
|
+
{result.passed ? '通过' : '失败'}
|
|
264
|
+
</span>
|
|
265
|
+
<span className="pp-meta">{result.passedCount}/{result.total}</span>
|
|
266
|
+
<span className="pp-meta">{result.durationMs} ms</span>
|
|
267
|
+
</div>
|
|
268
|
+
{result.error ? <p className="pp-error-text">{result.error}</p> : null}
|
|
269
|
+
<div className="pp-list" style={{ marginTop: 'var(--sp-2)' }}>
|
|
270
|
+
{result.rows.map((r, i) => (
|
|
271
|
+
<div key={i} className="pp-result-row">
|
|
272
|
+
<span className="pp-ellipsis">{r.name || r.id || '-'}</span>
|
|
273
|
+
<span className={r.passed ? 'pp-pill pp-pill-ok' : 'pp-pill pp-pill-bad'} style={{ marginLeft: 'auto' }}>
|
|
274
|
+
{r.passed ? '通过' : '失败'}
|
|
275
|
+
</span>
|
|
276
|
+
<span className="pp-meta pp-ellipsis">{r.error || '-'}</span>
|
|
277
|
+
</div>
|
|
278
|
+
))}
|
|
279
|
+
{result.rows.length === 0 ? <div className="pp-result-row pp-meta">无断言结果</div> : null}
|
|
280
|
+
</div>
|
|
281
|
+
</div>
|
|
282
|
+
) : <EmptyState text={emptyHint} />}
|
|
283
|
+
</div>
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
return (
|
|
287
|
+
<div className="pp-scope pp-page" data-page="test" ref={rootRef}>
|
|
288
|
+
<div className="pp-overview-head">
|
|
289
|
+
<span className="pp-overview-title">自动化测试</span>
|
|
290
|
+
<div className="pp-overview-actions">
|
|
291
|
+
<label className="pp-meta">项目</label>
|
|
292
|
+
<select className="pp-select" value={projectId}
|
|
293
|
+
onChange={(e) => { setProjectId(e.target.value); loadProject(e.target.value) }}>
|
|
294
|
+
{projects.map((p) => <option key={p.id} value={p.id}>{p.name || p.id}</option>)}
|
|
295
|
+
</select>
|
|
296
|
+
<button className="pp-btn" onClick={persist}>保存用例与场景</button>
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
<div className="pp-overview-content">
|
|
300
|
+
<div className="pp-toolbar">
|
|
301
|
+
<span className="pp-meta">
|
|
302
|
+
{isMock
|
|
303
|
+
? '示例数据 — api.storage 不可用,以下为文件内 mock'
|
|
304
|
+
: '数据来源:api.storage.getProject(用例与场景存 project.settings.testCases / testScenarios);运行走 api.test.runCase / runScenario'}
|
|
305
|
+
</span>
|
|
306
|
+
</div>
|
|
307
|
+
{error ? <p className="pp-error-text">{error}</p> : null}
|
|
308
|
+
{notice ? <p className="pp-muted">{notice}</p> : null}
|
|
309
|
+
|
|
310
|
+
<div className="pp-tabs">
|
|
311
|
+
<button className="pp-tab" data-active={tab === 'cases' ? 'true' : 'false'} onClick={() => setTab('cases')}>测试用例</button>
|
|
312
|
+
<button className="pp-tab" data-active={tab === 'scenarios' ? 'true' : 'false'} onClick={() => setTab('scenarios')}>测试场景</button>
|
|
313
|
+
</div>
|
|
314
|
+
|
|
315
|
+
{tab === 'cases' ? (
|
|
316
|
+
<div className="pp-debug-layout" style={{ marginTop: 'var(--sp-3)' }}>
|
|
317
|
+
<div className="pp-pane">
|
|
318
|
+
<div className="pp-card-title">用例</div>
|
|
319
|
+
<div className="pp-tree">
|
|
320
|
+
{cases.map((c) => (
|
|
321
|
+
<div key={c.id} className="pp-tree-row" data-active={c.id === activeCaseId ? 'true' : 'false'}
|
|
322
|
+
onClick={() => { setActiveCaseId(c.id); setResult(null); setError('') }}>
|
|
323
|
+
<span className="pp-ellipsis">{c.name || c.id}</span>
|
|
324
|
+
</div>
|
|
325
|
+
))}
|
|
326
|
+
</div>
|
|
327
|
+
{cases.length === 0 ? (
|
|
328
|
+
<EmptyState text="暂无用例" hint="在调试页保存接口后,点「保存用例与场景」新建" />
|
|
329
|
+
) : null}
|
|
330
|
+
</div>
|
|
331
|
+
<div className="pp-pane">
|
|
332
|
+
<div className="pp-card-title">断言</div>
|
|
333
|
+
{activeCase ? (
|
|
334
|
+
<div>
|
|
335
|
+
<div className="pp-form-grid" style={{ marginBottom: 'var(--sp-3)' }}>
|
|
336
|
+
<label className="pp-form-label">名称</label>
|
|
337
|
+
<input className="pp-input" value={activeCase.name || ''}
|
|
338
|
+
onChange={(e) => patchCase({ name: e.target.value })} />
|
|
339
|
+
<label className="pp-form-label">接口</label>
|
|
340
|
+
<select className="pp-select" value={activeCase.endpointId || ''}
|
|
341
|
+
onChange={(e) => patchCase({ endpointId: e.target.value })}>
|
|
342
|
+
<option value="">(未绑定)</option>
|
|
343
|
+
{endpoints.map((ep) => <option key={ep.id} value={ep.id}>{ep.method} {ep.url}</option>)}
|
|
344
|
+
</select>
|
|
345
|
+
</div>
|
|
346
|
+
<div className="pp-table-wrap">
|
|
347
|
+
<table className="pp-table pp-table-wide">
|
|
348
|
+
<thead>
|
|
349
|
+
<tr>
|
|
350
|
+
<th style={{ width: '90px' }}>来源</th>
|
|
351
|
+
<th>路径</th>
|
|
352
|
+
<th style={{ width: '110px' }}>操作</th>
|
|
353
|
+
<th>期望值</th>
|
|
354
|
+
<th>说明</th>
|
|
355
|
+
<th style={{ width: '70px' }}>操作</th>
|
|
356
|
+
</tr>
|
|
357
|
+
</thead>
|
|
358
|
+
<tbody>
|
|
359
|
+
{caseAssertions.map((a, i) => (
|
|
360
|
+
<tr key={i}>
|
|
361
|
+
<td>
|
|
362
|
+
<select className="pp-select pp-input-sm" value={a.source} onChange={(e) => patchAssertion(i, { source: e.target.value })}>
|
|
363
|
+
{SOURCES.map((s) => <option key={s} value={s}>{s}</option>)}
|
|
364
|
+
</select>
|
|
365
|
+
</td>
|
|
366
|
+
<td><input className="pp-input pp-input-sm pp-input-mono" style={{ width: '100%' }} value={a.path}
|
|
367
|
+
onChange={(e) => patchAssertion(i, { path: e.target.value })} /></td>
|
|
368
|
+
<td>
|
|
369
|
+
<select className="pp-select pp-input-sm" value={a.op} onChange={(e) => patchAssertion(i, { op: e.target.value })}>
|
|
370
|
+
{OPS.map((o) => <option key={o} value={o}>{o}</option>)}
|
|
371
|
+
</select>
|
|
372
|
+
</td>
|
|
373
|
+
<td><input className="pp-input pp-input-sm pp-input-mono" style={{ width: '100%' }} value={a.value}
|
|
374
|
+
onChange={(e) => patchAssertion(i, { value: e.target.value })} /></td>
|
|
375
|
+
<td><input className="pp-input pp-input-sm" style={{ width: '100%' }} value={a.message}
|
|
376
|
+
onChange={(e) => patchAssertion(i, { message: e.target.value })} /></td>
|
|
377
|
+
<td><button className="pp-btn pp-btn-sm pp-btn-danger" onClick={() => removeAssertion(i)}>删除</button></td>
|
|
378
|
+
</tr>
|
|
379
|
+
))}
|
|
380
|
+
{caseAssertions.length === 0 ? <tr><td colSpan={6} className="pp-muted">暂无断言</td></tr> : null}
|
|
381
|
+
</tbody>
|
|
382
|
+
</table>
|
|
383
|
+
</div>
|
|
384
|
+
<div className="pp-toolbar-inline" style={{ marginTop: 'var(--sp-3)' }}>
|
|
385
|
+
<button className="pp-btn" onClick={addAssertion}>新增断言</button>
|
|
386
|
+
<button className="pp-btn pp-btn-primary" onClick={runCase} disabled={running}>运行用例</button>
|
|
387
|
+
</div>
|
|
388
|
+
</div>
|
|
389
|
+
) : <EmptyState text="选择一个用例" hint="选中后可编辑断言并运行" />}
|
|
390
|
+
</div>
|
|
391
|
+
{resultPanel('尚未运行')}
|
|
392
|
+
</div>
|
|
393
|
+
) : (
|
|
394
|
+
<div className="pp-debug-layout" style={{ marginTop: 'var(--sp-3)' }}>
|
|
395
|
+
<div className="pp-pane">
|
|
396
|
+
<div className="pp-card-title">场景</div>
|
|
397
|
+
<div className="pp-tree">
|
|
398
|
+
{scenarios.map((s) => (
|
|
399
|
+
<div key={s.id} className="pp-tree-row" data-active={s.id === activeScenarioId ? 'true' : 'false'}
|
|
400
|
+
onClick={() => { setActiveScenarioId(s.id); setResult(null); setError('') }}>
|
|
401
|
+
<span className="pp-ellipsis">{s.name || s.id}</span>
|
|
402
|
+
<span className="pp-tree-row-count">{(s.steps || []).length}</span>
|
|
403
|
+
</div>
|
|
404
|
+
))}
|
|
405
|
+
</div>
|
|
406
|
+
{scenarios.length === 0 ? <EmptyState text="暂无场景" hint="点「保存用例与场景」新建场景" /> : null}
|
|
407
|
+
</div>
|
|
408
|
+
<div className="pp-pane">
|
|
409
|
+
<div className="pp-card-title">步骤编排</div>
|
|
410
|
+
{activeScenario ? (
|
|
411
|
+
<div>
|
|
412
|
+
<div className="pp-form-grid" style={{ marginBottom: 'var(--sp-3)' }}>
|
|
413
|
+
<label className="pp-form-label">场景名</label>
|
|
414
|
+
<input className="pp-input" value={activeScenario.name || ''}
|
|
415
|
+
onChange={(e) => patchScenario({ name: e.target.value })} />
|
|
416
|
+
</div>
|
|
417
|
+
<div className="pp-table-wrap">
|
|
418
|
+
<table className="pp-table pp-table-wide">
|
|
419
|
+
<thead>
|
|
420
|
+
<tr>
|
|
421
|
+
<th style={{ width: '40px' }}>#</th>
|
|
422
|
+
<th>步骤名</th>
|
|
423
|
+
<th>接口</th>
|
|
424
|
+
<th style={{ width: '140px' }}>操作</th>
|
|
425
|
+
</tr>
|
|
426
|
+
</thead>
|
|
427
|
+
<tbody>
|
|
428
|
+
{(activeScenario.steps || []).map((s, i) => (
|
|
429
|
+
<tr key={s.id || i}>
|
|
430
|
+
<td className="pp-meta">{i + 1}</td>
|
|
431
|
+
<td><input className="pp-input pp-input-sm" style={{ width: '100%' }} value={s.name || ''}
|
|
432
|
+
onChange={(e) => patchStep(i, { name: e.target.value })} /></td>
|
|
433
|
+
<td>
|
|
434
|
+
<select className="pp-select pp-input-sm" style={{ width: '100%' }} value={s.endpointId || ''}
|
|
435
|
+
onChange={(e) => patchStep(i, { endpointId: e.target.value })}>
|
|
436
|
+
<option value="">(未绑定)</option>
|
|
437
|
+
{endpoints.map((ep) => <option key={ep.id} value={ep.id}>{ep.method} {ep.url}</option>)}
|
|
438
|
+
</select>
|
|
439
|
+
{s.endpointId ? (
|
|
440
|
+
<span className="pp-method" data-method={(endpoints.find((ep) => ep.id === s.endpointId) || {}).method || 'GET'}>
|
|
441
|
+
{(endpoints.find((ep) => ep.id === s.endpointId) || {}).method || 'GET'}
|
|
442
|
+
</span>
|
|
443
|
+
) : null}
|
|
444
|
+
</td>
|
|
445
|
+
<td>
|
|
446
|
+
<button className="pp-btn pp-btn-sm" onClick={() => moveStep(i, -1)} title="上移">↑</button>{' '}
|
|
447
|
+
<button className="pp-btn pp-btn-sm" onClick={() => moveStep(i, 1)} title="下移">↓</button>{' '}
|
|
448
|
+
<button className="pp-btn pp-btn-sm pp-btn-danger" onClick={() => removeStep(i)} title="删除">×</button>
|
|
449
|
+
</td>
|
|
450
|
+
</tr>
|
|
451
|
+
))}
|
|
452
|
+
{(activeScenario.steps || []).length === 0 ? <tr><td colSpan={4} className="pp-muted">暂无步骤</td></tr> : null}
|
|
453
|
+
</tbody>
|
|
454
|
+
</table>
|
|
455
|
+
</div>
|
|
456
|
+
<div className="pp-toolbar-inline" style={{ marginTop: 'var(--sp-3)' }}>
|
|
457
|
+
<button className="pp-btn" onClick={addStep}>添加步骤</button>
|
|
458
|
+
<button className="pp-btn pp-btn-primary" onClick={runScenario} disabled={running}>运行场景</button>
|
|
459
|
+
</div>
|
|
460
|
+
</div>
|
|
461
|
+
) : <EmptyState text="选择一个场景" hint="选中后可编排步骤并运行" />}
|
|
462
|
+
</div>
|
|
463
|
+
{resultPanel('尚未运行')}
|
|
464
|
+
</div>
|
|
465
|
+
)}
|
|
466
|
+
|
|
467
|
+
</div>
|
|
468
|
+
</div>
|
|
469
|
+
)
|
|
470
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// theme.js — 主题/语言本地草稿(host face 未定义 settings 存储,暂走 localStorage)
|
|
2
|
+
const THEME_KEY = 'postapi.settings.theme'
|
|
3
|
+
const LOCALE_KEY = 'postapi.settings.locale'
|
|
4
|
+
|
|
5
|
+
export function readTheme() {
|
|
6
|
+
try {
|
|
7
|
+
return typeof localStorage !== 'undefined' ? localStorage.getItem(THEME_KEY) || 'light' : 'light'
|
|
8
|
+
} catch {
|
|
9
|
+
return 'light'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function saveTheme(value) {
|
|
13
|
+
try { localStorage.setItem(THEME_KEY, value) } catch { /* 忽略隐私模式 */ }
|
|
14
|
+
}
|
|
15
|
+
export function readLocale() {
|
|
16
|
+
try {
|
|
17
|
+
return typeof localStorage !== 'undefined' ? localStorage.getItem(LOCALE_KEY) || 'zh-CN' : 'zh-CN'
|
|
18
|
+
} catch {
|
|
19
|
+
return 'zh-CN'
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function saveLocale(value) {
|
|
23
|
+
try { localStorage.setItem(LOCALE_KEY, value) } catch { /* 忽略隐私模式 */ }
|
|
24
|
+
}
|
|
25
|
+
export function applyTheme(el) {
|
|
26
|
+
if (el) el.setAttribute('data-theme', readTheme())
|
|
27
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 集成接线(T4 lead):聚合页面模块,触发各页顶层 register。
|
|
3
|
+
* esbuild bundle 为 cjs 时按源码语句序执行:先初始化注册表(ensureGlobals,
|
|
4
|
+
* 含队列 drain),页面模块顶层 window.__postapiPages.register 即可命中。
|
|
5
|
+
* 本文件是唯一静态引用 pages 的位置;shell 与页面保持注册表解耦(契约偏离已标注)。
|
|
6
|
+
*/
|
|
7
|
+
import { ensureGlobals } from './shell/registry.js'
|
|
8
|
+
ensureGlobals()
|
|
9
|
+
import './pages/overview.jsx'
|
|
10
|
+
import './pages/doc.jsx'
|
|
11
|
+
import './pages/debug.jsx'
|
|
12
|
+
import './pages/mock.jsx'
|
|
13
|
+
import './pages/schema.jsx'
|
|
14
|
+
import './pages/env.jsx'
|
|
15
|
+
import './pages/history.jsx'
|
|
16
|
+
import './pages/test.jsx'
|
|
17
|
+
import './pages/import.jsx'
|
|
18
|
+
import './pages/flow.jsx'
|
|
19
|
+
import './pages/search.jsx'
|
|
20
|
+
import './pages/settings.jsx'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostAPI 页签 chip 标题(sidebar.right.pane.tab.title 席位)。
|
|
3
|
+
* 对照样板 FilesTitle.tsx:接收 { useTabInfo },读 tab.title;不注册该席位时
|
|
4
|
+
* chip 会显示 registry 打开时捕获的 title(address) 文本,注册后由本组件接管。
|
|
5
|
+
* 视觉走 Apifox token:字号/字重由 .pp-topbar-title 提供,间距用 var(--sp-1),
|
|
6
|
+
* 内联 style 只写 layout(display / alignItems / gap)。
|
|
7
|
+
*/
|
|
8
|
+
export function ApiTitle({ useTabInfo }) {
|
|
9
|
+
const { tab } = useTabInfo()
|
|
10
|
+
return (
|
|
11
|
+
<span className="pp-topbar-title" style={{ display: 'inline-flex', alignItems: 'center', gap: 'var(--sp-1)' }}>
|
|
12
|
+
<svg viewBox="0 0 64 64" width={14} height={14} aria-hidden="true"
|
|
13
|
+
className="pp-accent" style={{ display: 'block', flexShrink: 0 }}>
|
|
14
|
+
<path d="M6 50 L54 26 L6 8 L6 24 L36 26 L6 28 Z" fill="currentColor" />
|
|
15
|
+
</svg>
|
|
16
|
+
<span className="pp-ellipsis">{tab.title}</span>
|
|
17
|
+
</span>
|
|
18
|
+
)
|
|
19
|
+
}
|