()
| 255 | }} |
| 256 | testID="submit" |
| 257 | onPress={async () => { |
| 258 | setResult(null); |
| 259 | setRunning(true); |
| 260 | try { |
| 261 | const inputs = text |
| 262 | .split('\n') |
| 263 | .map(v => v.trim()) |
| 264 | .filter(v => v.length > 0); |
| 265 | const methodName = inputs[0]; |
| 266 | if (!methodName || typeof PushyModule[methodName] !== 'function') { |
| 267 | throw new Error(`Unknown method: ${methodName || '(empty)'}`); |
| 268 | } |
| 269 | let params; |
| 270 | let output; |
| 271 | if (inputs.length === 1) { |
| 272 | output = await invokePushyMethod(methodName); |
| 273 | } else { |
| 274 | if (inputs.length === 2) { |
| 275 | params = inputs[1]; |
| 276 | } else { |
| 277 | params = {}; |
| 278 | for (let i = 1; i < inputs.length; i += 2) { |
| 279 | params[inputs[i]] = inputs[i + 1]; |
| 280 | } |
| 281 | console.log({inputs, params}); |
| 282 | } |
| 283 | output = await invokePushyMethod(methodName, params); |
| 284 | } |
| 285 | const message = |
| 286 | output == null |
| 287 | ? '' |
| 288 | : typeof output === 'string' |
| 289 | ? output |
| 290 | : JSON.stringify(output); |
| 291 | setResult({ |
| 292 | status: 'done', |
| 293 | message, |
| 294 | }); |
| 295 | } catch (e) { |
| 296 | setResult({ |
| 297 | status: 'error', |
| 298 | message: e?.message || String(e), |
| 299 | }); |
| 300 | } |
| 301 | setRunning(false); |
| 302 | }}> |
| 303 | <Text style={{color: 'white'}}>执行</Text> |
| 304 | </TouchableOpacity> |
| 305 | <Button title="重置" onPress={() => setText('')} /> |
nothing calls this directly
no test coverage detected