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

@@ -1,29 +0,0 @@
@shard_2
Feature: CMS.Textbooks
Scenario: Create a textbook with multiple chapters
Given I have opened a new course in Studio
And I go to the textbooks page
When I click on the New Textbook button
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"

View File

@@ -1,126 +0,0 @@
# pylint: disable=missing-docstring
from django.conf import settings
from lettuce import step, world
from nose.tools import assert_equal
from common import upload_file
TEST_ROOT = settings.COMMON_TEST_DATA_ROOT
@step(u'I go to the textbooks page')
def go_to_uploads(_step):
world.wait_for_js_to_load()
world.click_course_content()
menu_css = 'li.nav-course-courseware-textbooks a'
world.css_click(menu_css)
@step(u'I should see a message telling me to create a new textbook')
def assert_create_new_textbook_msg(_step):
css = ".wrapper-content .no-textbook-content"
assert world.is_css_present(css)
no_tb = world.css_find(css)
assert "You haven't added any textbooks" in no_tb.text
@step(u'I upload the textbook "([^"]*)"$')
def upload_textbook(_step, file_name):
upload_file(file_name, sub_path="uploads/")
@step(u'I click (on )?the New Textbook button')
def click_new_textbook(_step, on):
button_css = ".nav-actions .new-button"
button = world.css_find(button_css)
button.click()
@step(u'I name my textbook "([^"]*)"')
def name_textbook(_step, name):
input_css = ".textbook input[name=textbook-name]"
world.css_fill(input_css, name)
if world.is_firefox():
world.trigger_event(input_css)
@step(u'I name the (first|second|third) chapter "([^"]*)"')
def name_chapter(_step, ordinal, name):
index = ["first", "second", "third"].index(ordinal)
input_css = ".textbook .chapter{i} input.chapter-name".format(i=index + 1)
world.css_fill(input_css, name)
if world.is_firefox():
world.trigger_event(input_css)
@step(u'I type in "([^"]*)" for the (first|second|third) chapter asset')
def asset_chapter(_step, name, ordinal):
index = ["first", "second", "third"].index(ordinal)
input_css = ".textbook .chapter{i} input.chapter-asset-path".format(i=index + 1)
world.css_fill(input_css, name)
if world.is_firefox():
world.trigger_event(input_css)
@step(u'I click the Upload Asset link for the (first|second|third) chapter')
def click_upload_asset(_step, ordinal):
index = ["first", "second", "third"].index(ordinal)
button_css = ".textbook .chapter{i} .action-upload".format(i=index + 1)
world.css_click(button_css)
@step(u'I click Add a Chapter')
def click_add_chapter(_step):
button_css = ".textbook .action-add-chapter"
world.css_click(button_css)
@step(u'I save the textbook')
def save_textbook(_step):
submit_css = "form.edit-textbook button[type=submit]"
world.css_click(submit_css)
@step(u'I should see a textbook named "([^"]*)" with a chapter path containing "([^"]*)"')
def check_textbook(_step, textbook_name, chapter_name):
title = world.css_text(".textbook h3.textbook-title", index=0)
chapter = world.css_text(".textbook .wrap-textbook p", index=0)
assert_equal(title, textbook_name)
assert_equal(chapter, chapter_name)
@step(r'I should see a textbook named "([^"]*)" with (\d+) chapters')
def check_textbook_chapters(_step, textbook_name, num_chapters_str):
num_chapters = int(num_chapters_str)
title = world.css_text(".textbook .view-textbook h3.textbook-title", index=0)
toggle_text = world.css_text(".textbook .view-textbook .chapter-toggle", index=0)
assert_equal(title, textbook_name)
assert_equal(
toggle_text,
"{num} PDF Chapters".format(num=num_chapters),
"Expected {num} chapters, found {real}".format(num=num_chapters, real=toggle_text)
)
@step(u'I click the textbook chapters')
def click_chapters(_step):
world.css_click(".textbook a.chapter-toggle")
@step(u'the (first|second|third) chapter should be named "([^"]*)"')
def check_chapter_name(_step, ordinal, name):
index = ["first", "second", "third"].index(ordinal)
chapter = world.css_find(".textbook .view-textbook ol.chapters li")[index]
element = chapter.find_by_css(".chapter-name")
assert element.text == name, "Expected chapter named {expected}, found chapter named {actual}".format(
expected=name, actual=element.text)
@step(u'the (first|second|third) chapter should have an asset called "([^"]*)"')
def check_chapter_asset(_step, ordinal, name):
index = ["first", "second", "third"].index(ordinal)
chapter = world.css_find(".textbook .view-textbook ol.chapters li")[index]
element = chapter.find_by_css(".chapter-asset-path")
assert element.text == name, "Expected chapter with asset {expected}, found chapter with asset {actual}".format(
expected=name, actual=element.text)

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)