Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions cms/static/coffee/spec/views/course_info_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ define ["js/views/course_info_handout", "js/views/course_info_update", "js/model
setFixtures($("<script>", {id: "course_info_update-tpl", type: "text/template"}).text(courseInfoTemplate))
appendSetFixtures courseInfoPage

courseUpdatesXhr = sinon.useFakeXMLHttpRequest()
@courseUpdatesRequests = requests = []
courseUpdatesXhr.onCreate = (xhr) -> requests.push(xhr)
@xhrRestore = courseUpdatesXhr.restore
@requests = requests = []
@xhr = sinon.useFakeXMLHttpRequest()
@xhr.onCreate = (xhr) -> requests.push(xhr)

@collection = new CourseUpdateCollection()
@collection.url = 'course_info_update/'
Expand Down Expand Up @@ -92,7 +91,7 @@ define ["js/views/course_info_handout", "js/views/course_info_update", "js/model
modalCover.click()

afterEach ->
@xhrRestore()
@xhr.restore()

it "does not rewrite links on save", ->
# Create a new update, verifying that the model is created
Expand All @@ -109,7 +108,7 @@ define ["js/views/course_info_handout", "js/views/course_info_update", "js/model
expect(model.save).toHaveBeenCalled()

# Verify content sent to server does not have rewritten links.
contentSaved = JSON.parse(@courseUpdatesRequests[@courseUpdatesRequests.length - 1].requestBody).content
contentSaved = JSON.parse(@requests[@requests.length - 1].requestBody).content
expect(contentSaved).toEqual('/static/image.jpg')

it "does rewrite links for preview", ->
Expand Down Expand Up @@ -146,10 +145,9 @@ define ["js/views/course_info_handout", "js/views/course_info_update", "js/model
setFixtures($("<script>", {id: "course_info_handouts-tpl", type: "text/template"}).text(handoutsTemplate))
appendSetFixtures courseInfoPage

courseHandoutsXhr = sinon.useFakeXMLHttpRequest()
@handoutsRequests = requests = []
courseHandoutsXhr.onCreate = (xhr) -> requests.push(xhr)
@handoutsXhrRestore = courseHandoutsXhr.restore
@requests = requests = []
@xhr = sinon.useFakeXMLHttpRequest()
@xhr.onCreate = (xhr) -> requests.push(xhr)

@model = new ModuleInfo({
id: 'handouts-id',
Expand All @@ -165,7 +163,7 @@ define ["js/views/course_info_handout", "js/views/course_info_update", "js/model
@handoutsEdit.render()

afterEach ->
@handoutsXhrRestore()
@xhr.restore()

it "does not rewrite links on save", ->
# Enter something in the handouts section, verifying that the model is saved
Expand All @@ -176,7 +174,7 @@ define ["js/views/course_info_handout", "js/views/course_info_update", "js/model
@handoutsEdit.$el.find('.save-button').click()
expect(@model.save).toHaveBeenCalled()

contentSaved = JSON.parse(@handoutsRequests[@handoutsRequests.length - 1].requestBody).data
contentSaved = JSON.parse(@requests[@requests.length - 1].requestBody).data
expect(contentSaved).toEqual('/static/image.jpg')

it "does rewrite links in initial content", ->
Expand Down Expand Up @@ -214,4 +212,4 @@ define ["js/views/course_info_handout", "js/views/course_info_update", "js/model
expect($('.edit-handouts-form').is(':hidden')).toEqual(true)
@handoutsEdit.$el.find('.edit-button').click()
expect(@handoutsEdit.$codeMirror.getValue()).toEqual('<p><a href="[URL OF FILE]>[LINK TEXT]</a></p>')
expect($('.edit-handouts-form').is(':hidden')).toEqual(false)
expect($('.edit-handouts-form').is(':hidden')).toEqual(false)
2 changes: 1 addition & 1 deletion cms/static/coffee/spec/views/overview_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ define ["js/views/overview", "js/views/feedback_notification", "sinon", "js/base
)
expect($('#subsection-2')).not.toHaveClass('collapsed')

xdescribe "AJAX", ->
describe "AJAX", ->
beforeEach ->
@requests = requests = []
@xhr = sinon.useFakeXMLHttpRequest()
Expand Down