|
41 | 41 | from selenium import webdriver |
42 | 42 | from selenium.webdriver.common.action_chains import ActionChains |
43 | 43 | from selenium.webdriver.common.by import By |
44 | | - from selenium.webdriver.support.ui import WebDriverWait |
| 44 | + from selenium.webdriver.support.ui import Select, WebDriverWait |
45 | 45 | from selenium.webdriver.support import expected_conditions |
46 | 46 | from selenium.common.exceptions import NoSuchElementException |
47 | 47 | except ImportError as e: |
@@ -904,6 +904,107 @@ def test_session_materials_modal(self): |
904 | 904 | with self.assertRaises(NoSuchElementException): |
905 | 905 | self.driver.find_element_by_xpath('//a[text()="%s"]' % slide.title) |
906 | 906 |
|
| 907 | + def _wait_for_tz_change_from(self, old_tz): |
| 908 | + """Helper to wait for tz displays to change from their old value""" |
| 909 | + match = 'text()!="%s"' % old_tz |
| 910 | + WebDriverWait(self.driver, 2).until( |
| 911 | + expected_conditions.presence_of_element_located((By.XPATH, '//*[@class="current-tz"][%s]' % match)) |
| 912 | + ) |
| 913 | + |
| 914 | + def test_agenda_time_zone_selection(self): |
| 915 | + self.assertNotEqual(self.meeting.time_zone, 'UTC', 'Meeting time zone must not be UTC') |
| 916 | + |
| 917 | + self.driver.get(self.absreverse('ietf.meeting.views.agenda')) |
| 918 | + |
| 919 | + # wait for the select box to be updated - look for an arbitrary time zone to be in |
| 920 | + # its options list to detect this |
| 921 | + WebDriverWait(self.driver, 2).until( |
| 922 | + expected_conditions.presence_of_element_located((By.XPATH, '//option[@value="America/Halifax"]')) |
| 923 | + ) |
| 924 | + |
| 925 | + tz_select_input = Select(self.driver.find_element_by_id('timezone_select')) |
| 926 | + meeting_tz_link = self.driver.find_element_by_id('meeting-timezone') |
| 927 | + local_tz_link = self.driver.find_element_by_id('local-timezone') |
| 928 | + utc_tz_link = self.driver.find_element_by_id('utc-timezone') |
| 929 | + tz_displays = self.driver.find_elements_by_css_selector('.current-tz') |
| 930 | + self.assertGreaterEqual(len(tz_displays), 1) |
| 931 | + # we'll check that all current-tz elements are updated, but first check that at least one is in the nav sidebar |
| 932 | + self.assertIsNotNone(self.driver.find_element_by_css_selector('.nav .current-tz')) |
| 933 | + |
| 934 | + # Moment.js guesses local time zone based on the behavior of Selenium's web client. This seems |
| 935 | + # to inherit Django's settings.TIME_ZONE but I don't know whether that's guaranteed to be consistent. |
| 936 | + # To avoid test fragility, ask Moment what it considers local and expect that. |
| 937 | + local_tz = self.driver.execute_script('return moment.tz.guess();') |
| 938 | + self.assertNotEqual(self.meeting.time_zone, local_tz, 'Meeting time zone must not be local time zone') |
| 939 | + self.assertNotEqual(local_tz, 'UTC', 'Local time zone must not be UTC') |
| 940 | + |
| 941 | + # Should start off in meeting time zone |
| 942 | + self.assertEqual(tz_select_input.first_selected_option.get_attribute('value'), self.meeting.time_zone) |
| 943 | + for disp in tz_displays: |
| 944 | + self.assertEqual(disp.text.strip(), self.meeting.time_zone) |
| 945 | + |
| 946 | + # Click 'local' button |
| 947 | + local_tz_link.click() |
| 948 | + self._wait_for_tz_change_from(self.meeting.time_zone) |
| 949 | + self.assertEqual(tz_select_input.first_selected_option.get_attribute('value'), local_tz) |
| 950 | + for disp in tz_displays: |
| 951 | + self.assertEqual(disp.text.strip(), local_tz) |
| 952 | + |
| 953 | + # click 'utc' button |
| 954 | + utc_tz_link.click() |
| 955 | + self._wait_for_tz_change_from(local_tz) |
| 956 | + self.assertEqual(tz_select_input.first_selected_option.get_attribute('value'), 'UTC') |
| 957 | + for disp in tz_displays: |
| 958 | + self.assertEqual(disp.text.strip(), 'UTC') |
| 959 | + |
| 960 | + # click back to meeting |
| 961 | + meeting_tz_link.click() |
| 962 | + self._wait_for_tz_change_from('UTC') |
| 963 | + self.assertEqual(tz_select_input.first_selected_option.get_attribute('value'), self.meeting.time_zone) |
| 964 | + for disp in tz_displays: |
| 965 | + self.assertEqual(disp.text.strip(), self.meeting.time_zone) |
| 966 | + |
| 967 | + # and then back to UTC... |
| 968 | + utc_tz_link.click() |
| 969 | + self._wait_for_tz_change_from(self.meeting.time_zone) |
| 970 | + self.assertEqual(tz_select_input.first_selected_option.get_attribute('value'), 'UTC') |
| 971 | + for disp in tz_displays: |
| 972 | + self.assertEqual(disp.text.strip(), 'UTC') |
| 973 | + |
| 974 | + # ... and test the switch from UTC to local |
| 975 | + local_tz_link.click() |
| 976 | + self._wait_for_tz_change_from('UTC') |
| 977 | + self.assertEqual(tz_select_input.first_selected_option.get_attribute('value'), local_tz) |
| 978 | + for disp in tz_displays: |
| 979 | + self.assertEqual(disp.text.strip(), local_tz) |
| 980 | + |
| 981 | + # Now select a different item from the select input |
| 982 | + tz_select_input.select_by_value('America/Halifax') |
| 983 | + self._wait_for_tz_change_from(self.meeting.time_zone) |
| 984 | + self.assertEqual(tz_select_input.first_selected_option.get_attribute('value'), 'America/Halifax') |
| 985 | + for disp in tz_displays: |
| 986 | + self.assertEqual(disp.text.strip(), 'America/Halifax') |
| 987 | + |
| 988 | + def test_agenda_time_zone_selection_updates_weekview(self): |
| 989 | + """Changing the time zone should update the weekview to match""" |
| 990 | + # enable a filter so the weekview iframe is visible |
| 991 | + self.driver.get(self.absreverse('ietf.meeting.views.agenda') + '?show=mars') |
| 992 | + # wait for the select box to be updated - look for an arbitrary time zone to be in |
| 993 | + # its options list to detect this |
| 994 | + WebDriverWait(self.driver, 2).until( |
| 995 | + expected_conditions.presence_of_element_located((By.XPATH, '//option[@value="America/Halifax"]')) |
| 996 | + ) |
| 997 | + |
| 998 | + tz_select_input = Select(self.driver.find_element_by_id('timezone_select')) |
| 999 | + |
| 1000 | + # Now select a different item from the select input |
| 1001 | + tz_select_input.select_by_value('America/Halifax') |
| 1002 | + self._wait_for_tz_change_from(self.meeting.time_zone) |
| 1003 | + self.assertEqual(tz_select_input.first_selected_option.get_attribute('value'), 'America/Halifax') |
| 1004 | + self.driver.switch_to.frame('weekview') |
| 1005 | + wv_url = self.driver.execute_script('return document.location.href') |
| 1006 | + self.assertIn('tz=america/halifax', wv_url) |
| 1007 | + |
907 | 1008 |
|
908 | 1009 | @skipIf(skip_selenium, skip_message) |
909 | 1010 | class WeekviewTests(MeetingTestCase): |
|
0 commit comments