Fix target attribute lookup on <script type="py"> (#1751)

* queryTarget takes element as first param

* Add test for 'target' attribute on script tags test_tag_target_attribute
This commit is contained in:
Jeff Glass
2023-09-25 07:27:47 -05:00
committed by GitHub
parent f0be7ef418
commit ffee4add4a
2 changed files with 28 additions and 9 deletions

View File

@@ -206,7 +206,7 @@ for (const [TYPE, interpreter] of TYPES) {
} = element;
const hasTarget = !!target?.value;
const show = hasTarget
? queryTarget(target.value)
? queryTarget(element, target.value)
: document.createElement("script-py");
if (!hasTarget) {

View File

@@ -54,7 +54,7 @@ class TestDisplay(PyScriptTest):
lines = [line for line in filter_page_content(lines)] # remove empty lines
assert lines == ["hello 1", "hello 2", "hello 3"]
def test_target_attribute(self):
def test_target_parameter(self):
self.pyscript_run(
"""
<script type="py">
@@ -67,6 +67,25 @@ class TestDisplay(PyScriptTest):
mydiv = self.page.locator("#mydiv")
assert mydiv.inner_text() == "hello world"
def test_tag_target_attribute(self):
self.pyscript_run(
"""
<script type="py" target="hello">
from pyscript import display
display('hello')
display("goodbye world", target="goodbye")
display('world')
</script>
<div id="hello"></div>
<div id="goodbye"></div>
"""
)
hello = self.page.locator("#hello")
assert hello.inner_text() == "hello\nworld"
goodbye = self.page.locator("#goodbye")
assert goodbye.inner_text() == "goodbye world"
def test_target_script_py(self):
self.pyscript_run(
"""
@@ -83,7 +102,7 @@ class TestDisplay(PyScriptTest):
"""
)
text = self.page.inner_text("body")
assert text == 'ONE\nTWO\nTHREE'
assert text == "ONE\nTWO\nTHREE"
def test_consecutive_display_target(self):
self.pyscript_run(
@@ -200,8 +219,8 @@ class TestDisplay(PyScriptTest):
</script>
"""
)
output = self.page.locator('script-py')
assert output.inner_text() == 'AAA\nBBB'
output = self.page.locator("script-py")
assert output.inner_text() == "AAA\nBBB"
def test_append_false(self):
self.pyscript_run(
@@ -213,8 +232,8 @@ class TestDisplay(PyScriptTest):
</script>
"""
)
output = self.page.locator('script-py')
assert output.inner_text() == 'BBB'
output = self.page.locator("script-py")
assert output.inner_text() == "BBB"
def test_display_multiple_values(self):
self.pyscript_run(
@@ -227,7 +246,7 @@ class TestDisplay(PyScriptTest):
</script>
"""
)
output = self.page.locator('script-py')
output = self.page.locator("script-py")
assert output.inner_text() == "hello\nworld"
def test_display_multiple_append_false(self):
@@ -240,7 +259,7 @@ class TestDisplay(PyScriptTest):
</script>
"""
)
output = self.page.locator('script-py')
output = self.page.locator("script-py")
assert output.inner_text() == "world"
# TODO: this is a display.py issue to fix when append=False is used