Skip to content
Snippets Groups Projects
Commit ed3b9720 authored by Jonathan Piacenti's avatar Jonathan Piacenti Committed by E. Kolpakov
Browse files

Added tests for Library pagination.

parent ff1a08cb
No related merge requests found
......@@ -3,6 +3,7 @@ Library edit page in Studio
"""
from bok_choy.page_object import PageObject
from selenium.webdriver.common.keys import Keys
from .container import XBlockWrapper
from ...tests.helpers import disable_animations
from .utils import confirm_prompt, wait_for_notification
......@@ -74,6 +75,58 @@ class LibraryPage(PageObject):
confirm_prompt(self) # this will also wait_for_notification()
self.wait_for_ajax()
def nav_disabled(self, position, arrows=('next', 'previous')):
"""
Verifies that pagination nav is disabled. Position can be 'top' or 'bottom'.
To specify a specific arrow, pass an iterable with a single element, 'next' or 'previous'.
"""
return all([
self.q(css='nav.%s * a.%s-page-link.is-disabled' % (position, arrow))
for arrow in arrows
])
def move_back(self, position):
"""
Clicks one of the forward nav buttons. Position can be 'top' or 'bottom'.
"""
self.q(css='nav.%s * a.previous-page-link' % position)[0].click()
self.wait_until_ready()
def move_forward(self, position):
"""
Clicks one of the forward nav buttons. Position can be 'top' or 'bottom'.
"""
self.q(css='nav.%s * a.next-page-link' % position)[0].click()
self.wait_until_ready()
def revisit(self):
"""
Visit the page's URL, instead of refreshing, so that a new state is created.
"""
self.browser.get(self.browser.current_url)
self.wait_until_ready()
def go_to_page(self, number):
"""
Enter a number into the page number input field, and then try to navigate to it.
"""
page_input = self.q(css="#page-number-input")[0]
page_input.click()
page_input.send_keys(str(number))
page_input.send_keys(Keys.RETURN)
self.wait_until_ready()
def check_page_unchanged(self, first_block_name):
"""
Used to make sure that a page has not transitioned after a bogus number is given.
"""
if not self.xblocks[0].name == first_block_name:
return False
if not self.q(css='#page-number-input')[0].get_attribute('value') == '':
return False
return True
def _get_xblocks(self):
"""
Create an XBlockWrapper for each XBlock div found on the page.
......
"""
Acceptance tests for Content Libraries in Studio
"""
from ddt import ddt, data
from .base_studio_test import StudioLibraryTest
from ...pages.studio.utils import add_component
from ...pages.studio.library import LibraryPage
@ddt
class LibraryEditPageTest(StudioLibraryTest):
"""
Test the functionality of the library edit page.
......@@ -107,3 +110,161 @@ class LibraryEditPageTest(StudioLibraryTest):
Ensure the UI is not loaded for adding discussions.
"""
self.assertFalse(self.browser.find_elements_by_css_selector('span.large-discussion-icon'))
def test_library_pagination(self):
"""
Scenario: Ensure that adding several XBlocks to a library results in pagination.
Given that I have a library in Studio with no XBlocks
And I create 10 Multiple Choice XBlocks
Then 10 are displayed.
When I add one more Multiple Choice XBlock
Then 1 XBlock will be displayed
When I delete that XBlock
Then 10 are displayed.
"""
self.assertEqual(len(self.lib_page.xblocks), 0)
for _ in range(0, 10):
add_component(self.lib_page, "problem", "Multiple Choice")
self.assertEqual(len(self.lib_page.xblocks), 10)
add_component(self.lib_page, "problem", "Multiple Choice")
self.assertEqual(len(self.lib_page.xblocks), 1)
self.lib_page.click_delete_button(self.lib_page.xblocks[0].locator)
self.assertEqual(len(self.lib_page.xblocks), 10)
@data('top', 'bottom')
def test_nav_present_but_disabled(self, position):
"""
Scenario: Ensure that the navigation buttons aren't active when there aren't enough XBlocks.
Given that I have a library in Studio with no XBlocks
The Navigation buttons should be disabled.
When I add 5 multiple Choice XBlocks
The Navigation buttons should be disabled.
"""
self.assertEqual(len(self.lib_page.xblocks), 0)
self.assertTrue(self.lib_page.nav_disabled(position))
for _ in range(0, 5):
add_component(self.lib_page, "problem", "Multiple Choice")
self.assertTrue(self.lib_page.nav_disabled(position))
@data('top', 'bottom')
def test_nav_buttons(self, position):
"""
Scenario: Ensure that the navigation buttons work.
Given that I have a library in Studio with no XBlocks
And I create 10 Multiple Choice XBlocks
And I create 10 Checkbox XBlocks
And I create 10 Dropdown XBlocks
And I revisit the page
The previous button should be disabled.
The first XBlock should be a Multiple Choice XBlock
Then if I hit the next button
The first XBlock should be a Checkboxes XBlock
Then if I hit the next button
The first XBlock should be a Dropdown XBlock
And the next button should be disabled
Then if I hit the previous button
The first XBlock should be an Checkboxes XBlock
Then if I hit the previous button
The first XBlock should be a Multipe Choice XBlock
And the previous button should be disabled
"""
self.assertEqual(len(self.lib_page.xblocks), 0)
block_types = [('problem', 'Multiple Choice'), ('problem', 'Checkboxes'), ('problem', 'Dropdown')]
for block_type in block_types:
for _ in range(0, 10):
add_component(self.lib_page, *block_type)
# Don't refresh, as that may contain additional state.
self.lib_page.revisit()
# Check forward navigation
self.assertTrue(self.lib_page.nav_disabled(position, ['previous']))
self.assertEqual(self.lib_page.xblocks[0].name, 'Multiple Choice')
self.lib_page.move_forward(position)
self.assertEqual(self.lib_page.xblocks[0].name, 'Checkboxes')
self.lib_page.move_forward(position)
self.assertEqual(self.lib_page.xblocks[0].name, 'Dropdown')
self.lib_page.nav_disabled(position, ['next'])
# Check backward navigation
self.lib_page.move_back(position)
self.assertEqual(self.lib_page.xblocks[0].name, 'Checkboxes')
self.lib_page.move_back(position)
self.assertEqual(self.lib_page.xblocks[0].name, 'Multiple Choice')
self.assertTrue(self.lib_page.nav_disabled(position, ['previous']))
def test_arbitrary_page_selection(self):
"""
Scenario: I can pick a specific page number of a Library at will.
Given that I have a library in Studio with no XBlocks
And I create 10 Multiple Choice XBlocks
And I create 10 Checkboxes XBlocks
And I create 10 Dropdown XBlocks
And I create 10 Numerical Input XBlocks
And I revisit the page
When I go to the 3rd page
The first XBlock should be a Dropdown XBlock
When I go to the 4th Page
The first XBlock should be a Numerical Input XBlock
When I go to the 1st page
The first XBlock should be a Multiple Choice XBlock
When I go to the 2nd page
The first XBlock should be a Checkboxes XBlock
"""
self.assertEqual(len(self.lib_page.xblocks), 0)
block_types = [
('problem', 'Multiple Choice'), ('problem', 'Checkboxes'), ('problem', 'Dropdown'),
('problem', 'Numerical Input'),
]
for block_type in block_types:
for _ in range(0, 10):
add_component(self.lib_page, *block_type)
# Don't refresh, as that may contain additional state.
self.lib_page.revisit()
self.lib_page.go_to_page(3)
self.assertEqual(self.lib_page.xblocks[0].name, 'Dropdown')
self.lib_page.go_to_page(4)
self.assertEqual(self.lib_page.xblocks[0].name, 'Numerical Input')
self.lib_page.go_to_page(1)
self.assertEqual(self.lib_page.xblocks[0].name, 'Multiple Choice')
self.lib_page.go_to_page(2)
self.assertEqual(self.lib_page.xblocks[0].name, 'Checkboxes')
def test_bogus_page_selection(self):
"""
Scenario: I can't pick a nonsense page number of a Library
Given that I have a library in Studio with no XBlocks
And I create 10 Multiple Choice XBlocks
And I create 10 Checkboxes XBlocks
And I create 10 Dropdown XBlocks
And I create 10 Numerical Input XBlocks
And I revisit the page
When I attempt to go to the 'a'th page
The input field will be cleared and no change of XBlocks will be made
When I attempt to visit the 5th page
The input field will be cleared and no change of XBlocks will be made
When I attempt to visit the -1st page
The input field will be cleared and no change of XBlocks will be made
When I attempt to visit the 0th page
The input field will be cleared and no change of XBlocks will be made
"""
self.assertEqual(len(self.lib_page.xblocks), 0)
block_types = [
('problem', 'Multiple Choice'), ('problem', 'Checkboxes'), ('problem', 'Dropdown'),
('problem', 'Numerical Input'),
]
for block_type in block_types:
for _ in range(0, 10):
add_component(self.lib_page, *block_type)
self.lib_page.revisit()
self.assertEqual(self.lib_page.xblocks[0].name, 'Multiple Choice')
self.lib_page.go_to_page('a')
self.assertTrue(self.lib_page.check_page_unchanged('Multiple Choice'))
self.lib_page.go_to_page(-1)
self.assertTrue(self.lib_page.check_page_unchanged('Multiple Choice'))
self.lib_page.go_to_page(5)
self.assertTrue(self.lib_page.check_page_unchanged('Multiple Choice'))
self.lib_page.go_to_page(0)
self.assertTrue(self.lib_page.check_page_unchanged('Multiple Choice'))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment