From a7fc96e63de63d56a5c011f24b2540bd8a68f155 Mon Sep 17 00:00:00 2001 From: George Schneeloch Date: Wed, 26 Aug 2015 14:03:46 -0400 Subject: [PATCH] Added test for StaffGradedAssignmentXBlock.save --- edx_sga/static/js/spec/test_studio.js | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 edx_sga/static/js/spec/test_studio.js 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'); + }); + + }); +});