Skip to content

Commit

Permalink
Add reading/term form interaction acceptance smoke test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed Dec 24, 2024
1 parent acf20b2 commit 753762d
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/acceptance/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,50 @@ def when_click_word(luteclient, word):
luteclient.click_word(word)


@then(parsers.parse('the reading page term form shows term "{text}"'))
def then_reading_page_term_form_iframe_shows_term(luteclient, text):
"Have to get and read the iframe content, it's not in the main browser page."
with luteclient.browser.get_iframe("wordframe") as iframe:
time.sleep(0.4) # Hack, test failing.
term_field = iframe.find_by_css("#text").first
zws = "\u200B"
val = term_field.value.replace(zws, "")
assert val == text, "check field value"


@then("the bulk edit term form is shown")
def then_reading_page_bulk_edit_term_form_is_shown(luteclient):
"Check content."
then_reading_page_term_form_iframe_contains(luteclient, "Updating")


@then("the term form is hidden")
def then_reading_page_term_form_is_hidden(luteclient):
"Set to blankn"
iframe_element = luteclient.browser.find_by_id("wordframeid").first
iframe_src = iframe_element["src"]
assert iframe_src == "about:blank"


@when(parsers.parse("I shift click:\n{words}"))
def shift_click_terms(luteclient, words):
"Shift-click"
words = words.split("\n")
luteclient.shift_click_words(words)


@when(parsers.parse('I shift-drag from "{wstart}" to "{wend}"'))
def shift_drag(luteclient, wstart, wend):
"shift-drag highlights multiple words, copies to clipboard."
luteclient.shift_drag(wstart, wend)


@when(parsers.parse('I drag from "{wstart}" to "{wend}"'))
def drag(luteclient, wstart, wend):
"shift-drag highlights multiple words, copies to clipboard."
luteclient.drag(wstart, wend)


@when(parsers.parse('I click "{word}" and press hotkey "{hotkey}"'))
def when_click_word_press_hotkey(luteclient, word, hotkey):
"Click word and press hotkey."
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/lute_test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,36 @@ def shift_click_words(self, words):
ac = ac.key_up(Keys.SHIFT)
ac.perform()

def shift_drag(self, fromword, toword):
"Shift-drag over words."
# https://stackoverflow.com/questions/27775759/
# send-keys-control-click-in-selenium-with-python-bindings
# pylint: disable=protected-access
[fromel, toel] = [
self._get_element_for_word(w)._element for w in [fromword, toword]
]
actions = ActionChains(self.browser.driver)
actions.key_down(Keys.SHIFT)
actions.click_and_hold(fromel)
actions.move_to_element(toel)
actions.key_up(Keys.SHIFT)
actions.release()
actions.perform()

def drag(self, fromword, toword):
"drag over words."
# https://stackoverflow.com/questions/27775759/
# send-keys-control-click-in-selenium-with-python-bindings
# pylint: disable=protected-access
[fromel, toel] = [
self._get_element_for_word(w)._element for w in [fromword, toword]
]
actions = ActionChains(self.browser.driver)
actions.click_and_hold(fromel)
actions.move_to_element(toel)
actions.release()
actions.perform()

def fill_reading_bulk_edit_form(self, updates=None):
"""
Click a word in the reading frame, fill in the term form iframe.
Expand Down Expand Up @@ -367,6 +397,7 @@ def fill_reading_bulk_edit_form(self, updates=None):
def press_hotkey(self, hotkey):
"Send a hotkey."
key_to_code_map = {
"escape": "Escape",
"1": "Digit1",
"2": "Digit2",
"3": "Digit3",
Expand Down
28 changes: 28 additions & 0 deletions tests/acceptance/reading.feature
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,34 @@ Feature: User can actually read and stuff.
Tengo (1)/ /otro/ /amigo (1)/.


Scenario: Edit forms are shown at appropriate times
Given a Spanish book "Hola" with content:
Tengo un amigo y una bebida.

When I click "amigo"
Then the reading page term form shows term "amigo"
When I shift-drag from "Tengo" to "un"
Then the reading page term form shows term "amigo"

When I shift click:
una
bebida
Then the bulk edit term form is shown
When I press hotkey "1"
Then the term form is hidden

When I drag from "una" to "bebida"
Then the reading page term form shows term "una bebida"

When I press hotkey "escape"
Then the term form is hidden

When I drag from "una" to "bebida"
Then the reading page term form shows term "una bebida"
When I shift-drag from "Tengo" to "un"
Then the reading page term form shows term "una bebida"


Scenario: Bulk editing terms while reading
Given a Spanish book "Hola" with content:
Tengo otro amigo.
Expand Down

0 comments on commit 753762d

Please sign in to comment.