|
| 1 | +# SPDX-License-Identifier: MIT |
| 2 | +# |
| 3 | +# MIT License |
| 4 | +# |
| 5 | +# Copyright (c) 2026 Ericsson |
| 6 | + |
| 7 | +"""Regression probes for the sequence modal submit buttons. |
| 8 | +
|
| 9 | +The group/note/box submit buttons used to carry inline ``onclick`` attributes. |
| 10 | +A browser runs those, but a strict Content-Security-Policy (the VS Code webview |
| 11 | +the frontend is reused in) refuses inline event handlers, so the buttons did |
| 12 | +nothing there. They are now wired with JavaScript-attached listeners, like the |
| 13 | +message/participant submit buttons already were. These tests lock that in: |
| 14 | +no inline handler survives, and a click actually reaches the backend. |
| 15 | +""" |
| 16 | + |
| 17 | + |
| 18 | +class TestSequenceSubmitButtons: |
| 19 | + def test_submit_buttons_have_no_inline_onclick(self, app_url, page): |
| 20 | + result = page.evaluate( |
| 21 | + """() => ({ |
| 22 | + group: document.getElementById('seq-submit-group').getAttribute('onclick'), |
| 23 | + note: document.getElementById('seq-submit-note').getAttribute('onclick'), |
| 24 | + box: document.getElementById('seq-submit-box').getAttribute('onclick'), |
| 25 | + })""" |
| 26 | + ) |
| 27 | + assert result == {"group": None, "note": None, "box": None} |
| 28 | + |
| 29 | + def test_clicking_group_submit_reaches_the_backend(self, app_url, page): |
| 30 | + # Wire the listeners (as sequenceEventListeners does on a real render), |
| 31 | + # stub fetch to capture the call, then click the button natively. |
| 32 | + called = page.evaluate( |
| 33 | + """async () => { |
| 34 | + groupOperationEventListeners(); |
| 35 | + document.getElementById('colb').innerHTML = |
| 36 | + '<svg viewBox="0 0 300 200"><g></g></svg>'; |
| 37 | +
|
| 38 | + const calls = []; |
| 39 | + const realFetch = window.fetch; |
| 40 | + window.fetch = (url, opts) => { |
| 41 | + calls.push(String(url)); |
| 42 | + return Promise.resolve({ |
| 43 | + json: () => Promise.resolve({ plantuml: editor.session.getValue() }) |
| 44 | + }); |
| 45 | + }; |
| 46 | +
|
| 47 | + groupEditMode = false; |
| 48 | + selectedGroupType = 'group'; |
| 49 | + const submit = document.getElementById('seq-submit-group'); |
| 50 | + submit.dataset.startIndex = '2'; |
| 51 | + submit.dataset.endIndex = '3'; |
| 52 | +
|
| 53 | + submit.dispatchEvent(new MouseEvent('click', { bubbles: true })); |
| 54 | + await new Promise((r) => setTimeout(r, 50)); |
| 55 | +
|
| 56 | + window.fetch = realFetch; |
| 57 | + return calls; |
| 58 | + }""" |
| 59 | + ) |
| 60 | + assert any("addGroup" in url for url in called) |
0 commit comments