Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-poll
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
edx
xblock-poll
Commits
17f35612
Commit
17f35612
authored
Jan 01, 2015
by
Jonathan Piacenti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test and Javascript refactoring.
parent
30017854
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
65 additions
and
25 deletions
+65
-25
poll/public/html/survey.html
+1
-1
poll/public/js/poll.js
+46
-17
tests/integration/test_defaults.py
+11
-3
tests/integration/test_layout.py
+2
-2
tests/integration/test_markdown.py
+2
-2
tests/integration/xml/poll_all_pictures.xml
+0
-0
tests/integration/xml/poll_defaults.xml
+0
-0
tests/integration/xml/poll_markdown.xml
+0
-0
tests/integration/xml/poll_one_picture.xml
+0
-0
tests/integration/xml/survey_defaults.xml
+3
-0
No files found.
poll/public/html/survey.html
View file @
17f35612
{{ js_template|safe }}
<div
class=
"
survey
-block"
>
<div
class=
"
poll
-block"
>
{# If no form is present, the Javascript will load the results instead. #}
{% if not choices %}
<form>
...
...
poll/public/js/poll.js
View file @
17f35612
/* Javascript for PollBlock. */
function
PollUtil
(
runtime
,
element
)
{
function
PollUtil
(
runtime
,
element
,
pollType
)
{
var
self
=
this
;
this
.
init
=
function
(
runtime
,
element
)
{
// Initialization function used for both Poll Types
this
.
voteUrl
=
runtime
.
handlerUrl
(
element
,
'vote'
);
this
.
tallyURL
=
runtime
.
handlerUrl
(
element
,
'get_results'
);
this
.
element
=
element
;
...
...
@@ -10,15 +11,21 @@ function PollUtil (runtime, element) {
this
.
submit
=
$
(
'input[type=button]'
,
element
);
this
.
answers
=
$
(
'input[type=radio]'
,
element
);
this
.
resultsTemplate
=
Handlebars
.
compile
(
$
(
"#poll-results-template"
,
element
).
html
());
var
getResults
=
this
.
getResults
();
// If the submit button doesn't exist, the user has already
// selected a choice. Render results instead of initializing machinery.
if
(
!
self
.
submit
.
length
)
{
getResults
({
'success'
:
true
});
return
false
;
}
return
true
;
};
this
.
pollInit
=
function
(){
// If the submit button doesn't exist, the user has already
// selected a choice.
var
self
=
this
;
// Initialization function for PollBlocks.
var
enableSubmit
=
self
.
enableSubmit
();
var
getResults
=
self
.
getResults
();
if
(
self
.
submit
.
length
)
{
var
radio
=
$
(
'input[name=choice]:checked'
,
self
.
element
);
self
.
submit
.
click
(
function
()
{
// Refresh.
...
...
@@ -28,27 +35,46 @@ function PollUtil (runtime, element) {
type
:
"POST"
,
url
:
self
.
voteUrl
,
data
:
JSON
.
stringify
({
"choice"
:
choice
}),
success
:
getResults
success
:
self
.
getResults
()
});
});
// If the user has refreshed the page, they may still have an answer
// selected and the submit button should be enabled.
var
answers
=
$
(
'input[type=radio]'
,
self
.
element
);
if
(
!
radio
.
val
())
{
answers
.
bind
(
"change.E
nableSubmit"
,
enableSubmit
);
answers
.
bind
(
"change.e
nableSubmit"
,
enableSubmit
);
}
else
{
enableSubmit
();
}
}
else
{
getResults
({
'success'
:
true
});
}
};
this
.
surveyInit
=
function
()
{
var
self
=
this
;
// Initialization function for Survey Blocks
var
verifyAll
=
self
.
verifyAll
();
self
.
answers
.
bind
(
"change.enableSubmit"
,
verifyAll
)
};
this
.
verifyAll
=
function
()
{
// Generates a function that will verify all questions have an answer selected.
var
self
=
this
;
var
enableSubmit
=
self
.
enableSubmit
();
return
function
()
{
var
doEnable
=
true
;
self
.
answers
.
each
(
function
(
index
,
el
)
{
if
(
!
$
(
"input[name='"
+
$
(
el
).
prop
(
'name'
)
+
"']:checked"
,
self
.
element
).
length
)
{
doEnable
=
false
;
return
false
}
});
if
(
doEnable
){
enableSubmit
();
}
}
};
this
.
getResults
=
function
()
{
// Generates a function that will grab and display results.
var
self
=
this
;
return
function
(
data
)
{
if
(
!
data
[
'success'
])
{
...
...
@@ -69,21 +95,24 @@ function PollUtil (runtime, element) {
};
this
.
enableSubmit
=
function
()
{
// Generates a function which will enable the submit button.
var
self
=
this
;
return
function
()
{
self
.
submit
.
removeAttr
(
"disabled"
);
self
.
answers
.
unbind
(
"change.
E
nableSubmit"
);
self
.
answers
.
unbind
(
"change.
e
nableSubmit"
);
}
};
this
.
init
(
runtime
,
element
);
var
run_init
=
this
.
init
(
runtime
,
element
);
if
(
run_init
)
{
var
init_map
=
{
'poll'
:
self
.
pollInit
,
'survey'
:
self
.
surveyInit
};
init_map
[
pollType
].
call
(
self
)
}
}
function
PollBlock
(
runtime
,
element
)
{
var
util
=
new
PollUtil
(
runtime
,
element
);
util
.
pollInit
();
new
PollUtil
(
runtime
,
element
,
'poll'
);
}
function
SurveyBlock
(
runtime
,
element
)
{
var
util
=
new
PollUtil
(
runtime
,
element
);
util
.
surveyInit
();
new
PollUtil
(
runtime
,
element
,
'survey'
);
}
tests/integration/test_defaults.py
View file @
17f35612
...
...
@@ -7,9 +7,9 @@ from selenium.common.exceptions import NoSuchElementException
from
.base_test
import
PollBaseTest
class
TestDefault
s
(
PollBaseTest
):
class
TestDefault
(
PollBaseTest
):
"""
Tests to run against the default
poll
.
Tests to run against the default
XBlock configurations
.
"""
def
test_default_poll
(
self
):
"""
...
...
@@ -17,7 +17,7 @@ class TestDefaults(PollBaseTest):
the tally displays afterward. Verifies that the feedback section does
not load since it is not enabled by default.
"""
self
.
go_to_page
(
'Defaults'
)
self
.
go_to_page
(
'
Poll
Defaults'
)
button
=
self
.
browser
.
find_element_by_css_selector
(
'input[type=radio]'
)
button
.
click
()
submit
=
self
.
get_submit
()
...
...
@@ -30,3 +30,11 @@ class TestDefaults(PollBaseTest):
# No feedback section.
self
.
assertRaises
(
NoSuchElementException
,
self
.
browser
.
find_element_by_css_selector
,
'.poll-feedback'
)
def
test_default_survey
(
self
):
"""
Verifies that a default survey loads, that it can be voted on, and
that the tally displays afterward. Verifies that the feedback section
does not load since it is not enabled by default.
"""
self
.
go_to_page
(
'Survey Defaults'
)
tests/integration/test_layout.py
View file @
17f35612
...
...
@@ -16,7 +16,7 @@ class TestLayout(PollBaseTest):
"""
Verify img tags are created for answers when they're all set.
"""
self
.
go_to_page
(
'All Pictures'
)
self
.
go_to_page
(
'
Poll
All Pictures'
)
pics
=
self
.
browser
.
find_elements_by_css_selector
(
'.poll-image'
)
self
.
assertEqual
(
len
(
pics
),
4
)
...
...
@@ -32,7 +32,7 @@ class TestLayout(PollBaseTest):
"""
Verify layout is sane when only one answer has an image.
"""
self
.
go_to_page
(
'One Picture'
)
self
.
go_to_page
(
'
Poll
One Picture'
)
pics
=
self
.
browser
.
find_elements_by_css_selector
(
'.poll-image'
)
# On the polling page, there should only be one pics div.
self
.
assertEqual
(
len
(
pics
),
1
)
...
...
tests/integration/test_markdown.py
View file @
17f35612
...
...
@@ -12,7 +12,7 @@ class MarkdownTestCase(PollBaseTest):
"""
Ensure Markdown is parsed for questions.
"""
self
.
go_to_page
(
"Markdown"
)
self
.
go_to_page
(
"
Poll
Markdown"
)
self
.
assertEqual
(
self
.
browser
.
find_element_by_css_selector
(
'.poll-question-container'
)
.
text
,
"""This is a test
...
...
@@ -30,7 +30,7 @@ We shall find out if markdown is respected.
"""
Ensure Markdown is parsed for feedback.
"""
self
.
go_to_page
(
"Markdown"
)
self
.
go_to_page
(
"
Poll
Markdown"
)
self
.
browser
.
find_element_by_css_selector
(
'input[type=radio]'
)
.
click
()
self
.
get_submit
()
.
click
()
...
...
tests/integration/xml/all_pictures.xml
→
tests/integration/xml/
poll_
all_pictures.xml
View file @
17f35612
File moved
tests/integration/xml/defaults.xml
→
tests/integration/xml/
poll_
defaults.xml
View file @
17f35612
File moved
tests/integration/xml/markdown.xml
→
tests/integration/xml/
poll_
markdown.xml
View file @
17f35612
File moved
tests/integration/xml/one_picture.xml
→
tests/integration/xml/
poll_
one_picture.xml
View file @
17f35612
File moved
tests/integration/xml/survey_defaults.xml
0 → 100644
View file @
17f35612
<vertical_demo>
<survey
url_name=
"defaults"
/>
</vertical_demo>
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