Commit 683925ca by E. Kolpakov

Added rendering integration tests

parent 9d1118ae
...@@ -12,11 +12,14 @@ class BaseIntegrationTest(SeleniumTest): ...@@ -12,11 +12,14 @@ class BaseIntegrationTest(SeleniumTest):
def setUp(self): def setUp(self):
super(BaseIntegrationTest, self).setUp() super(BaseIntegrationTest, self).setUp()
self.browser.get(self.live_server_url) # Needed to load scenarios once # Use test scenarios
self.browser.get(self.live_server_url) # Needed to load tests once
scenarios.SCENARIOS.clear() scenarios.SCENARIOS.clear()
# Suzy opens the browser to visit the workbench
self.browser.get(self.live_server_url) self.browser.get(self.live_server_url)
# She knows it's the site by the header
header1 = self.browser.find_element_by_css_selector('h1') header1 = self.browser.find_element_by_css_selector('h1')
self.assertEqual(header1.text, 'XBlock scenarios') self.assertEqual(header1.text, 'XBlock scenarios')
...@@ -27,6 +30,10 @@ class BaseIntegrationTest(SeleniumTest): ...@@ -27,6 +30,10 @@ class BaseIntegrationTest(SeleniumTest):
</vertical_demo> </vertical_demo>
""".format(display_name=escape(display_name), question_text=escape(question_text), completed=completed) """.format(display_name=escape(display_name), question_text=escape(question_text), completed=completed)
def _add_scenario(self, identifier, title, xml):
scenarios.add_xml_scenario(identifier, title, xml)
self.addCleanup(scenarios.remove_scenario, identifier)
def go_to_page(self, page_name, css_selector='section.xblock--drag-and-drop'): def go_to_page(self, page_name, css_selector='section.xblock--drag-and-drop'):
""" """
Navigate to the page `page_name`, as listed on the workbench home Navigate to the page `page_name`, as listed on the workbench home
...@@ -39,12 +46,5 @@ class BaseIntegrationTest(SeleniumTest): ...@@ -39,12 +46,5 @@ class BaseIntegrationTest(SeleniumTest):
def get_element_html(self, element): def get_element_html(self, element):
return element.get_attribute('innerHTML').strip() return element.get_attribute('innerHTML').strip()
def get_element_classes(self, element):
class SingleScenarioIntegrationTest(BaseIntegrationTest): return element.get_attribute('class').split()
def setUp(self): \ No newline at end of file
super(SingleScenarioIntegrationTest, self).setUp()
def _get_scenarios_for_test(self):
identifier, title, scenario = self._get_scenario_for_test()
self._page_title = title
return [(identifier, title, scenario)]
from tests.integration.test_base import BaseIntegrationTest
class TestDragAndDropRender(BaseIntegrationTest):
"""
Verifying Drag and Drop XBlock rendering against default data - if default data changes this would probably broke
"""
PAGE_TITLE = 'Drag and Drop v2'
PAGE_ID = 'drag_and_drop_v2'
def setUp(self):
super(TestDragAndDropRender, self).setUp()
scenario_xml = "<vertical_demo><drag-and-drop-v2/></vertical_demo>"
self._add_scenario(self.PAGE_ID, self.PAGE_TITLE, scenario_xml)
self.browser.get(self.live_server_url)
self._page = self.go_to_page(self.PAGE_TITLE)
def _get_items(self):
items_container = self._page.find_element_by_css_selector('ul.items')
return items_container.find_elements_by_css_selector('li.option')
def _get_zones(self):
return self._page.find_elements_by_css_selector(".drag-container .zone")
def _get_feedback_message(self):
return self._page.find_element_by_css_selector(".feedback .message")
def test_items(self):
items = self._get_items()
self.assertEqual(len(items), 3)
self.assertEqual(items[0].get_attribute('data-value'), '0')
self.assertEqual(items[0].text, 'A')
self.assertEqual(items[0].get_attribute('style'), u"width: 190px; height: auto;")
self.assertIn('ui-draggable', self.get_element_classes(items[0]))
self.assertEqual(items[1].get_attribute('data-value'), '1')
self.assertEqual(items[1].text, 'B')
self.assertEqual(items[1].get_attribute('style'), u"width: 190px; height: auto;")
self.assertIn('ui-draggable', self.get_element_classes(items[1]))
self.assertEqual(items[2].get_attribute('data-value'), '2')
self.assertEqual(items[2].text, 'X')
self.assertEqual(items[2].get_attribute('style'), u"width: 100px; height: 100px;")
self.assertIn('ui-draggable', self.get_element_classes(items[2]))
def test_zones(self):
zones = self._get_zones()
self.assertEqual(len(zones), 2)
self.assertEqual(zones[0].get_attribute('data-zone'), 'Zone A')
self.assertEqual(zones[0].get_attribute('style'), u"top: 200px; left: 120px; width: 200px; height: 100px;")
self.assertIn('ui-droppable', self.get_element_classes(zones[0]))
self.assertEqual(zones[1].get_attribute('data-zone'), 'Zone B')
self.assertEqual(zones[1].get_attribute('style'), u"top: 360px; left: 120px; width: 200px; height: 100px;")
self.assertIn('ui-droppable', self.get_element_classes(zones[1]))
def test_feedback(self):
feedback_message = self._get_feedback_message()
self.assertEqual(feedback_message.text, "Intro Feed")
\ No newline at end of file
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
from nose_parameterized import parameterized from nose_parameterized import parameterized
from tests.integration.test_base import BaseIntegrationTest
from workbench import scenarios from workbench import scenarios
from tests.integration.test_base import BaseIntegrationTest __author__ = 'john'
class TestBlockParameters(BaseIntegrationTest): class TestDragAndDropTitleAndQuestion(BaseIntegrationTest):
@parameterized.expand([ @parameterized.expand([
("plain1", 'title1', 'question1'), ('plain1', 'title1', 'question1'),
("plain2", 'title2', 'question2'), ('plain2', 'title2', 'question2'),
("html1", 'title with <i>HTML</i>', 'Question with <i>HTML</i>'), ('html1', 'title with <i>HTML</i>', 'Question with <i>HTML</i>'),
("html2", '<span style="color:red">Title: HTML?</span>', '<span style="color:red">Span question</span>'), ('html2', '<span style="color:red">Title: HTML?</span>', '<span style="color:red">Span question</span>'),
]) ])
def test_block_parameters(self, _, display_name, question_text): def test_title_and_question_parameters(self, _, display_name, question_text):
const_page_name = "Test block parameters" const_page_name = 'Test block parameters'
const_page_id = 'test_block_title' const_page_id = 'test_block_title'
scenario_xml = self._make_scenario_xml(display_name, question_text, False) scenario_xml = self._make_scenario_xml(display_name, question_text, False)
scenarios.add_xml_scenario(const_page_id, const_page_name, scenario_xml) scenarios.add_xml_scenario(const_page_id, const_page_name, scenario_xml)
...@@ -23,11 +24,5 @@ class TestBlockParameters(BaseIntegrationTest): ...@@ -23,11 +24,5 @@ class TestBlockParameters(BaseIntegrationTest):
problem_header = page.find_element_by_css_selector('h2.problem-header') problem_header = page.find_element_by_css_selector('h2.problem-header')
self.assertEqual(self.get_element_html(problem_header), display_name) self.assertEqual(self.get_element_html(problem_header), display_name)
question = page.find_element_by_css_selector("section.problem > p") question = page.find_element_by_css_selector('section.problem > p')
self.assertEqual(self.get_element_html(question), question_text) self.assertEqual(self.get_element_html(question), question_text)
def _get_scenario_for_test(self):
return None, None, None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment