Skip to content

Commit

Permalink
prevent usage of inputs that are keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
agoscinski committed Jul 1, 2024
1 parent 2c03ef7 commit 7dbbe3f
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,21 @@ def test_widget_answer(self, selenium_driver):

assert len(text_inputs) == 1
text_input = text_inputs[0]
text_input.send_keys("test-answers")
text_input.send_keys("test-E")
# wait till typing finished
WebDriverWait(driver, 5).until(
expected_conditions.text_to_be_present_in_element_attribute(
(By.CLASS_NAME, TEXT_INPUT_CLASS_NAME),
"value",
"test-answers",
"test-E",
)
)
# wait till everything is sync with python kernel
time.sleep(0.1)
create_file_button.click()

output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
assert output.text == "File 'pytest-test-answers.json' created and loaded."
assert output.text == "File 'pytest-test-E.json' created and loaded."

answer_registry_buttons = nb_cell.find_elements(
By.CLASS_NAME, BUTTON_CLASS_NAME
Expand Down Expand Up @@ -286,7 +286,7 @@ def test_widget_answer(self, selenium_driver):
)
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
assert (
output.text == "All answers were saved in file 'pytest-test-answers.json'."
output.text == "All answers were saved in file 'pytest-test-E.json'."
)
# cancel
# wait till everything is sync with python kernel
Expand Down Expand Up @@ -321,7 +321,7 @@ def test_widget_answer(self, selenium_driver):
expected_conditions.invisibility_of_element_located(output)
)
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
assert output.text == "All answers loaded from file 'pytest-test-answers.json'."
assert output.text == "All answers loaded from file 'pytest-test-E.json'."

# TODO test interaction of ExerciseWidgets with ExerciseRegistry

Expand All @@ -346,7 +346,7 @@ def test_widget_answer(self, selenium_driver):
load_button = answer_buttons[1]

# tests save button
input_answer = "answer text"
input_answer = "T"
text_input.send_keys(input_answer)
# wait till everything is sync with python kernel
time.sleep(0.1)
Expand Down Expand Up @@ -378,11 +378,12 @@ def test_widget_answer(self, selenium_driver):
assert text_input.get_attribute("value") == input_answer
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
assert (
output.text == "Exercise has been saved in file 'pytest-test-answers.json'."
output.text == "Exercise has been saved in file 'pytest-test-E.json'."
)

# tests load button
text_input.send_keys(" update")
update_keys = " up"
text_input.send_keys(update_keys)
# wait till everything is sync with python kernel
time.sleep(0.1)
# wait for cued box
Expand All @@ -394,7 +395,7 @@ def test_widget_answer(self, selenium_driver):
By.CLASS_NAME, reset_cue_button_class_name("save", True)
)
assert len(reset_cue_buttons) == 2
assert text_input.get_attribute("value") == input_answer + " update"
assert text_input.get_attribute("value") == input_answer + update_keys
#
WebDriverWait(driver, 1).until(
expected_conditions.element_to_be_clickable(load_button)
Expand All @@ -419,7 +420,7 @@ def test_widget_answer(self, selenium_driver):
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
assert (
output.text
== "Exercise has been loaded from file 'pytest-test-answers.json'."
== "Exercise has been loaded from file 'pytest-test-E.json'."
)
assert text_input.get_attribute("value") == input_answer

Expand All @@ -444,7 +445,7 @@ def test_widget_answer(self, selenium_driver):

output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
assert (
output.text == "Exercise has been saved in file 'pytest-test-answers.json'."
output.text == "Exercise has been saved in file 'pytest-test-E.json'."
)
# not cued
cue_box = nb_cell.find_element(By.CLASS_NAME, cue_box_class_name("save", False))
Expand Down Expand Up @@ -479,7 +480,7 @@ def test_widget_answer(self, selenium_driver):
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
assert (
output.text
== "Exercise has been loaded from file 'pytest-test-answers.json'."
== "Exercise has been loaded from file 'pytest-test-E.json'."
)
# not cued
cue_box = nb_cell.find_element(By.CLASS_NAME, cue_box_class_name("save", False))
Expand Down Expand Up @@ -671,9 +672,9 @@ def test_cue_box_cued(nb_cell, cue_box_name, cued_on_init):
# some input that changes the widget

# Check if cue is added once text input is changed
text_input.send_keys("a")
text_input.send_keys("E")
time.sleep(0.1)
assert text_input.get_attribute("value") == "Texta"
assert text_input.get_attribute("value") == "TextE"
assert cue_box_class_name(cue_box_name, True).replace(
".", " "
) == cue_box_widget.get_attribute("class")
Expand Down Expand Up @@ -725,9 +726,9 @@ def test_reset_cue_button(
) == RESET_CUE_BUTTON_CLASS_NAME.replace(".", " ")

# Check if unused text input does not effect cueing of button
unused_text_input.send_keys("a")
unused_text_input.send_keys("E")
time.sleep(0.1)
assert unused_text_input.get_attribute("value") == "Unuseda"
assert unused_text_input.get_attribute("value") == "UnusedE"
assert (
sum(
[
Expand Down Expand Up @@ -758,8 +759,8 @@ def test_reset_cue_button(
assert reset_cue_button.is_enabled()

# Checks if two more widgets are cued on change
text_input.send_keys("a")
assert text_input.get_attribute("value") == "Texta"
text_input.send_keys("E")
assert text_input.get_attribute("value") == "TextE"

WebDriverWait(driver, 1).until(
expected_conditions.element_to_be_clickable(reset_cue_button)
Expand Down Expand Up @@ -1121,7 +1122,7 @@ def test_code_exercise(
# Issue #22
# sending keys to code widget does not work at the moment
# once this works please add this code
# code_input.send_keys("a=5\n")
# code_input.send_keys("v=9\n")
# time.sleep(0.1)
# assert (scwidget_cue_box_class_name("check", True) in
# check_code_input.get_attribute("class"))
Expand All @@ -1138,7 +1139,7 @@ def test_code_exercise(
slider_input_box = nb_cell.find_element(By.CLASS_NAME, "widget-readout")
slider_input_box.send_keys(Keys.BACKSPACE)
slider_input_box.send_keys(Keys.BACKSPACE)
slider_input_box.send_keys(2)
slider_input_box.send_keys(9)
slider_input_box.send_keys(Keys.ENTER)
time.sleep(0.2)

Expand Down

0 comments on commit 7dbbe3f

Please sign in to comment.