File size: 1,717 Bytes
6a7089a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# 05-eval.sh β€” CLI evaluate command

source "$(dirname "$0")/common.sh"

# ─────────────────────────────────────────────────────────────────
start_test "pinchtab eval <expression>"

pt_ok nav "${FIXTURES_URL}/index.html"
pt_ok eval "1 + 1"
assert_output_contains "2" "evaluates simple expression"

end_test

# ─────────────────────────────────────────────────────────────────
start_test "pinchtab eval (DOM query)"

pt_ok nav "${FIXTURES_URL}/form.html"
pt_ok eval "document.title"
assert_output_contains "Form" "returns page title"

end_test

# ─────────────────────────────────────────────────────────────────
start_test "pinchtab eval (JSON result)"

pt_ok eval 'JSON.stringify({a: 1, b: 2})'
# Output is {"result": "{\"a\":1,\"b\":2}"} - escaped JSON
assert_output_contains 'a' "returns JSON object"
assert_output_contains 'b' "contains both keys"

end_test

# ─────────────────────────────────────────────────────────────────
start_test "pinchtab eval --tab <tabId> <expression>"

pt_ok nav "${FIXTURES_URL}/buttons.html"
TAB_ID=$(echo "$PT_OUT" | jq -r '.tabId')

pt_ok eval "document.title" --tab "$TAB_ID"
assert_output_contains "Button" "evaluates in correct tab"

end_test