Skip to content

Commit f20985d

Browse files
committed
Add additional test condition
1 parent 567b693 commit f20985d

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

evap/student/tests/test_live.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from django.test import override_settings
22
from model_bakery import baker
3-
from selenium.webdriver import ActionChains, Keys
43
from selenium.webdriver.common.by import By
54
from selenium.webdriver.remote.webelement import WebElement
6-
from selenium.webdriver.support.expected_conditions import presence_of_element_located, visibility_of_element_located
5+
from selenium.webdriver.support.expected_conditions import (
6+
invisibility_of_element,
7+
presence_of_element_located,
8+
visibility_of_element_located,
9+
)
710

811
from evap.evaluation.models import Contribution, Evaluation, Question, Questionnaire, QuestionType, UserProfile
912
from evap.evaluation.tests.tools import LiveServerTest
@@ -120,43 +123,46 @@ def test_skip_contributor_clears_warning(self) -> None:
120123
id_ = button.get_attribute("data-mark-no-answers-for")
121124
self.assertEqual(len(self.selenium.find_elements(By.CSS_SELECTOR, f"#vote-area-{id_} .choice-error")), 0)
122125

123-
def test_skip_contributor_modal_appears(self) -> None:
124-
def get_open_modals():
125-
modals = self.selenium.find_elements(By.CSS_SELECTOR, "confirmation-modal.mark-no-answer-modal")
126-
return [
127-
modal for modal in modals if len(modal.shadow_root.find_elements(By.CSS_SELECTOR, "dialog:open")) == 1
128-
]
126+
def get_open_modals(self):
127+
modals = self.selenium.find_elements(By.CSS_SELECTOR, "confirmation-modal.mark-no-answer-modal")
128+
return [modal for modal in modals if len(modal.shadow_root.find_elements(By.CSS_SELECTOR, "dialog:open")) == 1]
129129

130-
def assert_modal_visible_and_close():
131-
modals = get_open_modals()
132-
self.assertEqual(len(modals), 1)
133-
ActionChains(self.selenium).send_keys(Keys.ESCAPE).perform()
130+
def test_skip_contributor_modal_not_shown(self) -> None:
131+
self.selenium.get(self.url)
134132

135-
def assert_modal_not_visible():
136-
modals = get_open_modals()
137-
self.assertEqual(len(modals), 0)
133+
button = self.wait.until(presence_of_element_located((By.CSS_SELECTOR, "[data-mark-no-answers-for]")))
134+
id_ = button.get_attribute("data-mark-no-answers-for")
135+
vote_area = self.selenium.find_element(By.ID, f"vote-area-{id_}")
138136

137+
radio_button = vote_area.find_element(By.CSS_SELECTOR, "input[value='1'] + label.vote-btn")
138+
139+
open_textanswer = vote_area.find_element(By.CSS_SELECTOR, "button.btn-textanswer")
140+
open_textanswer.click()
141+
142+
radio_button.click()
143+
button.click()
144+
self.assertEqual(len(self.get_open_modals()), 0)
145+
146+
def test_skip_contributor_modal_shown(self) -> None:
139147
self.selenium.get(self.url)
140148

141149
button = self.wait.until(presence_of_element_located((By.CSS_SELECTOR, "[data-mark-no-answers-for]")))
142150
id_ = button.get_attribute("data-mark-no-answers-for")
143151
vote_area = self.selenium.find_element(By.ID, f"vote-area-{id_}")
144152

145-
textareas = vote_area.find_elements(By.CSS_SELECTOR, "textarea")
146-
textarea = vote_area.find_element(By.CSS_SELECTOR, f"textarea[name='{textareas[0].get_attribute('name')}']")
147-
radio_buttons = vote_area.find_elements(By.CSS_SELECTOR, "input[value='1'] + label.vote-btn")
148-
self.assertEqual(len(radio_buttons), 1)
153+
textarea = vote_area.find_element(By.CSS_SELECTOR, "textarea")
149154

150155
open_textanswer = vote_area.find_element(By.CSS_SELECTOR, "button.btn-textanswer")
151156
open_textanswer.click()
152157

153158
textarea.click()
154159
textarea.send_keys("a")
155160
button.click()
156-
assert_modal_visible_and_close()
157-
158-
textarea.click()
159-
textarea.send_keys(Keys.BACKSPACE)
160-
radio_buttons[0].click()
161-
button.click()
162-
assert_modal_not_visible()
161+
modals = self.get_open_modals()
162+
self.assertEqual(len(modals), 1)
163+
modal = modals[0]
164+
confirm_button = modal.shadow_root.find_element(By.CSS_SELECTOR, "button[data-event-type='confirm']")
165+
confirm_button.click()
166+
self.wait.until(invisibility_of_element(modal))
167+
self.assertEqual(len(self.get_open_modals()), 0)
168+
self.assertEqual(textarea.text, "")

0 commit comments

Comments
 (0)