Courseware wordcloud tests

This commit is contained in:
Agha Awais
2018-10-01 13:23:20 +00:00
parent a55ed88378
commit b0d678d77c
4 changed files with 115 additions and 72 deletions

View File

@@ -333,6 +333,48 @@ class CoursewarePage(CoursePage, CompletionOnViewMixin):
and self.q(css='.btn-brand').text[0] == u'Go To Prerequisite Section' \
and self.q(css='.problem-header').text[0] == u'Content Locked'
@property
def is_word_cloud_rendered(self):
"""
Check for word cloud fields presence
"""
return self.q(css='.input-cloud').visible
def input_word_cloud(self, answer_word):
"""
Fill the word cloud fields
Args:
answer_word(str): An answer words to be filled in the field
"""
self.wait_for_element_visibility('.input-cloud', "Word cloud fields are visible")
css = '.input_cloud_section label:nth-child({}) .input-cloud'
for index in range(1, len(self.q(css='.input-cloud')) + 1):
self.q(css=css.format(index)).fill(answer_word + str(index))
def save_word_cloud(self):
"""
Click save button
"""
self.q(css='.input_cloud_section .action button.save').click()
self.wait_for_ajax()
@property
def word_cloud_answer_list(self):
"""
Get saved words
Returns:
list: Return empty when no answer words are present
list: Return populated when answer words are present
"""
self.wait_for_element_presence('.your_words', "Answer list is present")
if self.q(css='.your_words strong').present:
return self.q(css='.your_words strong').text
else:
return self.q(css='.your_words').text[0]
class CoursewareSequentialTabPage(CoursePage):
"""

View File

@@ -853,3 +853,76 @@ class CompletionTestCase(UniqueCourseTest, EventsTestMixin):
# Auto-auth register for the course.
AutoAuthPage(self.browser, username=self.USERNAME, email=self.EMAIL,
course_id=self.course_id, staff=False).visit()
@attr(shard=9)
class WordCloudTests(UniqueCourseTest):
"""
Tests the Word Cloud.
"""
USERNAME = "STUDENT_TESTER"
EMAIL = "student101@example.com"
def setUp(self):
super(WordCloudTests, self).setUp()
self.courseware_page = CoursewarePage(self.browser, self.course_id)
self.studio_course_outline = StudioCourseOutlinePage(
self.browser,
self.course_info['org'],
self.course_info['number'],
self.course_info['run']
)
# Install a course
course_fix = CourseFixture(
self.course_info['org'], self.course_info['number'],
self.course_info['run'], self.course_info['display_name']
)
# Set word cloud value against advanced modules in advanced settings
course_fix.add_advanced_settings({
"advanced_modules": {"value": ["word_cloud"]},
})
course_fix.add_children(
XBlockFixtureDesc('chapter', 'Test Section 1').add_children(
XBlockFixtureDesc('sequential', 'Test Subsection 1').add_children(
XBlockFixtureDesc('vertical', 'Test Unit').add_children(
XBlockFixtureDesc(
'word_cloud', 'advanced WORDCLOUD'
)
)
)
)
).install()
auto_auth(self.browser, self.USERNAME, self.EMAIL, False, self.course_id)
self.courseware_page.visit()
def test_word_cloud_is_rendered_with_empty_result(self):
"""
Scenario: Word Cloud component in LMS is rendered with empty result
Given the course has a Word Cloud component
Then I view the word cloud and it has rendered
When I press the Save button
Then I see the empty result
"""
self.assertTrue(self.courseware_page.is_word_cloud_rendered)
self.courseware_page.save_word_cloud()
self.assertEqual(self.courseware_page.word_cloud_answer_list, '')
def test_word_cloud_is_rendered_with_result(self):
"""
Scenario: Word Cloud component in LMS is rendered with result
Given the course has a Word Cloud component
Then I view the word cloud and it has rendered
When I fill inputs
And I press the Save button
Then I see the result with words count
"""
expected_data = ['test_wordcloud1', 'test_wordcloud2', 'test_wordcloud3', 'test_wordcloud4', 'test_wordcloud5']
self.assertTrue(self.courseware_page.is_word_cloud_rendered)
self.courseware_page.input_word_cloud('test_wordcloud')
self.courseware_page.save_word_cloud()
self.assertItemsEqual(expected_data, self.courseware_page.word_cloud_answer_list)

View File

@@ -1,16 +0,0 @@
@shard_2
Feature: LMS.World Cloud component
As a student, I want to view Word Cloud component in LMS.
Scenario: Word Cloud component in LMS is rendered with empty result
Given the course has a Word Cloud component
Then I view the word cloud and it has rendered
When I press the Save button
Then I see the empty result
Scenario: Word Cloud component in LMS is rendered with result
Given the course has a Word Cloud component
Then I view the word cloud and it has rendered
When I fill inputs
And I press the Save button
Then I see the result with words count

View File

@@ -1,56 +0,0 @@
# pylint: disable=missing-docstring
from lettuce import step, world
from common import i_am_registered_for_the_course, section_location, visit_scenario_item
@step('I view the word cloud and it has rendered')
def word_cloud_is_rendered(_step):
assert world.is_css_present('.word_cloud')
@step('the course has a Word Cloud component')
def view_word_cloud(_step):
coursenum = 'test_course'
i_am_registered_for_the_course(_step, coursenum)
add_word_cloud_to_course(coursenum)
visit_scenario_item('SECTION')
@step('I press the Save button')
def press_the_save_button(_step):
button_css = '.input_cloud_section .save'
world.css_click(button_css)
@step('I see the empty result')
def see_empty_result(_step):
assert world.css_text('.your_words', 0) == ''
@step('I fill inputs')
def fill_inputs(_step):
input_css = '.input_cloud_section .input-cloud'
world.css_fill(input_css, 'text1', 0)
for index in range(1, 4):
world.css_fill('.input_cloud_section .input-cloud', 'text2', index)
@step('I see the result with words count')
def see_result(_step):
"""
Uppercasing since CSS capitalizes the headings
"""
strong_css = '.your_words strong'
target_text = set([world.css_text(strong_css, i) for i in range(2)])
assert set(['text1', 'text2']) == target_text
def add_word_cloud_to_course(course):
category = 'word_cloud'
world.ItemFactory.create(parent_location=section_location(course),
category=category,
display_name='Word Cloud')