Skip to content

Commit

Permalink
fix select2 X test
Browse files Browse the repository at this point in the history
  • Loading branch information
delijati committed Nov 9, 2023
1 parent 305c479 commit c89ec78
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions deformdemo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,26 +2639,25 @@ def test_render_default(self):
self.assertEqual(len(findxpaths("//optgroup")), 2)

def test_submit_selected(self):
action_chains_xpath_on_select(
"//select[@name='musician']/option"
).click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()
findcss("[data-select2-id='1']").click()
search_field = findcss(".select2-search__field")
search_field.send_keys(Keys.ARROW_DOWN)
search_field.send_keys(Keys.ENTER)

findid("deformsubmit").click()
self.assertRaises(NoSuchElementException, findcss, ".is-invalid")
captured = findid("captured").text
self.assertSimilarRepr(captured, self.first_selected_captured)
self.assertEqual(captured, self.first_selected_captured)

time.sleep(1)

action_chains_xpath_on_select(
"//option[contains(text(), 'Page')]"
).click().send_keys(Keys.ARROW_DOWN).send_keys(
Keys.ARROW_DOWN
).send_keys(
Keys.ARROW_DOWN
).send_keys(
Keys.ENTER
).perform()
findcss("[data-select2-id='1']").click()
search_field = findcss(".select2-search__field")
search_field.send_keys(Keys.ARROW_DOWN)
search_field.send_keys(Keys.ARROW_DOWN)
search_field.send_keys(Keys.ARROW_DOWN)
search_field.send_keys(Keys.ENTER)

findid("deformsubmit").click()
self.assertTrue(
findid("captured").text in self.second_selected_captured
Expand All @@ -2669,25 +2668,22 @@ class Select2TagsWidgetTests(Base, unittest.TestCase):
url = test_url("/select2_with_tags/")

def test_submit_new_option(self):
# open select search field
findcss(".select2-container").click()

# options list is empty
self.assertSimilarRepr(
self.assertEqual(
findid("select2-deformField1-results").text, "No results found"
)

# type a value in select2 search
(
findid("public")
.find_element(By.CSS_SELECTOR, ".select2-search__field")
.send_keys("hello\n")
)
search_field = findcss(".select2-search__field")
search_field.send_keys("hello\n")
search_field.send_keys(Keys.ENTER)

# after form submission typed value appear in captured
findid("deformsubmit").click()
captured = findid("captured").text
self.assertSimilarRepr(
self.assertEqual(
captured,
"{'pepper': 'hello'}",
)
Expand All @@ -2702,28 +2698,28 @@ def test_submit_new_options(self):

# options list is empty
findid("item-deformField1").click()
self.assertSimilarRepr(
findid("select2-deformField1-results").text, "No results found"
self.assertEqual(
findid("select2-deformField1-results").text,
"No results found",
)

# adding values to select field
for value in ("hello", "qwerty", "hello"):
# open select search field
findid("item-deformField1").click()
# type values in selec2 search
(
findid("public")
.find_element(By.CSS_SELECTOR, ".select2-search__field")
.send_keys(value + "\n")
)

search_field = findcss(".select2-search__field")
search_field.send_keys(value + "\n")
search_field.send_keys(Keys.ENTER)

# after form submission typed value appear in captured
findid("deformsubmit").click()
captured = findid("captured").text
expected = "{'pepper': {'hello', 'qwerty'}}"
if PY3:
captured = sort_set_values(captured)
self.assertSimilarRepr(captured, expected)
self.assertEqual(captured, expected)


class SelectizeWidgetTests(Base, unittest.TestCase):
Expand Down

0 comments on commit c89ec78

Please sign in to comment.