Merge pull request #19524 from edx/awais/lett_2_bc_problem_editor_II
Problem Editor bokchoy tests II(remaining tests)
This commit is contained in:
@@ -28,19 +28,56 @@ class ProblemXBlockEditorView(XBlockEditorView):
|
||||
script = "$(arguments[0]).val(arguments[1]).change();"
|
||||
self.browser.execute_script(script, selector, field_value)
|
||||
|
||||
def get_field_val(self, field_display_name):
|
||||
"""
|
||||
If editing, get the value of field
|
||||
|
||||
Args:
|
||||
field_display_name(str): Name of the field for which the value is required
|
||||
Returns:
|
||||
(string): Value of the field
|
||||
"""
|
||||
script = "return $('.wrapper-comp-setting label:contains({}) + input').val();".format(field_display_name)
|
||||
return self.browser.execute_script(script)
|
||||
|
||||
def get_default_dropdown_value(self, css):
|
||||
"""
|
||||
Gets default value from the dropdown
|
||||
Arguments:
|
||||
Args:
|
||||
css(string): css of the dropdown for which default value is required
|
||||
Returns:
|
||||
dropdown_value(string): Default dropdown value
|
||||
value(string): Default dropdown value
|
||||
"""
|
||||
element = self.browser.find_element_by_css_selector(css)
|
||||
dropdown_default_selection = Select(element)
|
||||
value = dropdown_default_selection.first_selected_option.text
|
||||
return value
|
||||
|
||||
def select_from_dropdown(self, dropdown_name, value):
|
||||
"""
|
||||
Selects from the dropdown
|
||||
Arguments:
|
||||
dropdown_name(string): Name of the dropdown to be opened
|
||||
value(string): Value to be selected
|
||||
"""
|
||||
self.q(css='select[class="input setting-input"][name="{}"]'.format(dropdown_name)).first.click()
|
||||
self.wait_for_element_visibility('option[value="{}"]'.format(value), 'Dropdown is visible')
|
||||
self.q(css='option[value="{}"]'.format(value)).click()
|
||||
|
||||
def get_value_from_the_dropdown(self, dropdown_name):
|
||||
"""
|
||||
Get selected value from the dropdown
|
||||
Args:
|
||||
dropdown_name(string): Name of the dropdown
|
||||
Returns:
|
||||
(string): Selected Value from the dropdown
|
||||
|
||||
"""
|
||||
dropdown = self.browser.find_element_by_css_selector(
|
||||
'select[class="input setting-input"][name="{}"]'.format(dropdown_name)
|
||||
)
|
||||
return Select(dropdown).first_selected_option.text
|
||||
|
||||
def get_settings(self):
|
||||
"""
|
||||
Default settings of problem
|
||||
@@ -61,6 +98,30 @@ class ProblemXBlockEditorView(XBlockEditorView):
|
||||
|
||||
return settings_dict
|
||||
|
||||
def revert_setting(self, display_name=False):
|
||||
"""
|
||||
Click to revert setting to default
|
||||
"""
|
||||
if display_name:
|
||||
self.q(css='.action.setting-clear.active').first.click()
|
||||
else:
|
||||
self.q(css='.action.setting-clear.active').results[1].click()
|
||||
|
||||
def toggle_cheatsheet(self):
|
||||
"""
|
||||
Toggle cheatsheet on toolbar
|
||||
"""
|
||||
self.q(css='.cheatsheet-toggle').first.click()
|
||||
self.wait_for_element_visibility('.simple-editor-cheatsheet.shown', 'Cheatsheet is visible')
|
||||
|
||||
def is_cheatsheet_present(self):
|
||||
"""
|
||||
Check for cheatsheet presence
|
||||
Returns:
|
||||
bool: True if present
|
||||
"""
|
||||
return self.q(css='.simple-editor-cheatsheet.shown').present
|
||||
|
||||
def is_latex_compiler_present(self):
|
||||
"""
|
||||
Checks for the presence of latex compiler settings
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Acceptance tests for Problem component in studio
|
||||
"""
|
||||
from common.test.acceptance.tests.helpers import skip_if_browser
|
||||
from common.test.acceptance.tests.studio.base_studio_test import ContainerBase
|
||||
from common.test.acceptance.fixtures.course import XBlockFixtureDesc
|
||||
from common.test.acceptance.pages.studio.container import ContainerPage
|
||||
@@ -74,7 +75,7 @@ class ProblemComponentEditor(ContainerBase):
|
||||
self.problem_editor.set_field_val('Display Name', 'New Name')
|
||||
self.problem_editor.save()
|
||||
component_name = self.unit.xblock_titles[0]
|
||||
self.assertEqual(component_name, 'New Name')
|
||||
self.assertEqual(component_name, 'New Name', 'Component Name is not same as the new name')
|
||||
|
||||
def test_user_can_specify_special_characters(self):
|
||||
"""
|
||||
@@ -88,4 +89,178 @@ class ProblemComponentEditor(ContainerBase):
|
||||
self.problem_editor.set_field_val('Display Name', '&&&')
|
||||
self.problem_editor.save()
|
||||
component_name = self.unit.xblock_titles[0]
|
||||
self.assertEqual(component_name, '&&&')
|
||||
self.assertEqual(component_name, '&&&', 'Component Name is not same as the new name')
|
||||
|
||||
def test_user_can_revert_display_name_to_unset(self):
|
||||
"""
|
||||
Scenario: User can revert display name to unset
|
||||
Given I have created a Blank Common Problem
|
||||
When I edit and select Settings
|
||||
Then I can revert the display name to unset
|
||||
And my display name is unset on save
|
||||
"""
|
||||
self.problem_editor.open_settings()
|
||||
self.problem_editor.set_field_val('Display Name', 'New Name')
|
||||
self.problem_editor.save()
|
||||
|
||||
# reopen settings
|
||||
self.container_page.edit()
|
||||
self.problem_editor.open_settings()
|
||||
|
||||
self.problem_editor.revert_setting(display_name=True)
|
||||
self.problem_editor.save()
|
||||
component_name = self.unit.xblock_titles[0]
|
||||
self.assertEqual(component_name, 'Blank Advanced Problem', 'Component Name is not reverted to default name')
|
||||
|
||||
def test_user_can_set_html_in_display_name(self):
|
||||
"""
|
||||
Scenario: User can specify html in display name and it will be escaped
|
||||
Given I have created a Blank Common Problem
|
||||
When I edit and select Settings
|
||||
Then I can specify html in the display name and save
|
||||
And the problem display name is "<script>alert('test')</script>"
|
||||
"""
|
||||
self.problem_editor.open_settings()
|
||||
self.problem_editor.set_field_val('Display Name', '<script>alert("test")</script>')
|
||||
self.problem_editor.save()
|
||||
component_name = self.unit.xblock_titles[0]
|
||||
self.assertEqual(
|
||||
component_name,
|
||||
'<script>alert("test")</script>',
|
||||
'Component Name is not same as the new name'
|
||||
)
|
||||
|
||||
def test_user_can_modify_float_input(self):
|
||||
"""
|
||||
Scenario: User can modify float input values
|
||||
Given I have created a Blank Common Problem
|
||||
When I edit and select Settings
|
||||
Then I can set the weight to "3.5"
|
||||
And my change to weight is persisted
|
||||
And I can revert to the default value of unset for weight
|
||||
"""
|
||||
self.problem_editor.open_settings()
|
||||
self.problem_editor.set_field_val('Problem Weight', '3.5')
|
||||
self.problem_editor.save()
|
||||
|
||||
# reopen settings
|
||||
self.container_page.edit()
|
||||
self.problem_editor.open_settings()
|
||||
|
||||
field_value = self.problem_editor.get_field_val('Problem Weight')
|
||||
self.assertEqual(field_value, '3.5')
|
||||
self.problem_editor.revert_setting()
|
||||
field_value = self.problem_editor.get_field_val('Problem Weight')
|
||||
self.assertEqual(field_value, '', 'Component settings is not reverted to default')
|
||||
|
||||
def test_user_cannot_type_letters(self):
|
||||
"""
|
||||
Scenario: User cannot type letters in float number field
|
||||
Given I have created a Blank Common Problem
|
||||
When I edit and select Settings
|
||||
Then if I set the weight to "abc", it remains unset
|
||||
"""
|
||||
self.problem_editor.open_settings()
|
||||
self.problem_editor.set_field_val('Problem Weight', 'abc')
|
||||
field_value = self.problem_editor.get_field_val('Problem Weight')
|
||||
self.assertEqual(field_value, '', "Only the Numerical input is allowed in this field")
|
||||
|
||||
@skip_if_browser('firefox')
|
||||
# Lettuce tests run on chrome and chrome does not allow to enter
|
||||
# periods/dots in this field and consequently we have to save the
|
||||
# value as '234'. Whereas, bokchoy runs with the older version of
|
||||
# firefox on jenkins, which does not allow to save the value if it
|
||||
# has a period/dot. Clicking on save button after filling '2.34' in
|
||||
# field, does not do anything and test does not go any further.
|
||||
# So, it fails always.
|
||||
def test_user_cannot_type_decimal_values(self):
|
||||
"""
|
||||
Scenario: User cannot type decimal values integer number field
|
||||
Given I have created a Blank Common Problem
|
||||
When I edit and select Settings
|
||||
Then if I set the max attempts to "2.34", it will persist as a valid integer
|
||||
"""
|
||||
self.problem_editor.open_settings()
|
||||
self.problem_editor.set_field_val('Maximum Attempts', '2.34')
|
||||
self.problem_editor.save()
|
||||
|
||||
# reopen settings
|
||||
self.container_page.edit()
|
||||
self.problem_editor.open_settings()
|
||||
|
||||
field_value = self.problem_editor.get_field_val('Maximum Attempts')
|
||||
self.assertEqual(field_value, '234', "Decimal values are not allowed in this field")
|
||||
|
||||
def test_user_cannot_type_out_of_range_values(self):
|
||||
"""
|
||||
Scenario: User cannot type out of range values in an integer number field
|
||||
Given I have created a Blank Common Problem
|
||||
When I edit and select Settings
|
||||
Then if I set the max attempts to "-3", it will persist as a valid integer
|
||||
"""
|
||||
self.problem_editor.open_settings()
|
||||
self.problem_editor.set_field_val('Maximum Attempts', '-3')
|
||||
self.problem_editor.save()
|
||||
|
||||
# reopen settings
|
||||
self.container_page.edit()
|
||||
self.problem_editor.open_settings()
|
||||
|
||||
field_value = self.problem_editor.get_field_val('Maximum Attempts')
|
||||
self.assertGreaterEqual(field_value, '0', "Negative values are not allowed in this field")
|
||||
|
||||
def test_settings_are_not_saved_on_cancel(self):
|
||||
"""
|
||||
Scenario: Settings changes are not saved on Cancel
|
||||
Given I have created a Blank Common Problem
|
||||
When I edit and select Settings
|
||||
Then I can set the weight to "3.5"
|
||||
And I can modify the display name
|
||||
Then If I press Cancel my changes are not persisted
|
||||
"""
|
||||
self.problem_editor.open_settings()
|
||||
self.problem_editor.set_field_val('Problem Weight', '3.5')
|
||||
self.problem_editor.cancel()
|
||||
|
||||
# reopen settings
|
||||
self.container_page.edit()
|
||||
self.problem_editor.open_settings()
|
||||
|
||||
field_value = self.problem_editor.get_field_val('Problem Weight')
|
||||
self.assertEqual(field_value, '', "Component setting should not appear updated if cancelled during editing")
|
||||
|
||||
def test_cheat_sheet_visible_on_toggle(self):
|
||||
"""
|
||||
Scenario: Cheat sheet visible on toggle
|
||||
Given I have created a Blank Common Problem
|
||||
And I can edit the problem
|
||||
Then I can see cheatsheet
|
||||
"""
|
||||
self.problem_editor.toggle_cheatsheet()
|
||||
self.assertTrue(self.problem_editor.is_cheatsheet_present(), "Cheatsheet not present")
|
||||
|
||||
def test_user_can_select_values(self):
|
||||
"""
|
||||
Scenario: User can select values in a Select
|
||||
Given I have created a Blank Common Problem
|
||||
When I edit and select Settings
|
||||
Then I can select 'Per Student' for Randomization
|
||||
And my change to randomization is persisted
|
||||
And I can revert to the default value for randomization
|
||||
"""
|
||||
dropdown_name = 'Randomization'
|
||||
self.problem_editor.open_settings()
|
||||
self.problem_editor.select_from_dropdown(dropdown_name, 'Per Student')
|
||||
self.problem_editor.save()
|
||||
|
||||
# reopen the settings
|
||||
self.container_page.edit()
|
||||
self.problem_editor.open_settings()
|
||||
|
||||
dropdown_value = self.problem_editor.get_value_from_the_dropdown(dropdown_name)
|
||||
self.assertEqual(dropdown_value, 'Per Student', "Component setting is not changed")
|
||||
|
||||
# revert settings
|
||||
self.problem_editor.revert_setting()
|
||||
dropdown_value = self.problem_editor.get_value_from_the_dropdown(dropdown_name)
|
||||
self.assertEqual(dropdown_value, 'Never', 'Component setting is not reverted to default')
|
||||
|
||||
Reference in New Issue
Block a user