diff --git a/tests/acceptance/conftest.py b/tests/acceptance/conftest.py index cde5a1caf..8e3ef66f3 100644 --- a/tests/acceptance/conftest.py +++ b/tests/acceptance/conftest.py @@ -426,6 +426,31 @@ 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" @@ -433,6 +458,18 @@ def shift_click_terms(luteclient, words): 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." diff --git a/tests/acceptance/lute_test_client.py b/tests/acceptance/lute_test_client.py index eba1a07f2..648df1580 100644 --- a/tests/acceptance/lute_test_client.py +++ b/tests/acceptance/lute_test_client.py @@ -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. @@ -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", diff --git a/tests/acceptance/reading.feature b/tests/acceptance/reading.feature index 094645bd8..cfb8e4704 100644 --- a/tests/acceptance/reading.feature +++ b/tests/acceptance/reading.feature @@ -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.