Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Merge pull request #839 from cfpb/functional-tests
Browse files Browse the repository at this point in the history
Update functional tests
  • Loading branch information
niqjohnson authored Nov 29, 2017
2 parents d5de190 + 6381fa7 commit 716af4c
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 6 deletions.
59 changes: 54 additions & 5 deletions regulations/uitests/diff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import unittest
from base_test import BaseTest
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.color import Color
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait

class DiffTest(BaseTest, unittest.TestCase):

Expand All @@ -29,6 +30,24 @@ def test_diffs(self):
# drawer button should be active
self.assertTrue('current' in drawer_button.get_attribute('class'))

# drawer should display regulation history
timeline_list_items = self.driver.find_elements_by_css_selector('#history-toc-list .status-list')
expected_timeline_versions = [
'2011-11111',
'2012-12121'
]
for index, expected_version in enumerate(expected_timeline_versions):
self.assertEqual(timeline_list_items[index].get_attribute('data-base-version'), expected_version)

# each timeline entry is a link to the rule effective on that date
timeline_links = self.driver.find_elements_by_class_name('version-link')
expected_timeline_urls = [
self.test_url + '/1005-2/2011-11111',
self.test_url + '/1005-2/2012-12121'
]
for index, expected_url in enumerate(expected_timeline_urls):
self.assertEqual(timeline_links[index].get_attribute('href'), expected_url)

diff_field = Select(self.driver.find_element_by_xpath('//*[@id="timeline"]/div[2]/ul/li[1]/div/div/div/form/select'))
# select version to compare to
diff_field.select_by_value('2012-12121')
Expand All @@ -50,6 +69,10 @@ def test_diffs(self):
WebDriverWait(self.driver, 60).until(
lambda driver: 'current' in active_drawer_button.get_attribute('class'))

# diff pane drawer button should be red
diff_button_hex_color = Color.from_string(active_drawer_button.value_of_css_property('color')).hex
self.assertEqual(diff_button_hex_color, '#d14124')

# navigate to 1005.3
self.driver.find_element_by_id('menu-link').click()
WebDriverWait(self.driver, 10).until(
Expand All @@ -63,14 +86,24 @@ def test_diffs(self):
WebDriverWait(self.driver, 30).until(
lambda driver: driver.current_url == self.test_url + '/diff/1005-3/2012-12121/2011-11111?from_version=2011-11111')

# make sure new section is greened
# added text should be italicized and highlighted in green
new_section = self.driver.find_element_by_xpath('//*[@id="1005-3-b-1-vi"]')
self.assertTrue(new_section.find_element_by_tag_name('ins'))
new_section_insertion = new_section.find_element_by_tag_name('ins')
insertion_hex_color = Color.from_string(new_section_insertion.value_of_css_property('background-color')).hex
self.assertEqual(new_section_insertion.value_of_css_property('font-style'), 'italic')
self.assertEqual(insertion_hex_color, '#e2efd8')

# make sure changed paragraph has insertions and deletions
changed_section = self.driver.find_element_by_xpath('//*[@id="1005-3-b-2-ii"]')
self.assertTrue(len(changed_section.find_elements_by_tag_name('ins')) == 2)
self.assertTrue(len(changed_section.find_elements_by_tag_name('del')))
changed_section_insertions = changed_section.find_elements_by_tag_name('ins')
changed_section_deletion = changed_section.find_elements_by_tag_name('del')
self.assertTrue(len(changed_section_insertions) == 2)
self.assertTrue(len(changed_section_deletion))

# deleted text should be struck through and gray
deletion_hex_color = Color.from_string(changed_section_deletion[0].value_of_css_property('color')).hex
self.assertEqual(deletion_hex_color, '#b4b5b6')
self.assertEqual(changed_section_deletion[0].value_of_css_property('text-decoration'), 'line-through')

# go back into diff pane in drawer, stop comparing
self.get_drawer_button().click()
Expand All @@ -81,5 +114,21 @@ def test_diffs(self):
WebDriverWait(self.driver, 30).until(
lambda driver: driver.current_url == self.test_url + '/1005-3/2011-11111')

# "find the regulation effective on this date" takes you to the proper version
self.get_drawer_button().click()
month_input = self.driver.find_element_by_class_name('month-input')
day_input = self.driver.find_element_by_class_name('day-input')
year_input = self.driver.find_element_by_class_name('year-input')
find_button = self.driver.find_element_by_class_name('find-button')
month_input.clear()
day_input.clear()
year_input.clear()
month_input.send_keys('3')
day_input.send_keys('10')
year_input.send_keys('2012')
find_button.click()
WebDriverWait(self.driver, 30).until(
lambda driver: driver.current_url == self.test_url + '/1005-3/2012-12121')

if __name__ == '__main__':
unittest.main()
8 changes: 8 additions & 0 deletions regulations/uitests/interp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def test_interps(self):
# should have the appropriate header
self.assertTrue('OFFICIAL INTERPRETATION TO 2(h)' in interp_dropdown.text)

# should have the "SHOW" link
self.assertIn('SHOW', interp_dropdown.text)

self.driver.execute_script('p10052h = document.getElementById("1005-2-h").offsetTop')
self.driver.execute_script('window.scrollTo(0, p10052h)')

Expand All @@ -42,6 +45,11 @@ def test_interps(self):
# should contain the appropriate reg section
self.assertTrue('clicked. A finances centripetally curiousest stronghold cemeteries' in interp_text.text)

# should contain a link to the appropriate reg section
interp_link = self.driver.find_element_by_xpath('//*[@id="1005-2-h"]/section/section/p/a[@class="internal section-link"]')
self.assertEqual(self.test_url + '/1005-Subpart-Interp/2012-12121#1005-18-a', interp_link.get_attribute('href'))
self.assertEqual(u'See this interpretation in Supplement I', interp_link.text)

self.driver.find_element_by_xpath('//*[@id="1005-2-h"]/section/header/a').click()

WebDriverWait(self.driver, 10).until(
Expand Down
8 changes: 7 additions & 1 deletion regulations/uitests/navigation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_navigation(self):
self.driver.execute_script('window.scrollTo(0, poffset)')
# wayfinding header should update
WebDriverWait(self.driver, 30).until(
lambda driver: driver.find_element_by_xpath('//*[@id="active-title"]').text in
lambda driver: driver.find_element_by_xpath('//*[@id="active-title"]').text in
(u'\u00A71005.5(b)(1)', u'\u00A71005.5(b)'))

fwd_link = self.driver.find_element_by_xpath('//*[@id="1005-5"]/nav/ul/li[2]/a')
Expand All @@ -38,5 +38,11 @@ def test_navigation(self):
WebDriverWait(self.driver, 30).until(
lambda driver: driver.find_element_by_id('1005-4'))

# internal reference should link to the correct subsection
internal_link_1005_7 = self.driver.find_element_by_xpath('//*[@id="1005-4-d"]//a[@data-section-id="1005-7"]')
internal_link_1005_7.click()
WebDriverWait(self.driver, 30).until(
lambda driver: driver.find_element_by_id('1005-7'))

if __name__ == '__main__':
unittest.main()
80 changes: 80 additions & 0 deletions regulations/uitests/responsive_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
import unittest
from base_test import BaseTest
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

class ResponsiveTest(BaseTest, unittest.TestCase):

def job_name(self):
return 'Responsive test'

def test_responsive(self):
# make window the same size as the viewport of iPhone 6/7/8
self.driver.set_window_size(375, 667)

active_subsection_id = '1005-3-b'
self.driver.get(self.test_url + '/1005-3/2012-12121#' + active_subsection_id)
html = self.driver.find_element_by_tag_name('html')
WebDriverWait(self.driver, 30).until(
lambda driver: 'selenium-start' in html.get_attribute('class'))

# interface is formatted for small screens
site_title = self.driver.find_element_by_class_name('site-title')
mobile_nav_trigger = self.driver.find_element_by_class_name('mobile-nav-trigger')
menu_drawer = self.driver.find_element_by_id('menu')
wayfinding_header = self.driver.find_element_by_class_name('wayfinding')
sidebar = self.driver.find_element_by_id('sidebar')
sample_paragraph = self.driver.find_element_by_xpath('//*[@id="' + active_subsection_id + '"]/p')
definition_link = self.driver.find_element_by_xpath('//*[@id="1005-3-a"]/p/a[@class="citation definition"]')
window_y_offset = self.driver.execute_script('return window.pageYOffset;')
active_subsection_offset = self.driver.execute_script('return document.getElementById("' + active_subsection_id + '").offsetTop;')
# site title should be hidden on page load
self.assertFalse(site_title.is_displayed())
# mobile navigation trigger should be visible on page load
self.assertTrue(mobile_nav_trigger.is_displayed())
# menu drawer should be closed on page load
self.assertIn('close', menu_drawer.get_attribute('class'))
# wayfinding header should not be floated
self.assertEqual(wayfinding_header.value_of_css_property('float'), 'none')
# sidebar shoud not be fixed
self.assertNotEqual(sidebar.value_of_css_property('position'), 'fixed')
""" active subsection that the URL points to should be at the top of the
viewport when the page loads; the window offset minus the subsection
offset should be zero, but we use "less than 10" to allow for wiggle
room in how different browsers render the page """
self.assertTrue(window_y_offset - active_subsection_offset < 10)
# wayfinding should update on scroll
self.driver.execute_script('window.scrollTo(0, 0);')
self.assertEqual(wayfinding_header.text, u'\xa71005.3(a)')
# definition panel should be fixed
definition_link.click()
definition_panel = self.driver.find_element_by_class_name('open-definition')
self.assertEqual(definition_panel.value_of_css_property('position'), 'fixed')

# clicking the ">" icon opens the drawer on top of the main content
drawer_toggle = self.driver.find_element_by_id('panel-link')
content_body = self.driver.find_element_by_id('content-body')
drawer_toggle.click()
# menu drawer should open when the draw toggle is clicked
self.assertIn('open', menu_drawer.get_attribute('class'))
# drawer should open on top of the main content
self.assertEqual(content_body.value_of_css_property('margin-left'), '0px')

# global navigation works on small screens
main_navigation = self.driver.find_element_by_class_name('app-nav-list')
# main navigation should be hidden on page load
self.assertFalse(main_navigation.is_displayed())
# main navigation should appear when nav trigger is clicked
mobile_nav_trigger.click()
self.assertTrue(main_navigation.is_displayed())
# landing page should load
nav_landing_link = self.driver.find_element_by_link_text('Regulations')
nav_landing_link.click()
WebDriverWait(self.driver, 30).until(
lambda driver: driver.find_element_by_class_name('landing-content'))
landing_page_content = self.driver.find_element_by_class_name('landing-content')
self.assertTrue(landing_page_content)

if __name__ == '__main__':
unittest.main()
70 changes: 70 additions & 0 deletions regulations/uitests/search_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
""" TODO: Search isn't working correctly when running locally, and any term
you search for will return 100% of the dummy reg's sections as results. When
search is working correctly locally, we should update this test to check for
the correct number and text of results. """

import os
import unittest
from base_test import BaseTest
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

class SearchTest(BaseTest, unittest.TestCase):

def job_name(self):
return 'Search test'

def test_search(self):
self.driver.set_window_size(1024, 600)
self.driver.get(self.test_url + '/1005')
html = self.driver.find_element_by_tag_name('html')
WebDriverWait(self.driver, 30).until(
lambda driver: 'selenium-start' in html.get_attribute('class'))

# clicking on the search icon shows the initially hidden search drawer
search_icon = self.driver.find_element_by_id('search-link')
search_drawer = self.driver.find_element_by_class_name('search-drawer')
self.assertIn('hidden', search_drawer.get_attribute('class'))
search_icon.click()
self.assertNotIn('hidden', search_drawer.get_attribute('class'))

# searching for a term displays the correct results
search_input = self.driver.find_element_by_id('search-input')
search_submit = self.driver.find_element_by_xpath('//*[@id="search"]//button[@type="submit"]')
search_term = 'lorem ipsum'
search_input.send_keys(search_term)
search_submit.click()
WebDriverWait(self.driver, 30).until(
lambda driver: driver.find_element_by_class_name('result-list'))
drawer_toggle = self.driver.find_element_by_id('panel-link')
drawer_toggle.click()
search_header = self.driver.find_element_by_xpath('//h2[@class="search-term"]')
search_pager = self.driver.find_element_by_class_name('pager')
search_results = self.driver.find_elements_by_xpath('//ul[@class="result-list"]/li/h3/a')
expected_results = [
u'1005.Subpart',
u'1005.1 \xa7',
u'1005.1(a)',
u'1005.1(b)',
u'1005.2 \xa7',
u'1005.2(a)',
u'1005.2(a)(1)',
u'1005.2(a)(2)',
u'1005.2(a)(2)(i)',
u'1005.2(a)(2)(ii)'
]
self.assertEqual(search_header.text, u'Searching for \u201c' + search_term + u'\u201d')
self.assertEqual(search_pager.text, u'Page 1 of 124')
for index, expected_result in enumerate(expected_results):
self.assertEqual(search_results[index].text, expected_result)

# clicking a search result loads the appropriate subsection
search_result_link = search_results[9]
search_result_link.click()
WebDriverWait(self.driver, 30).until(
lambda driver: driver.find_element_by_id('1005-2'))
wayfinding_header = self.driver.find_element_by_xpath('//*[@id="active-title"]/*[@class="header-label"]')
self.assertEqual(wayfinding_header.text, u'\xa71005.2(a)(2)(i)')

if __name__ == '__main__':
unittest.main()
8 changes: 8 additions & 0 deletions regulations/uitests/toc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def test_toc(self):
# reg section should load in content area
self.assertTrue('catharine and myriads' in self.driver.find_element_by_class_name('section-title').text)

# subpart number should display as the active title in the wayfinding subhead
active_title_1005_1 = self.driver.find_element_by_id('active-title').text
self.assertEqual(active_title_1005_1, u'\xa71005.1')

# effective date should display in the wayfinding subhead
effective_date = self.driver.find_element_by_class_name('effective-date').text
self.assertEqual(effective_date, 'Effective Date: 10/28/2012')

# toc link should be highlighted
self.assertTrue('current' in toc_link_1005_1.get_attribute('class'))

Expand Down

0 comments on commit 716af4c

Please sign in to comment.