bokchoy tests for textbook page

This commit is contained in:
Agha Awais
2018-08-01 11:22:04 +00:00
parent 90b2751997
commit 2f94817118
4 changed files with 132 additions and 156 deletions

View File

@@ -81,3 +81,69 @@ class TextbookUploadPage(CoursePage):
self.set_input_field_value('.edit-textbook #textbook-name-input', 'book_1')
self.set_input_field_value('.edit-textbook #chapter1-name', 'chap_1')
self.click_textbook_submit_button()
def set_textbook_name(self, textbook_name):
"""
Set the name of textbook.
"""
self.open_add_textbook_form()
self.set_input_field_value('.edit-textbook #textbook-name-input', textbook_name)
def fill_chapter_name(self, ordinal, chapter_name):
"""
Adds chapter name by taking the ordinal of the chapter.
"""
index = ["first", "second", "third"].index(ordinal)
self.set_input_field_value('.textbook .chapter{i} input.chapter-name'.format(i=index + 1), chapter_name)
def fill_chapter_asset(self, ordinal, chapter_asset):
"""
Adds chapter asset by taking the ordinal of the chapter.
"""
index = ["first", "second", "third"].index(ordinal)
self.set_input_field_value('.textbook .chapter{i} input.chapter-asset-path'.format(i=index + 1), chapter_asset)
def submit_chapter(self):
"""
Click on Add Chapter button.
"""
self.q(css='.action.action-add-chapter').first.click()
@property
def textbook_name(self):
"""
Gets the name of a saved textbook.
"""
return self.q(css='.textbook-title').text[0]
def get_chapter_name(self, index):
"""
Gets the name of chapter by taking an ordinal.
"""
return self.q(css='.chapter-name').text[index]
def get_asset_name(self, index):
"""
Gets the name of chapter asset by taking an ordinal.
"""
return self.q(css='.chapter-asset-path').text[index]
def toggle_chapters(self):
"""
Toggle saved chapters.
"""
self.q(css='.chapter-toggle.show-chapters').click()
@property
def number_of_chapters(self):
"""
Gets the total number of saved chapters.
"""
return len(self.q(css='.chapter').results)
def refresh_and_wait_for_load(self):
"""
Refresh the page and wait for all resources to load.
"""
self.browser.refresh()
self.wait_for_page()

View File

@@ -13,7 +13,7 @@ class TextbooksTest(StudioCourseTest):
"""
Test that textbook functionality is working properly on studio side
"""
def setUp(self, is_staff=True):
def setUp(self, is_staff=True): # pylint: disable=arguments-differ
"""
Install a course with no content using a fixture.
"""
@@ -29,6 +29,24 @@ class TextbooksTest(StudioCourseTest):
self.textbook_view_page = TextbookViewPage(self.browser, self.course_id)
def _assert_textbook_data(self, textbook_data):
"""
Asserts the textbook data on textbook page
"""
textbook_name = self.textbook_upload_page.textbook_name
self.assertEqual(textbook_data['textbook_name'], textbook_name)
self.textbook_upload_page.toggle_chapters()
number_of_chapters = self.textbook_upload_page.number_of_chapters
self.assertEqual(2, number_of_chapters)
first_chapter_name = self.textbook_upload_page.get_chapter_name(0)
second_chapter_name = self.textbook_upload_page.get_chapter_name(1)
self.assertEqual(textbook_data['first_chapter'], first_chapter_name)
self.assertEqual(textbook_data['second_chapter'], second_chapter_name)
first_asset_name = self.textbook_upload_page.get_asset_name(0)
second_asset_name = self.textbook_upload_page.get_asset_name(1)
self.assertEqual(textbook_data['first_asset'], first_asset_name)
self.assertEqual(textbook_data['second_asset'], second_asset_name)
@attr(shard=9)
def test_create_first_book_message(self):
"""
@@ -88,3 +106,50 @@ class TextbooksTest(StudioCourseTest):
],
})
self.textbook_view_page.a11y_audit.check_for_accessibility_errors()
def test_create_textbooks_with_multiple_chapters(self):
"""
Scenario: Create a textbook with multiple chapters
Given I have opened a new course in Studio
And I go to the textbooks page
And I name my textbook "History"
And I name the first chapter "Britain"
And I type in "britain.pdf" for the first chapter asset
And I click Add a Chapter
And I name the second chapter "America"
And I type in "america.pdf" for the second chapter asset
And I save the textbook
Then I should see a textbook named "History" with 2 chapters
And I click the textbook chapters
Then I should see a textbook named "History" with 2 chapters
And the first chapter should be named "Britain"
And the first chapter should have an asset called "britain.pdf"
And the second chapter should be named "America"
And the second chapter should have an asset called "america.pdf"
And I reload the page
Then I should see a textbook named "History" with 2 chapters
And I click the textbook chapters
Then I should see a textbook named "History" with 2 chapters
And the first chapter should be named "Britain"
And the first chapter should have an asset called "britain.pdf"
And the second chapter should be named "America"
And the second chapter should have an asset called "america.pdf"
"""
textbook_data = {
'textbook_name': 'History',
'first_chapter': 'Britain',
'first_asset': 'britain.pdf',
'second_chapter': 'America',
'second_asset': 'america.pdf'
}
self.textbook_upload_page.set_textbook_name(textbook_data['textbook_name'])
self.textbook_upload_page.fill_chapter_name('first', textbook_data['first_chapter'])
self.textbook_upload_page.fill_chapter_asset('first', textbook_data['first_asset'])
self.textbook_upload_page.submit_chapter()
self.textbook_upload_page.fill_chapter_name('second', textbook_data['second_chapter'])
self.textbook_upload_page.fill_chapter_asset('second', textbook_data['second_asset'])
self.textbook_upload_page.click_textbook_submit_button()
self._assert_textbook_data(textbook_data)
self.textbook_upload_page.refresh_and_wait_for_load()
self.textbook_upload_page.toggle_chapters()
self._assert_textbook_data(textbook_data)