Repository navigation
🎨 Palette: [파일 드롭 존 클릭 기능 추가 및 사용성 개선] #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ead29a1
🎨 Palette: [파일 드롭 존 클릭 기능 추가 및 사용성 개선]
seonghobae 1811b6f
fix(ui): defer drop-zone listeners until DOM ready
seonghobae cb14877
🎨 Palette: [스크린 리더 지원을 위한 파일 드롭 존 ARIA 랜드마크 추가]
seonghobae f986298
fix(ui): restore DOM-ready drop-zone contract after stale-tree rewrite
seonghobae f6365e0
🎨 Palette: [스크린 리더 지원을 위한 파일 드롭 존 ARIA 랜드마크 추가]
seonghobae 18f779b
fix(ui): restore reviewed drop-zone interaction after stale design re…
seonghobae f39f57a
test(ui): execute drop-zone click contract
seonghobae d14ea48
🎨 Palette: [스크린 리더 지원을 위한 파일 드롭 존 ARIA 랜드마크 추가]
seonghobae 71c0349
fix(ui): restore tested drop-zone interaction after stale rewrite
seonghobae a8dce40
docs(a11y): preserve nested control click guard
seonghobae 2208840
Fix UI contract test missing fastapi import
seonghobae 05c86b6
Fix UI contract test missing fastapi import
seonghobae 1142050
Fix UI contract test missing fastapi import
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,233 @@ | ||
| """Executable contracts for the embedded SaaS browser UI.""" | ||
|
|
||
| import json | ||
| import re | ||
| import shutil | ||
| import subprocess | ||
| import textwrap | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
| import saas_web | ||
|
|
||
|
|
||
| SOURCE_TEXT = (Path(__file__).resolve().parents[1] / "saas_web.py").read_text( | ||
| encoding="utf-8" | ||
| ) | ||
|
|
||
|
|
||
| class TestSaasUiContract(unittest.TestCase): | ||
| """Keep DOM registration and nested-control handling safe.""" | ||
|
|
||
| def test_drop_zone_registration_waits_for_complete_dom(self): | ||
| """Batch controls must exist before any listener looks them up.""" | ||
| self.assertIn("window.addEventListener('DOMContentLoaded'", SOURCE_TEXT) | ||
| self.assertLess( | ||
| SOURCE_TEXT.index("window.addEventListener('DOMContentLoaded'"), | ||
| SOURCE_TEXT.index( | ||
| "document.getElementById('batch_preset_buttons_container')" | ||
| ), | ||
| ) | ||
| self.assertIn("window.updateFileSizePreview = function(input)", SOURCE_TEXT) | ||
|
|
||
| def test_nested_interactive_elements_do_not_open_file_picker_twice(self): | ||
| """A child span inside a label remains part of that interactive label.""" | ||
| self.assertEqual( | ||
| SOURCE_TEXT.count("e.target.closest('input, button, label')"), 2 | ||
| ) | ||
|
|
||
| def test_drop_zone_click_behavior_executes_against_dom_harness(self): | ||
| """Execute the generated script and prove both picker click boundaries.""" | ||
| node = shutil.which("node") | ||
| self.assertIsNotNone( | ||
| node, | ||
| "Node.js is required for the embedded-browser UI contract test", | ||
| ) | ||
|
|
||
| scripts = re.findall( | ||
| r"<script>(.*?)</script>", | ||
| saas_web.HTML_TEMPLATE, | ||
| flags=re.DOTALL, | ||
| ) | ||
| self.assertEqual(len(scripts), 1) | ||
| script_literal = json.dumps(scripts[0]) | ||
|
|
||
| harness = textwrap.dedent( | ||
| f""" | ||
| const vm = require('node:vm'); | ||
|
|
||
| class FakeElement {{ | ||
| constructor(tagName = 'DIV', parentElement = null) {{ | ||
| this.tagName = tagName; | ||
| this.parentElement = parentElement; | ||
| this.listeners = new Map(); | ||
| this.clickCount = 0; | ||
| this.dataset = {{}}; | ||
| this.style = {{}}; | ||
| this.files = []; | ||
| this.value = ''; | ||
| this.classList = {{ | ||
| contains: () => false, | ||
| add: () => {{}}, | ||
| remove: () => {{}}, | ||
| }}; | ||
| }} | ||
|
|
||
| addEventListener(type, callback) {{ | ||
| if (!this.listeners.has(type)) this.listeners.set(type, []); | ||
| this.listeners.get(type).push(callback); | ||
| }} | ||
|
|
||
| dispatch(type, target = this) {{ | ||
| for (const callback of this.listeners.get(type) || []) {{ | ||
| callback({{ | ||
| target, | ||
| dataTransfer: {{ files: [] }}, | ||
| preventDefault() {{}}, | ||
| stopPropagation() {{}}, | ||
| isTrusted: true, | ||
| }}); | ||
| }} | ||
| }} | ||
|
|
||
| closest(selector) {{ | ||
| const accepted = new Set( | ||
| selector.split(',').map((part) => part.trim().toUpperCase()) | ||
| ); | ||
| let current = this; | ||
| while (current) {{ | ||
| if (accepted.has(current.tagName)) return current; | ||
| current = current.parentElement; | ||
| }} | ||
| return null; | ||
| }} | ||
|
|
||
| click() {{ | ||
| this.clickCount += 1; | ||
| }} | ||
|
|
||
| setCustomValidity() {{}} | ||
| removeAttribute() {{}} | ||
| setAttribute() {{}} | ||
| }} | ||
|
|
||
| const ids = [ | ||
| 'preset_buttons_container', | ||
| 'batch_preset_buttons_container', | ||
| 'target_bytes', | ||
| 'batch_target_bytes', | ||
| 'target_bytes_preview', | ||
| 'batch_target_bytes_preview', | ||
| 'shrink-form', | ||
| 'submit-btn', | ||
| 'batch_files_preview', | ||
| 'shrink-batch-form', | ||
| 'batch-submit-btn', | ||
| 'drop-zone', | ||
| 'batch-drop-zone', | ||
| 'file', | ||
| 'batch_files', | ||
| 'file_size_preview', | ||
| ]; | ||
|
|
||
| const inputIds = new Set([ | ||
| 'target_bytes', | ||
| 'batch_target_bytes', | ||
| 'file', | ||
| 'batch_files', | ||
| ]); | ||
| const buttonIds = new Set(['submit-btn', 'batch-submit-btn']); | ||
| const elements = Object.fromEntries( | ||
| ids.map((id) => [ | ||
| id, | ||
| new FakeElement( | ||
| inputIds.has(id) ? 'INPUT' : buttonIds.has(id) ? 'BUTTON' : 'DIV' | ||
| ), | ||
| ]) | ||
| ); | ||
|
|
||
| const lateIds = new Set([ | ||
| 'batch_preset_buttons_container', | ||
| 'batch_target_bytes', | ||
| 'batch_target_bytes_preview', | ||
| 'batch_files_preview', | ||
| 'shrink-batch-form', | ||
| 'batch-submit-btn', | ||
| 'batch-drop-zone', | ||
| 'batch_files', | ||
| ]); | ||
| let parserComplete = false; | ||
|
|
||
| const document = {{ | ||
| body: new FakeElement('BODY'), | ||
| getElementById(id) {{ | ||
| if (lateIds.has(id) && !parserComplete) return null; | ||
| if (!(id in elements)) throw new Error(`missing fake element: ${{id}}`); | ||
| return elements[id]; | ||
| }}, | ||
| querySelectorAll() {{ | ||
| return []; | ||
| }}, | ||
| }}; | ||
|
|
||
| const windowListeners = new Map(); | ||
| const window = {{ | ||
| addEventListener(type, callback) {{ | ||
| windowListeners.set(type, callback); | ||
| }}, | ||
| }}; | ||
|
|
||
| global.document = document; | ||
| global.window = window; | ||
| global.Event = class Event {{ | ||
| constructor(type, init = {{}}) {{ | ||
| this.type = type; | ||
| Object.assign(this, init); | ||
| }} | ||
| }}; | ||
|
|
||
| vm.runInThisContext({script_literal}); | ||
| const ready = windowListeners.get('DOMContentLoaded'); | ||
| if (!ready) throw new Error('DOMContentLoaded registration missing'); | ||
|
|
||
| parserComplete = true; | ||
| ready(); | ||
|
|
||
| const empty = new FakeElement('DIV'); | ||
| const input = new FakeElement('INPUT'); | ||
| const button = new FakeElement('BUTTON'); | ||
| const label = new FakeElement('LABEL'); | ||
| const nestedInLabel = new FakeElement('SPAN', label); | ||
|
|
||
| const dropZone = elements['drop-zone']; | ||
| const batchDropZone = elements['batch-drop-zone']; | ||
|
|
||
| dropZone.dispatch('click', empty); | ||
| batchDropZone.dispatch('click', empty); | ||
| for (const target of [input, button, label, nestedInLabel]) {{ | ||
| dropZone.dispatch('click', target); | ||
| batchDropZone.dispatch('click', target); | ||
| }} | ||
|
|
||
| process.stdout.write(JSON.stringify({{ | ||
| fileClicks: elements.file.clickCount, | ||
| batchClicks: elements.batch_files.clickCount, | ||
| }})); | ||
| """ | ||
| ) | ||
|
|
||
| completed = subprocess.run( | ||
| [node, "-e", harness], | ||
| check=True, | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=10, | ||
| ) | ||
| self.assertEqual( | ||
| json.loads(completed.stdout), | ||
| {"fileClicks": 1, "batchClicks": 1}, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.