From 70c593f9b3c204e8dd81e338afd07e0662ce7ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9line=20MS?= Date: Mon, 9 Sep 2019 18:58:53 +0200 Subject: [PATCH 1/2] Test that disabling isochrone features does not remove distance filters. --- .../tests/selenium/test_disable_isochrone.py | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 labonneboite/tests/selenium/test_disable_isochrone.py diff --git a/labonneboite/tests/selenium/test_disable_isochrone.py b/labonneboite/tests/selenium/test_disable_isochrone.py new file mode 100644 index 000000000..9c923ecfa --- /dev/null +++ b/labonneboite/tests/selenium/test_disable_isochrone.py @@ -0,0 +1,117 @@ +""" +If ENABLE_ISOCHRONES is set to False in settings, +isochrone features should be hidden. +""" + +import re + +from unittest.mock import patch +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + +from labonneboite.conf import settings +from .base import LbbSeleniumTestCase + + +class TestSearchWithoutIsochrone(LbbSeleniumTestCase): + + # @patch.multiple(settings, ENABLE_ISOCHRONES=False) + # def create_app(self): + # """ + # Override app settings to disable isochrone features. + # PROBLEM: it overrides settings for all selenium tests! + # """ + # app = super().create_app() + # settings.ENABLE_ISOCHRONES=False + # return app.test_client() + + + def setUp(self): + super().setUp() + url = self.url_for( + 'search.entreprises', + l='Metz+57050', + occupation='comptabilite', + tr='car', + lat='49.119146', + lon='6.176026', + ) + self.driver.get(url) + + # Click on the Memo button. + memo_button = WebDriverWait(self.driver, 60)\ + .until( + EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "J'ai compris")) + ) + memo_button.click() + + # Wait until the Memo overlay is invisible. + WebDriverWait(self.driver, 60)\ + .until( + EC.invisibility_of_element_located((By.XPATH, "//div[@class='introjs-overlay']")) + ) + + # Accept RGPD, otherwise selecting isochrone filters is not possible. ¯\_(ツ)_/¯ + self.driver.find_element_by_xpath("//button[@class='rgpd-accept']").click() + + + def test_search(self): + """ + Test that isochrone features are not active + but distance filters are still displayed. + """ + + # Store current results + results_sentence = self.driver.find_element_by_css_selector('h1.lbb-result-info').text + primitive_results = re.match(r'(\d+)', results_sentence).group() + + # Assert duration filter is not displayed + duration_filter = self.driver\ + .find_elements_by_css_selector('.switch-element[data-switch-value="duration"]') + + self.assertFalse(duration_filter) + + # Assert distance filter is displayed + distances_list = self.driver\ + .find_element_by_css_selector('#d')\ + .is_displayed() + self.assertTrue(distances_list) + + # Click on a duration + self.driver.find_element_by_css_selector('#d input[value="5"]').click() + + # wait for a new page result to show + new_title = WebDriverWait(self.driver, 60)\ + .until( + EC.visibility_of_element_located((By.CSS_SELECTOR, "h1.lbb-result-info")) + ) + + # Assert new results + results_sentence = new_title.text + last_results = re.match(r'(\d+)', results_sentence).group() + + self.assertEqual(last_results, '7') + + # Make sure we don't have the same results + self.assertLessEqual(int(last_results), int(primitive_results)) + + + def test_commute_time_is_not_displayed(self): + """ + If isochrone features are disabled, + office details should not include commute time + but still display the distance. + """ + + travel_distance_duration = self.driver\ + .find_element_by_css_selector('.lbb-result .travel-distance-duration') + + distance_is_displayed = travel_distance_duration.is_displayed() + self.assertTrue(distance_is_displayed) + + commute_time_is_displayed = travel_distance_duration\ + .find_element_by_css_selector('.travel-duration')\ + .is_displayed() + + self.assertFalse(commute_time_is_displayed) From dd295ae7e48b4ea67f4eb5156ea017b3064469d8 Mon Sep 17 00:00:00 2001 From: Vermeer GRANGE Date: Fri, 3 Jan 2020 12:20:20 +0200 Subject: [PATCH 2/2] Drop no longer active memo introjs from test --- .../tests/selenium/test_disable_isochrone.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/labonneboite/tests/selenium/test_disable_isochrone.py b/labonneboite/tests/selenium/test_disable_isochrone.py index 9c923ecfa..24fd7a357 100644 --- a/labonneboite/tests/selenium/test_disable_isochrone.py +++ b/labonneboite/tests/selenium/test_disable_isochrone.py @@ -39,19 +39,6 @@ def setUp(self): ) self.driver.get(url) - # Click on the Memo button. - memo_button = WebDriverWait(self.driver, 60)\ - .until( - EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "J'ai compris")) - ) - memo_button.click() - - # Wait until the Memo overlay is invisible. - WebDriverWait(self.driver, 60)\ - .until( - EC.invisibility_of_element_located((By.XPATH, "//div[@class='introjs-overlay']")) - ) - # Accept RGPD, otherwise selecting isochrone filters is not possible. ¯\_(ツ)_/¯ self.driver.find_element_by_xpath("//button[@class='rgpd-accept']").click()