Update unit tests.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<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>
|
||||
|
||||
@@ -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)', ->
|
||||
visualEditorStub =
|
||||
isDirty: () -> true
|
||||
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', ->
|
||||
it 'Returns data from Visual Editor if Visual Editor is dirty', ->
|
||||
visualEditorStub =
|
||||
isDirty: () -> true
|
||||
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 'Returns data from Visual Editor even if Visual Editor is not dirty', ->
|
||||
visualEditorStub =
|
||||
isDirty: () -> false
|
||||
getContent: () -> 'from visual editor'
|
||||
spyOn(@descriptor, 'getVisualEditor').andCallFake () ->
|
||||
visualEditorStub
|
||||
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')
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user