mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-07-02 01:22:07 -04:00
Keep snap helper safe without context (#1828)
This commit is contained in:
@@ -36,6 +36,28 @@ def test_compute_snap_tolerates_non_array_other_layers():
|
||||
assert r["x"] == 10 and r["y"] == 10 and r["guides"] == []
|
||||
|
||||
|
||||
@pytest.mark.skipif(not _HAS_NODE, reason="node binary not on PATH")
|
||||
def test_compute_snap_tolerates_missing_layer_or_context():
|
||||
js = f"""
|
||||
import {{ computeSnap }} from '{_HELPER.as_posix()}';
|
||||
console.log(JSON.stringify([
|
||||
computeSnap(null, 10, 20, {{ zoom: 1, canvasW: 800, canvasH: 600 }}),
|
||||
computeSnap({{ id: 'L1' }}, 11, 21, {{ zoom: 1, canvasW: 800, canvasH: 600 }}),
|
||||
computeSnap({{ id: 'L1', canvas: {{ width: 100, height: 50 }} }}, 12, 22, null)
|
||||
]));
|
||||
"""
|
||||
proc = subprocess.run(
|
||||
["node", "--input-type=module"],
|
||||
input=js, capture_output=True, text=True, cwd=str(_REPO), timeout=30,
|
||||
)
|
||||
assert proc.returncode == 0, proc.stderr
|
||||
assert json.loads(proc.stdout.strip()) == [
|
||||
{"x": 10, "y": 20, "guides": []},
|
||||
{"x": 11, "y": 21, "guides": []},
|
||||
{"x": 12, "y": 22, "guides": []},
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.skipif(not _HAS_NODE, reason="node binary not on PATH")
|
||||
def test_compute_snap_still_snaps_to_a_layer_edge():
|
||||
other = [{"id": "L2", "visible": True, "offset": {"x": 12, "y": 300},
|
||||
|
||||
Reference in New Issue
Block a user