|
1 | 1 | from django.test import override_settings |
2 | 2 | from model_bakery import baker |
3 | | -from selenium.webdriver import ActionChains, Keys |
4 | 3 | from selenium.webdriver.common.by import By |
5 | 4 | 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 | +) |
7 | 10 |
|
8 | 11 | from evap.evaluation.models import Contribution, Evaluation, Question, Questionnaire, QuestionType, UserProfile |
9 | 12 | from evap.evaluation.tests.tools import LiveServerTest |
@@ -120,43 +123,46 @@ def test_skip_contributor_clears_warning(self) -> None: |
120 | 123 | id_ = button.get_attribute("data-mark-no-answers-for") |
121 | 124 | self.assertEqual(len(self.selenium.find_elements(By.CSS_SELECTOR, f"#vote-area-{id_} .choice-error")), 0) |
122 | 125 |
|
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] |
129 | 129 |
|
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) |
134 | 132 |
|
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_}") |
138 | 136 |
|
| 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: |
139 | 147 | self.selenium.get(self.url) |
140 | 148 |
|
141 | 149 | button = self.wait.until(presence_of_element_located((By.CSS_SELECTOR, "[data-mark-no-answers-for]"))) |
142 | 150 | id_ = button.get_attribute("data-mark-no-answers-for") |
143 | 151 | vote_area = self.selenium.find_element(By.ID, f"vote-area-{id_}") |
144 | 152 |
|
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") |
149 | 154 |
|
150 | 155 | open_textanswer = vote_area.find_element(By.CSS_SELECTOR, "button.btn-textanswer") |
151 | 156 | open_textanswer.click() |
152 | 157 |
|
153 | 158 | textarea.click() |
154 | 159 | textarea.send_keys("a") |
155 | 160 | 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