Files
edx-platform/cms/static/coffee/spec/main_spec.coffee
Brian Jacobel 4f0aee3f2d Fix unit and acceptance tests broken in upgrade (squashed)
Fix syntax error in selectors

.attr() now returns a string (though it can still be passed an integer)

Fixes checkbox test failures

Remove remaining references to jquery.min (in wrong folder)

$.ajax now returns 422 if type is json and body is not JSON, e.g. ''

Substitute prop for attr

Remove references to jquery.min, add jquery.migrate (again)

"Fix" jquery karma config

This wasn't suppoed to survive the merge

This throws an error when called with an 'undefined' error

Fix Karma warning about [re|un]loading the window

Fix path for jquery in cms-squire tests

Move jasmine.clock.uninstall() to afterEach so it runs even on failure

Fix test failing due to timezone issues

Do the timeout before the window scrolling (so handler will not be _.throttled)

Fix an alert() triggered by window.onBeforeUnload while testing in Chrome
2016-05-24 16:53:57 -04:00

61 lines
2.1 KiB
CoffeeScript

require ["jquery", "backbone", "coffee/src/main", "common/js/spec_helpers/ajax_helpers", "jquery.cookie"],
($, Backbone, main, AjaxHelpers) ->
describe "CMS", ->
it "should initialize URL", ->
expect(window.CMS.URL).toBeDefined()
describe "main helper", ->
beforeEach ->
@previousAjaxSettings = $.extend(true, {}, $.ajaxSettings)
spyOn($, "cookie").and.callFake(
(param) ->
if param == "csrftoken"
return "stubCSRFToken"
)
main()
afterEach ->
$.ajaxSettings = @previousAjaxSettings
it "turn on Backbone emulateHTTP", ->
expect(Backbone.emulateHTTP).toBeTruthy()
it "setup AJAX CSRF token", ->
expect($.ajaxSettings.headers["X-CSRFToken"]).toEqual("stubCSRFToken")
describe "AJAX Errors", ->
server = null
beforeEach ->
appendSetFixtures(sandbox({id: "page-notification"}))
afterEach ->
server && server.restore()
it "successful AJAX request does not pop an error notification", ->
server = AjaxHelpers.server([200, {"Content-Type": "application/json"}, "{}"])
expect($("#page-notification")).toBeEmpty()
$.ajax("/test")
expect($("#page-notification")).toBeEmpty()
server.respond()
expect($("#page-notification")).toBeEmpty()
it "AJAX request with error should pop an error notification", ->
server = AjaxHelpers.server([500, {"Content-Type": "application/json"}, "{}"])
$.ajax("/test")
server.respond()
expect($("#page-notification")).not.toBeEmpty()
expect($("#page-notification")).toContainElement('div.wrapper-notification-error')
it "can override AJAX request with error so it does not pop an error notification", ->
server = AjaxHelpers.server([500, {"Content-Type": "application/json"}, "{}"])
$.ajax
url: "/test"
notifyOnError: false
server.respond()
expect($("#page-notification")).toBeEmpty()