diff --git a/edx_sga/static/js/spec/test_studio.js b/edx_sga/static/js/spec/test_studio.js new file mode 100644 index 00000000..c3cee946 --- /dev/null +++ b/edx_sga/static/js/spec/test_studio.js @@ -0,0 +1,55 @@ +describe("studio.js", function() { + 'use strict'; + describe("StaffGradedAssignmentXBlock", function() { + beforeEach(function() { + jasmine.Ajax.install(); + }); + + afterEach(function() { + jasmine.Ajax.uninstall(); + }); + + it("saves the view", function() { + // Mock some arguments + var fakeUrl = "/test_url/"; + var element = $("
" + + "" + + "" + + "
"); + var server = null; + + var runtime = { + handlerUrl: function() { + return fakeUrl; + }, + notify: function(type, state) { + notifyStates[type] = state; + } + }; + + var XBlock = StaffGradedAssignmentXBlock(runtime, element, server); + // Function expects this.runtime to exist + XBlock.save = XBlock.save.bind({runtime: runtime}); + + var notifyStates = {}; + + // Mock a response to the POST + jasmine.Ajax.stubRequest( + fakeUrl, JSON.stringify({ + one: "1", + two: "2", + three: "3" + }), "POST" + ).andReturn({responseText: "{}"}); + + // Execute the save + XBlock.save(); + + var request = jasmine.Ajax.requests.mostRecent(); + expect(request.status).toBe(200); + expect(request.url).toBe(fakeUrl); + expect(notifyStates.save.state).toBe('end'); + }); + + }); +});