Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
28dc8e0e
Commit
28dc8e0e
authored
Mar 18, 2014
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update unit tests.
parent
7ac1e7bb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
95 deletions
+15
-95
common/lib/xmodule/xmodule/js/fixtures/html-edit-formattingbug.html
+1
-0
common/lib/xmodule/xmodule/js/spec/html/edit_spec.coffee
+12
-85
common/lib/xmodule/xmodule/js/src/html/edit.coffee
+2
-10
No files found.
common/lib/xmodule/xmodule/js/fixtures/html-edit-formattingbug.html
View file @
28dc8e0e
<section
class=
"html-edit"
>
<textarea
class=
"tiny-mce"
>
dummy
</textarea>
<!--
TODO: DELETE THIS FILE
The text passed in is the escaped version of
<problem>
<p></p>
...
...
common/lib/xmodule/xmodule/js/spec/html/edit_spec.coffee
View file @
28dc8e0e
...
...
@@ -3,53 +3,24 @@ describe 'HTMLEditingDescriptor', ->
window
.
baseUrl
=
"/static/deadbeef"
afterEach
->
delete
window
.
baseUrl
describe
'Read data from server, create Editor, and get data back out'
,
->
it
'Does not munge <'
,
->
# This is a test for Lighthouse #22,
# "html names are automatically converted to the symbols they describe"
# A better test would be a Selenium test to avoid duplicating the
# mako template structure in html-edit-formattingbug.html.
# However, we currently have no working Selenium tests.
loadFixtures
'html-edit-formattingbug.html'
@
descriptor
=
new
HTMLEditingDescriptor
(
$
(
'.html-edit'
))
visualEditorStub
=
isDirty
:
()
->
false
spyOn
(
@
descriptor
,
'getVisualEditor'
).
andCallFake
()
->
visualEditorStub
data
=
@
descriptor
.
save
().
data
expect
(
data
).
toEqual
(
"""<problem>
<p></p>
<multiplechoiceresponse>
<pre><problem>
<p></p></pre>
<div><foo>bar</foo></div>"""
)
describe
'Saves HTML'
,
->
describe
'HTML Editor'
,
->
beforeEach
->
loadFixtures
'html-edit.html'
@
descriptor
=
new
HTMLEditingDescriptor
(
$
(
'.html-edit'
))
it
'Returns data from Advanced Editor if Visual Editor is not dirty'
,
->
visualEditorStub
=
isDirty
:
()
->
false
spyOn
(
@
descriptor
,
'getVisualEditor'
).
andCallFake
()
->
visualEditorStub
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
data
=
@
descriptor
.
save
().
data
expect
(
data
).
toEqual
(
'Advanced Editor Text'
)
it
'Returns data from Advanced Editor if Visual Editor is not showing (even if Visual Editor is dirty)'
,
->
it
'Returns data from Visual Editor if Visual Editor is dirty'
,
->
visualEditorStub
=
isDirty
:
()
->
true
getContent
:
()
->
'from visual editor'
spyOn
(
@
descriptor
,
'getVisualEditor'
).
andCallFake
()
->
visualEditorStub
@
descriptor
.
showingVisualEditor
=
false
data
=
@
descriptor
.
save
().
data
expect
(
data
).
toEqual
(
'
Advanced Editor Text
'
)
it
'Returns data from Visual Editor
if Visual Editor is dirty and showing
'
,
->
expect
(
data
).
toEqual
(
'
from visual editor
'
)
it
'Returns data from Visual Editor
even if Visual Editor is not dirty
'
,
->
visualEditorStub
=
isDirty
:
()
->
tru
e
isDirty
:
()
->
fals
e
getContent
:
()
->
'from visual editor'
spyOn
(
@
descriptor
,
'getVisualEditor'
).
andCallFake
()
->
visualEditorStub
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
data
=
@
descriptor
.
save
().
data
expect
(
data
).
toEqual
(
'from visual editor'
)
it
'Performs link rewriting for static assets when saving'
,
->
...
...
@@ -58,63 +29,19 @@ describe 'HTMLEditingDescriptor', ->
getContent
:
()
->
'from visual editor with /c4x/foo/bar/asset/image.jpg'
spyOn
(
@
descriptor
,
'getVisualEditor'
).
andCallFake
()
->
visualEditorStub
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
@
descriptor
.
base_asset_url
=
'/c4x/foo/bar/asset/'
data
=
@
descriptor
.
save
().
data
expect
(
data
).
toEqual
(
'from visual editor with /static/image.jpg'
)
describe
'Can switch to Advanced Editor'
,
->
beforeEach
->
loadFixtures
'html-edit.html'
@
descriptor
=
new
HTMLEditingDescriptor
(
$
(
'.html-edit'
))
it
'Populates from Visual Editor if Advanced Visual is dirty'
,
->
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
visualEditorStub
=
isDirty
:
()
->
true
getContent
:
()
->
'from visual editor'
@
descriptor
.
showAdvancedEditor
(
visualEditorStub
)
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
false
)
expect
(
@
descriptor
.
advanced_editor
.
getValue
()).
toEqual
(
'from visual editor'
)
it
'Does not populate from Visual Editor if Visual Editor is not dirty'
,
->
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
visualEditorStub
=
isDirty
:
()
->
false
getContent
:
()
->
'from visual editor'
@
descriptor
.
showAdvancedEditor
(
visualEditorStub
)
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
false
)
expect
(
@
descriptor
.
advanced_editor
.
getValue
()).
toEqual
(
'Advanced Editor Text'
)
describe
'Can switch to Visual Editor'
,
->
it
'Always populates from the Advanced Editor'
,
->
loadFixtures
'html-edit.html'
@
descriptor
=
new
HTMLEditingDescriptor
(
$
(
'.html-edit'
))
@
descriptor
.
showingVisualEditor
=
false
visualEditorStub
=
content
:
'not set'
startContent
:
'not set'
,
focus
:
()
->
true
isDirty
:
()
->
false
setContent
:
(
x
)
->
@
content
=
x
getContent
:
->
@
content
@
descriptor
.
showVisualEditor
(
visualEditorStub
)
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
expect
(
visualEditorStub
.
getContent
()).
toEqual
(
'Advanced Editor Text'
)
expect
(
visualEditorStub
.
startContent
).
toEqual
(
'Advanced Editor Text'
)
it
'When switching to visual editor links are rewritten to c4x format'
,
->
loadFixtures
'html-edit-with-links.html'
it
'When showing visual editor links are rewritten to c4x format'
,
->
@
descriptor
=
new
HTMLEditingDescriptor
(
$
(
'.html-edit'
))
@
descriptor
.
base_asset_url
=
'/c4x/foo/bar/asset/'
@
descriptor
.
showingVisualEditor
=
false
visualEditorStub
=
content
:
'not set'
startContent
:
'not set'
,
focus
:
()
->
true
isDirty
:
()
->
false
content
:
'text /static/image.jpg'
startContent
:
'text /static/image.jpg'
focus
:
->
setContent
:
(
x
)
->
@
content
=
x
getContent
:
->
@
content
@
descriptor
.
showVisualEditor
(
visualEditorStub
)
expect
(
@
descriptor
.
showingVisualEditor
).
toEqual
(
true
)
expect
(
visualEditorStub
.
getContent
()).
toEqual
(
'Advanced Editor Text with link /c4x/foo/bar/asset/dummy.jpg'
)
expect
(
visualEditorStub
.
startContent
).
toEqual
(
'Advanced Editor Text with link /c4x/foo/bar/asset/dummy.jpg'
)
@
descriptor
.
initInstanceCallback
(
visualEditorStub
)
expect
(
visualEditorStub
.
getContent
()).
toEqual
(
'text /c4x/foo/bar/asset/image.jpg'
)
common/lib/xmodule/xmodule/js/src/html/edit.coffee
View file @
28dc8e0e
...
...
@@ -58,9 +58,6 @@ class @HTMLEditingDescriptor
image
:
"
#{
baseUrl
}
/images/ico-tinymce-code.png"
,
onclick
:
()
->
ed
.
formatter
.
toggle
(
'code'
)
# Without this, the dirty flag does not get set unless the user also types in text.
# Visual Editor must be marked as dirty or else we won't populate the Advanced Editor from it.
ed
.
isNotDirty
=
false
})
@
visualEditor
=
ed
...
...
@@ -86,18 +83,14 @@ class @HTMLEditingDescriptor
initInstanceCallback
:
(
visualEditor
)
=>
@
rewriteLinksFromStatic
(
visualEditor
)
@
focusVisualEditor
(
visualEditor
)
visualEditor
.
focus
(
)
rewriteLinksFromStatic
:
(
visualEditor
)
=>
visualEditor
.
setContent
(
rewriteStaticLinks
(
visualEditor
.
getContent
({
no_events
:
1
}),
'/static/'
,
@
base_asset_url
))
focusVisualEditor
:
(
visualEditor
)
=>
visualEditor
.
focus
()
getVisualEditor
:
()
->
###
Returns the instance of TinyMCE.
This is different from the textarea that exists in the HTML template (@tiny_mce_textarea.
Pulled out as a helper method for unit test.
###
...
...
@@ -105,6 +98,5 @@ class @HTMLEditingDescriptor
save
:
->
visualEditor
=
@
getVisualEditor
()
if
visualEditor
.
isDirty
()
text
=
rewriteStaticLinks
(
visualEditor
.
getContent
({
no_events
:
1
}),
@
base_asset_url
,
'/static/'
)
text
=
rewriteStaticLinks
(
visualEditor
.
getContent
({
no_events
:
1
}),
@
base_asset_url
,
'/static/'
)
data
:
text
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