Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
problem-builder
Commits
b63d2bfd
Commit
b63d2bfd
authored
Oct 17, 2015
by
Braden MacDonald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for the slider block, plus fix title
parent
772c1f26
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
177 additions
and
1 deletions
+177
-1
problem_builder/slider.py
+1
-0
problem_builder/templates/html/slider.html
+1
-1
problem_builder/tests/integration/test_slider.py
+147
-0
problem_builder/tests/integration/xml_templates/slider_problem.xml
+12
-0
problem_builder/tests/integration/xml_templates/slider_step.xml
+16
-0
No files found.
problem_builder/slider.py
View file @
b63d2bfd
...
@@ -94,6 +94,7 @@ class SliderBlock(
...
@@ -94,6 +94,7 @@ class SliderBlock(
context
[
'initial_value'
]
=
int
(
self
.
student_value
*
100
)
if
self
.
student_value
is
not
None
else
50
context
[
'initial_value'
]
=
int
(
self
.
student_value
*
100
)
if
self
.
student_value
is
not
None
else
50
context
[
'min_label'
]
=
self
.
min_label
context
[
'min_label'
]
=
self
.
min_label
context
[
'max_label'
]
=
self
.
max_label
context
[
'max_label'
]
=
self
.
max_label
context
[
'title'
]
=
self
.
display_name_with_default
context
[
'hide_header'
]
=
context
.
get
(
'hide_header'
,
False
)
or
not
self
.
show_title
context
[
'hide_header'
]
=
context
.
get
(
'hide_header'
,
False
)
or
not
self
.
show_title
context
[
'instructions_string'
]
=
self
.
_
(
"Select a value from {min_label} to {max_label}"
)
.
format
(
context
[
'instructions_string'
]
=
self
.
_
(
"Select a value from {min_label} to {max_label}"
)
.
format
(
min_label
=
self
.
min_label
,
max_label
=
self
.
max_label
min_label
=
self
.
min_label
,
max_label
=
self
.
max_label
...
...
problem_builder/templates/html/slider.html
View file @
b63d2bfd
<div
class=
"xblock-pb-slider"
>
<div
class=
"xblock-pb-slider"
>
{% if not hide_header %}
<h3
class=
"question-title"
>
{{
self.display_name_with_default
}}
</h3>
{% endif %}
{% if not hide_header %}
<h3
class=
"question-title"
>
{{
title
}}
</h3>
{% endif %}
{% if question %}
{% if question %}
<p><label
for=
"{{slider_id}}"
>
{{ question|safe }}
<span
class=
"sr"
>
({{instructions_string}})
</span></label></p>
<p><label
for=
"{{slider_id}}"
>
{{ question|safe }}
<span
class=
"sr"
>
({{instructions_string}})
</span></label></p>
{% endif %}
{% endif %}
...
...
problem_builder/tests/integration/test_slider.py
0 → 100644
View file @
b63d2bfd
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014-2015 Harvard, edX & OpenCraft
#
# This software's license gives you freedom; you can copy, convey,
# propagate, redistribute and/or modify this program under the terms of
# the GNU Affero General Public License (AGPL) as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version of the AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
# Imports ###########################################################
from
.base_test
import
ProblemBuilderBaseTest
,
MentoringAssessmentBaseTest
,
CORRECT
,
GetChoices
# Classes ###########################################################
class
SliderBlockTestMixins
(
object
):
""" Mixins for testing slider blocks. Assumes only one slider block is on the page. """
def
get_slider_value
(
self
):
return
int
(
self
.
browser
.
execute_script
(
"return $('.pb-slider-range').val()"
))
def
set_slider_value
(
self
,
val
):
self
.
browser
.
execute_script
(
"$('.pb-slider-range').val(arguments[0]).change()"
,
val
)
class
SliderBlockTest
(
SliderBlockTestMixins
,
ProblemBuilderBaseTest
):
"""
Tests for the SliderBlock inside a normal Problem Builder block.
"""
def
test_simple_flow
(
self
):
""" Test a regular Problem Builder block containing one slider """
pb_wrapper
=
self
.
load_scenario
(
"slider_problem.xml"
,
{
"include_mcq"
:
False
})
self
.
wait_for_init
()
# The initial value should be 50 and submit should be enabled since 50 is a valid value:
self
.
assertTrue
(
self
.
submit_button
.
is_enabled
())
self
.
assertEqual
(
self
.
get_slider_value
(),
50
)
self
.
expect_checkmark_visible
(
False
)
# Set the value to 75:
self
.
set_slider_value
(
75
)
self
.
assertEqual
(
self
.
get_slider_value
(),
75
)
self
.
click_submit
(
pb_wrapper
)
# Now, we expect submit to be disabled and the checkmark to be visible:
self
.
expect_checkmark_visible
(
True
)
self
.
assertFalse
(
self
.
submit_button
.
is_enabled
())
# Now change the value, and the button/checkmark should reset:
self
.
set_slider_value
(
45
)
self
.
assertTrue
(
self
.
submit_button
.
is_enabled
())
self
.
expect_checkmark_visible
(
False
)
# Now reload the page:
self
.
browser
.
execute_script
(
"$(document).html(' ');"
)
pb_wrapper
=
self
.
go_to_view
(
"student_view"
)
self
.
wait_for_init
()
# Now the initial value should be 75 and submit should be disabled (to discourage submitting the same answer):
self
.
assertEqual
(
self
.
get_slider_value
(),
75
)
self
.
assertFalse
(
self
.
submit_button
.
is_enabled
())
self
.
expect_checkmark_visible
(
True
)
def
test_simple_flow_with_peer
(
self
):
""" Test a regular Problem Builder block containing one slider and an MCQ """
pb_wrapper
=
self
.
load_scenario
(
"slider_problem.xml"
,
{
"include_mcq"
:
True
})
self
.
wait_for_init
()
# The initial value should be 50 and submit should be disabled until an MCQ choice is selected
self
.
assertEqual
(
self
.
get_slider_value
(),
50
)
self
.
assertFalse
(
self
.
submit_button
.
is_enabled
())
self
.
expect_checkmark_visible
(
False
)
# Set the value to 15:
self
.
set_slider_value
(
15
)
self
.
assertEqual
(
self
.
get_slider_value
(),
15
)
self
.
assertFalse
(
self
.
submit_button
.
is_enabled
())
# Choose a choice:
mcq_choices
=
pb_wrapper
.
find_elements_by_css_selector
(
'.choices .choice input'
)
mcq_choices
[
0
]
.
click
()
self
.
assertTrue
(
self
.
submit_button
.
is_enabled
())
self
.
click_submit
(
pb_wrapper
)
# Now, we expect submit to be disabled and the checkmark to be visible:
self
.
expect_checkmark_visible
(
True
)
self
.
assertFalse
(
self
.
submit_button
.
is_enabled
())
# Now change the value, and the button/checkmark should reset:
self
.
set_slider_value
(
20
)
self
.
assertTrue
(
self
.
submit_button
.
is_enabled
())
self
.
expect_checkmark_visible
(
False
)
def
wait_for_init
(
self
):
""" Wait for the scenario to initialize """
self
.
wait_until_hidden
(
self
.
browser
.
find_element_by_css_selector
(
'.messages'
))
@property
def
submit_button
(
self
):
return
self
.
browser
.
find_element_by_css_selector
(
'.submit input.input-main'
)
def
expect_checkmark_visible
(
self
,
visible
):
checkmark
=
self
.
browser
.
find_element_by_css_selector
(
'.xblock-pb-slider .submit-result'
)
self
.
assertEqual
(
checkmark
.
is_displayed
(),
visible
)
class
SliderStepBlockTest
(
SliderBlockTestMixins
,
MentoringAssessmentBaseTest
):
"""
Tests for the SliderBlock inside a Step Builder block.
"""
def
test_step_with_slider
(
self
):
""" Test a regular Step Builder block containing one slider and an MCQ """
step_builder
,
controls
=
self
.
load_assessment_scenario
(
"slider_step.xml"
)
self
.
wait_for_init
()
self
.
assertEqual
(
self
.
get_slider_value
(),
50
)
# Check step 1 (the slider step):
question
=
self
.
expect_question_visible
(
1
,
step_builder
,
question_text
=
"Information Reliability"
)
self
.
assertIn
(
"How reliable is this information?"
,
question
.
text
)
self
.
assertIn
(
"Select a value from 0
%
to 100
%
"
,
question
.
text
)
# Screen reader explanation
self
.
assertTrue
(
controls
.
submit
.
is_enabled
())
self
.
assert_hidden
(
controls
.
try_again
)
self
.
set_slider_value
(
99
)
controls
.
submit
.
click
()
self
.
do_submit_wait
(
controls
,
last
=
False
)
self
.
wait_until_clickable
(
controls
.
next_question
)
controls
.
next_question
.
click
()
# Submit step 2:
question
=
self
.
expect_question_visible
(
2
,
step_builder
)
GetChoices
(
question
)
.
select
(
"Yes"
)
controls
.
submit
.
click
()
self
.
do_submit_wait
(
controls
,
last
=
True
)
self
.
wait_until_clickable
(
controls
.
review
)
controls
.
review
.
click
()
self
.
wait_until_visible
(
controls
.
try_again
)
# You can't get a slider question wrong, but it does count as one correct point by default:
self
.
assertIn
(
"You answered 2 questions correctly"
,
step_builder
.
text
)
def
wait_for_init
(
self
):
""" Wait for the scenario to initialize """
self
.
wait_until_hidden
(
self
.
browser
.
find_element_by_css_selector
(
'.assessment-review-tips'
))
problem_builder/tests/integration/xml_templates/slider_problem.xml
0 → 100644
View file @
b63d2bfd
<problem-builder
url_name=
"pb_with_slider"
>
<pb-slider
name=
"slider_1"
question=
"How much do you like pizza?"
min_label=
"A little"
max_label=
"A lot"
/>
{% if include_mcq %}
<pb-mcq
name=
"mcq_2"
question=
"Do you like this MCQ?"
correct_choices=
'["yes"]'
>
<pb-choice
value=
"yes"
>
Yes
</pb-choice>
<pb-choice
value=
"maybenot"
>
Maybe not
</pb-choice>
<pb-choice
value=
"understand"
>
I don't understand
</pb-choice>
</pb-mcq>
{% endif %}
</problem-builder>
problem_builder/tests/integration/xml_templates/slider_step.xml
0 → 100644
View file @
b63d2bfd
<step-builder
display_name=
"Step Builder"
max_attempts=
"90"
>
<sb-step
display_name=
"Slider step"
>
<pb-slider
name=
"slider_1"
display_name=
"Information Reliability"
question=
"How reliable is this information?"
min_label=
"0%"
max_label=
"100%"
/>
</sb-step>
<sb-step
display_name=
"MCQ step"
>
<pb-mcq
name=
"mcq"
display_name=
"Question 2"
question=
"Do you like this MCQ?"
correct_choices=
'["yes"]'
>
<pb-choice
value=
"yes"
>
Yes
</pb-choice>
<pb-choice
value=
"no"
>
No
</pb-choice>
</pb-mcq>
</sb-step>
<sb-review-step/>
</step-builder>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment