8000 Pydom add better support for select element by fpliger · Pull Request #1887 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

Pydom add better support for select element #1887

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

Merged
merged 14 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add tests for select options
  • Loading branch information
fpliger committed Dec 5, 2023
commit e16824c0b25485509d3cd33187286a0cdaa79aad
11 changes: 11 additions & 0 deletions pyscript.core/test/pyscript_dom/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ <h2 id="multi-elem-h2" class="multi-elems">Content multi-elem-h2</h2>
<input id="test_rr_input_password" type="password" value="Content test_rr_input_password">
</form>

<select id="test_select_element"></select>
<select id="test_select_element_w_options">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<select id="test_select_element_to_clear">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="4">Option 4</option>
</select>

<div id="element-creation-test"></div>

<button id="a-test-button">I'm a button to be clicked</button>
Expand Down
37 changes: 37 additions & 0 deletions pyscript.core/test/pyscript_dom/tests/test_dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,40 @@ def test_element_without_collection(self):
result = pydom[f"#tests-terminal"]
with pytest.raises(AttributeError):
result.value = "some value"

def test_element_without_collection(self):
result = pydom[f"#tests-terminal"]
with pytest.raises(AttributeError):
result.value = "some value"


class TestInput:
def test_select_options_iter(self):
select = pydom[f"#test_select_element_w_options"][0]

for i, option in enumerate(select.options, 1):
assert option.value == f"{i}"
assert option.html == f"Option {i}"

def test_select_options_len(self):
select = pydom[f"#test_select_element_w_options"][0]
assert len(select.options) == 2

def test_select_options_clear(self):
select = pydom[f"#test_select_element_w_options"][0]
assert len(select.options) == 3

select.options.clear()

assert len(select.options) == 0

def test_select_element_add(self):
select = pydom[f"#test_select_element"][0]
assert len(select.options) == 0

select.options.add({"value": "3", "html": "Option 3"})
assert len(select.options) == 1
assert select.options[0].value == "3"
assert select.options[0].html == "Option 3"

select.options.clear()
0