diff --git a/cms/static/coffee/spec/main.coffee b/cms/static/coffee/spec/main.coffee index b7efe681c3..0aa0e96687 100644 --- a/cms/static/coffee/spec/main.coffee +++ b/cms/static/coffee/spec/main.coffee @@ -1,4 +1,5 @@ requirejs.config({ + baseUrl: '/base/', paths: { "gettext": "xmodule_js/common_static/js/test/i18n", "mustache": "xmodule_js/common_static/js/vendor/mustache", @@ -42,10 +43,9 @@ requirejs.config({ "accessibility": "xmodule_js/common_static/js/src/accessibility_tools", "sinon": "xmodule_js/common_static/js/vendor/sinon-1.17.0", "squire": "xmodule_js/common_static/js/vendor/Squire", - "jasmine-jquery": "xmodule_js/common_static/js/vendor/jasmine-jquery", "jasmine-imagediff": "xmodule_js/common_static/js/vendor/jasmine-imagediff", - "jasmine-stealth": "xmodule_js/common_static/js/vendor/jasmine-stealth", - "jasmine.async": "xmodule_js/common_static/js/vendor/jasmine.async", + "jasmine-stealth": "xmodule_js/common_static/js/libs/jasmine-stealth", + "jasmine-waituntil": "xmodule_js/common_static/js/libs/jasmine-waituntil", "draggabilly": "xmodule_js/common_static/js/vendor/draggabilly", "domReady": "xmodule_js/common_static/js/vendor/domReady", "URI": "xmodule_js/common_static/js/vendor/URI.min", @@ -158,17 +158,17 @@ requirejs.config({ "mathjax": { exports: "MathJax", init: -> - MathJax.Hub.Config - tex2jax: - inlineMath: [ - ["\\(","\\)"], - ['[mathjaxinline]','[/mathjaxinline]'] - ] - displayMath: [ - ["\\[","\\]"], - ['[mathjax]','[/mathjax]'] - ] - MathJax.Hub.Configured() + MathJax.Hub.Config + tex2jax: + inlineMath: [ + ["\\(", "\\)"], + ['[mathjaxinline]', '[/mathjaxinline]'] + ] + displayMath: [ + ["\\[", "\\]"], + ['[mathjax]', '[/mathjax]'] + ] + MathJax.Hub.Configured() }, "URI": { exports: "URI" @@ -179,18 +179,12 @@ requirejs.config({ "sinon": { exports: "sinon" }, - "jasmine-jquery": { - deps: ["jasmine"] - }, - "jasmine-imagediff": { - deps: ["jasmine"] - }, + "jasmine-imagediff": {}, "jasmine-stealth": { - deps: ["jasmine"] + deps: ["underscore", "underscore.string"] }, - "jasmine.async": { - deps: ["jasmine"], - exports: "AsyncSpec" + "jasmine-waituntil": { + deps: ["jquery"] }, "xblock/core": { exports: "XBlock", @@ -201,7 +195,7 @@ requirejs.config({ deps: ["xblock/core"] }, "mock-ajax": { - deps: ["jasmine", "jquery"] + deps: ["jquery"] } "coffee/src/main": { @@ -221,35 +215,33 @@ requirejs.config({ jasmine.getFixtures().fixturesPath += 'coffee/fixtures' -define([ +testFiles = [ "coffee/spec/main_spec", - - "coffee/spec/models/course_spec", "coffee/spec/models/metadata_spec", + "coffee/spec/models/course_spec", + "coffee/spec/models/metadata_spec", "coffee/spec/models/section_spec", "coffee/spec/models/settings_course_grader_spec", - "coffee/spec/models/settings_grading_spec", "coffee/spec/models/textbook_spec", + "coffee/spec/models/settings_grading_spec", + "coffee/spec/models/textbook_spec", "coffee/spec/models/upload_spec", - "coffee/spec/views/course_info_spec", "coffee/spec/views/metadata_edit_spec", "coffee/spec/views/module_edit_spec", "coffee/spec/views/textbook_spec", "coffee/spec/views/upload_spec", - - "js/spec/video/transcripts/utils_spec", "js/spec/video/transcripts/editor_spec", - "js/spec/video/transcripts/videolist_spec", "js/spec/video/transcripts/message_manager_spec", - "js/spec/video/transcripts/file_uploader_spec", - + "js/spec/video/transcripts/utils_spec", + "js/spec/video/transcripts/editor_spec", +# "js/spec/video/transcripts/videolist_spec", +# "js/spec/video/transcripts/message_manager_spec", +# "js/spec/video/transcripts/file_uploader_spec", "js/spec/models/component_template_spec", "js/spec/models/explicit_url_spec", "js/spec/models/xblock_info_spec", "js/spec/models/xblock_validation_spec", "js/spec/models/license_spec", - "js/spec/utils/drag_and_drop_spec", "js/spec/utils/handle_iframe_binding_spec", "js/spec/utils/module_spec", - "js/spec/views/active_video_upload_list_spec", "js/spec/views/previous_video_upload_spec", "js/spec/views/previous_video_upload_list_spec", @@ -266,7 +258,6 @@ define([ "js/spec/views/license_spec", "js/spec/views/paging_spec", "js/spec/views/login_studio_spec", - "js/spec/views/pages/container_spec", "js/spec/views/pages/container_subviews_spec", "js/spec/views/pages/group_configurations_spec", @@ -274,25 +265,24 @@ define([ "js/spec/views/pages/course_rerun_spec", "js/spec/views/pages/index_spec", "js/spec/views/pages/library_users_spec", - "js/spec/views/modals/base_modal_spec", "js/spec/views/modals/edit_xblock_spec", "js/spec/views/modals/validation_error_modal_spec", - "js/spec/views/settings/main_spec", - "js/spec/factories/xblock_validation_spec", - "js/spec/xblock/cms.runtime.v1_spec", - - # Certificates application test suite mappings "js/certificates/spec/models/certificate_spec", "js/certificates/spec/views/certificate_details_spec", "js/certificates/spec/views/certificate_editor_spec", "js/certificates/spec/views/certificates_list_spec", - "js/certificates/spec/views/certificate_preview_spec", + "js/certificates/spec/views/certificate_preview_spec" +] - # these tests are run separately in the cms-squire suite, due to process - # isolation issues with Squire.js - # "coffee/spec/views/assets_spec" - ]) +i = 0 +while i < testFiles.length + testFiles[i] = '/base/' + testFiles[i] + '.js' + i++ + +require testFiles, -> +# start test run, once Require.js is done + window.__karma__.start() diff --git a/cms/static/coffee/spec/main_spec.coffee b/cms/static/coffee/spec/main_spec.coffee index 66e8048889..ee68e31326 100644 --- a/cms/static/coffee/spec/main_spec.coffee +++ b/cms/static/coffee/spec/main_spec.coffee @@ -1,4 +1,5 @@ -require ["jquery", "backbone", "coffee/src/main", "common/js/spec_helpers/ajax_helpers", "jasmine-stealth", "jquery.cookie"], +require ["jquery", "backbone", "coffee/src/main", "common/js/spec_helpers/ajax_helpers", + "jasmine-stealth", "jasmine-waituntil", "jquery.cookie"], ($, Backbone, main, AjaxHelpers) -> describe "CMS", -> it "should initialize URL", -> @@ -7,8 +8,12 @@ require ["jquery", "backbone", "coffee/src/main", "common/js/spec_helpers/ajax_h describe "main helper", -> beforeEach -> @previousAjaxSettings = $.extend(true, {}, $.ajaxSettings) - spyOn($, "cookie") - $.cookie.when("csrftoken").thenReturn("stubCSRFToken") + spyOn($, "cookie").and.callFake( + (param) -> + if param == "csrftoken" + return "stubCSRFToken" + ) + main() afterEach -> @@ -21,12 +26,15 @@ require ["jquery", "backbone", "coffee/src/main", "common/js/spec_helpers/ajax_h 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(this, [200, {}, '']) + server = AjaxHelpers.server([200, {}, '']) expect($("#page-notification")).toBeEmpty() $.ajax("/test") @@ -35,15 +43,15 @@ require ["jquery", "backbone", "coffee/src/main", "common/js/spec_helpers/ajax_h expect($("#page-notification")).toBeEmpty() it "AJAX request with error should pop an error notification", -> - server = AjaxHelpers.server(this, [500, {}, '']) + server = AjaxHelpers.server([500, {}, '']) $.ajax("/test") server.respond() expect($("#page-notification")).not.toBeEmpty() - expect($("#page-notification")).toContain('div.wrapper-notification-error') + 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(this, [500, {}, '']) + server = AjaxHelpers.server([500, {}, '']) $.ajax url: "/test" diff --git a/cms/static/coffee/spec/main_squire.coffee b/cms/static/coffee/spec/main_squire.coffee index afd40603df..1a537b4d64 100644 --- a/cms/static/coffee/spec/main_squire.coffee +++ b/cms/static/coffee/spec/main_squire.coffee @@ -1,4 +1,6 @@ requirejs.config({ + baseUrl: '/base/', + paths: { "gettext": "xmodule_js/common_static/js/test/i18n", "mustache": "xmodule_js/common_static/js/vendor/mustache", @@ -22,8 +24,8 @@ requirejs.config({ "datepair": "xmodule_js/common_static/js/vendor/timepicker/datepair", "date": "xmodule_js/common_static/js/vendor/date", "text": "xmodule_js/common_static/js/vendor/requirejs/text", - "underscore": "xmodule_js/common_static/common/js/vendor/underscore", - "underscore.string": "xmodule_js/common_static/common/js/vendor/underscore.string", + "underscore": "common/js/vendor/underscore", + "underscore.string": "common/js/vendor/underscore.string", "backbone": "xmodule_js/common_static/js/vendor/backbone-min", "backbone.associations": "xmodule_js/common_static/js/vendor/backbone-associations-min", "backbone.paginator": "xmodule_js/common_static/js/vendor/backbone.paginator.min", @@ -36,11 +38,11 @@ requirejs.config({ "utility": "xmodule_js/common_static/js/src/utility", "sinon": "xmodule_js/common_static/js/vendor/sinon-1.17.0", "squire": "xmodule_js/common_static/js/vendor/Squire", - "jasmine-stealth": "xmodule_js/common_static/js/vendor/jasmine-stealth", - "jasmine.async": "xmodule_js/common_static/js/vendor/jasmine.async", "modernizr": "xmodule_js/common_static/edx-pattern-library/js/modernizr-custom", "afontgarde": "xmodule_js/common_static/edx-pattern-library/js/afontgarde", "edxicons": "xmodule_js/common_static/edx-pattern-library/js/edx-icons", + "jasmine-stealth": "xmodule_js/common_static/js/libs/jasmine-stealth", + "jasmine-waituntil": "xmodule_js/common_static/js/libs/jasmine-waituntil", "draggabilly": "xmodule_js/common_static/js/vendor/draggabilly", "domReady": "xmodule_js/common_static/js/vendor/domReady", "URI": "xmodule_js/common_static/js/vendor/URI.min", @@ -159,11 +161,10 @@ requirejs.config({ exports: "sinon" }, "jasmine-stealth": { - deps: ["jasmine"] + deps: ["underscore", "underscore.string"] }, - "jasmine.async": { - deps: ["jasmine"], - exports: "AsyncSpec" + "jasmine-waituntil": { + deps: ["jquery"] }, "xblock/core": { exports: "XBlock", @@ -191,9 +192,16 @@ requirejs.config({ jasmine.getFixtures().fixturesPath += 'coffee/fixtures' -define([ - "coffee/spec/views/assets_spec", - "js/spec/video/translations_editor_spec", - "js/spec/video/file_uploader_editor_spec", - "js/spec/models/group_configuration_spec" - ]) +testFiles = [ + 'coffee/spec/views/assets_spec', + 'js/spec/video/translations_editor_spec', + 'js/spec/video/file_uploader_editor_spec', + 'js/spec/models/group_configuration_spec' +] +i = 0 +while i < testFiles.length + testFiles[i] = '/base/' + testFiles[i] + '.js' + i++ +require testFiles, -> +# start test run, once Require.js is done + window.__karma__.start() diff --git a/cms/static/coffee/spec/models/section_spec.coffee b/cms/static/coffee/spec/models/section_spec.coffee index 536d3507d6..82fd1c9b3f 100644 --- a/cms/static/coffee/spec/models/section_spec.coffee +++ b/cms/static/coffee/spec/models/section_spec.coffee @@ -34,7 +34,7 @@ define ["js/models/section", "common/js/spec_helpers/ajax_helpers", "js/utils/mo }) it "show/hide a notification when it saves to the server", -> - server = AjaxHelpers.server(this, [200, {}, '']) + server = AjaxHelpers.server([200, {}, '']) @model.save() expect(Section.prototype.showNotification).toHaveBeenCalled() @@ -43,7 +43,7 @@ define ["js/models/section", "common/js/spec_helpers/ajax_helpers", "js/utils/mo it "don't hide notification when saving fails", -> # this is handled by the global AJAX error handler - server = AjaxHelpers.server(this, [500, {}, '']) + server = AjaxHelpers.server([500, {}, '']) @model.save() server.respond() diff --git a/cms/static/coffee/spec/models/textbook_spec.coffee b/cms/static/coffee/spec/models/textbook_spec.coffee index fa4f86742c..dd78ba8997 100644 --- a/cms/static/coffee/spec/models/textbook_spec.coffee +++ b/cms/static/coffee/spec/models/textbook_spec.coffee @@ -1,12 +1,6 @@ define ["backbone", "js/models/textbook", "js/collections/textbook", "js/models/chapter", "js/collections/chapter", "coffee/src/main"], (Backbone, Textbook, TextbookSet, Chapter, ChapterSet, main) -> - beforeEach -> - @addMatchers - toBeInstanceOf: (expected) -> - return @actual instanceof expected - - describe "Textbook model", -> beforeEach -> main() diff --git a/cms/static/coffee/spec/views/assets_spec.coffee b/cms/static/coffee/spec/views/assets_spec.coffee index aa24e82ac2..6c82b2e3e2 100644 --- a/cms/static/coffee/spec/views/assets_spec.coffee +++ b/cms/static/coffee/spec/views/assets_spec.coffee @@ -1,25 +1,25 @@ -define ["jquery", "jasmine", "common/js/spec_helpers/ajax_helpers", "squire"], -($, jasmine, AjaxHelpers, Squire) -> +define ["jquery", "common/js/spec_helpers/ajax_helpers", "squire"], +($, AjaxHelpers, Squire) -> assetLibraryTpl = readFixtures('asset-library.underscore') assetTpl = readFixtures('asset.underscore') describe "Asset view", -> - beforeEach -> + beforeEach (done) -> setFixtures($("" + ); schedule_template = _.template($('#schedule_template').html()); save_url = 'save_ccx'; $.fn.leanModal = function(param) { return true; - } + }; data = [{ "category": "chapter", @@ -44,10 +47,8 @@ define(['common/js/spec_helpers/ajax_helpers', 'js/ccx/schedule'], ] }]; view = new edx.ccx.schedule.ScheduleView({el: $('#new-ccx-schedule')}); - view.schedule_collection.set(data) + view.schedule_collection.set(data); view.render(); - - }); it("verifies correct view setup", function() { diff --git a/lms/static/js/spec/dashboard/donation.js b/lms/static/js/spec/dashboard/donation.js index b6a90955c5..55447995ef 100644 --- a/lms/static/js/spec/dashboard/donation.js +++ b/lms/static/js/spec/dashboard/donation.js @@ -29,7 +29,7 @@ define(['common/js/spec_helpers/template_helpers', 'common/js/spec_helpers/ajax_ // This function gets passed the dynamically constructed // form with signed payment parameters from the LMS server, // so we can verify that the form is constructed correctly. - spyOn(view, 'submitPaymentForm').andCallFake(function() {}); + spyOn(view, 'submitPaymentForm').and.callFake(function() {}); // Stub the analytics event tracker window.analytics = jasmine.createSpyObj('analytics', ['track']); @@ -64,7 +64,7 @@ define(['common/js/spec_helpers/template_helpers', 'common/js/spec_helpers/ajax_ // We stub out the actual submission of the form to avoid // leaving the current page during the test. expect(view.submitPaymentForm).toHaveBeenCalled(); - var form = view.submitPaymentForm.mostRecentCall.args[0]; + var form = view.submitPaymentForm.calls.mostRecent().args[0]; expect(form.serialize()).toEqual($.param(PAYMENT_PARAMS)); expect(form.attr('method')).toEqual("post"); expect(form.attr('action')).toEqual(PAYMENT_URL); diff --git a/lms/static/js/spec/dashboard/dropdown_spec.js b/lms/static/js/spec/dashboard/dropdown_spec.js index 2b9b18177c..b3b63a3a5a 100644 --- a/lms/static/js/spec/dashboard/dropdown_spec.js +++ b/lms/static/js/spec/dashboard/dropdown_spec.js @@ -14,15 +14,10 @@ define(['js/dashboard/dropdown', 'jquery.simulate'], verifyDropdownNotVisible = function() { expect($(dropdownSelector)).not.toBeVisible(); }, - waitForElementToBeFocused = function(element, desc) { - // This is being used instead of toBeFocused which is flaky - waitsFor( - function () { - return element === document.activeElement; - }, - desc + ' element to have focus', - 500 - ); + waitForElementToBeFocused = function(element, done) { + jasmine.waitUntil(function () { + return element === document.activeElement; + }).always(done); }, openDropDownMenu = function() { verifyDropdownNotVisible(); @@ -47,39 +42,39 @@ define(['js/dashboard/dropdown', 'jquery.simulate'], clickToggleButton(); verifyDropdownNotVisible(); }); - it("ESCAPE will close dropdown and return focus to the button", function() { + it("ESCAPE will close dropdown and return focus to the button", function(done) { openDropDownMenu(); keydown({ keyCode: keys.ESCAPE }); verifyDropdownNotVisible(); - waitForElementToBeFocused($(toggleButtonSelector)[0], "button"); + waitForElementToBeFocused($(toggleButtonSelector)[0], done); }); - it("SPACE will close dropdown and return focus to the button", function() { + it("SPACE will close dropdown and return focus to the button", function(done) { openDropDownMenu(); keydown({ keyCode: keys.SPACE }); verifyDropdownNotVisible(); - waitForElementToBeFocused($(toggleButtonSelector)[0], "button"); + waitForElementToBeFocused($(toggleButtonSelector)[0], done); }); describe("Focus is trapped when navigating with", function() { - it("TAB key", function() { + it("TAB key", function(done) { openDropDownMenu(); keydown({ keyCode: keys.TAB }); - waitForElementToBeFocused($(dropdownItemSelector)[0], "first"); + waitForElementToBeFocused($(dropdownItemSelector)[0], done); }); - it("DOWN key", function() { + it("DOWN key", function(done) { openDropDownMenu(); keydown({ keyCode: keys.DOWN }); - waitForElementToBeFocused($(dropdownItemSelector)[0], "first"); + waitForElementToBeFocused($(dropdownItemSelector)[0], done); }); - it("TAB key + SHIFT key", function() { + it("TAB key + SHIFT key", function(done) { openDropDownMenu(); keydown({ keyCode: keys.TAB, shiftKey: true }); - waitForElementToBeFocused($(dropdownItemSelector)[1], "last"); + waitForElementToBeFocused($(dropdownItemSelector)[1], done); }); - it("UP key", function() { + it("UP key", function(done) { openDropDownMenu(); keydown({ keyCode: keys.UP }); - waitForElementToBeFocused($(dropdownItemSelector)[1], "last"); + waitForElementToBeFocused($(dropdownItemSelector)[1], done); }); }); }); diff --git a/lms/static/js/spec/discovery/discovery_factory_spec.js b/lms/static/js/spec/discovery/discovery_factory_spec.js index 199323d0ea..2395895946 100644 --- a/lms/static/js/spec/discovery/discovery_factory_spec.js +++ b/lms/static/js/spec/discovery/discovery_factory_spec.js @@ -121,7 +121,7 @@ define([ it('loads more', function () { var requests = AjaxHelpers.requests(this); - jasmine.Clock.useMock(); + jasmine.clock().install(); $('.discovery-input').val('test'); $('.discovery-submit').trigger('click'); AjaxHelpers.respondWithJson(requests, JSON_RESPONSE); @@ -129,12 +129,14 @@ define([ expect($('.courses-listing .course-title')).toContainHtml('edX Demonstration Course'); window.scroll(0, $(document).height()); $(window).trigger('scroll'); - jasmine.Clock.tick(500); + jasmine.clock().tick(500); // TODO: determine why the search API is invoked twice AjaxHelpers.respondWithJson(requests, JSON_RESPONSE); AjaxHelpers.respondWithJson(requests, JSON_RESPONSE); expect($('.courses-listing article').length).toEqual(2); + + jasmine.clock().uninstall(); }); it('displays not found message', function () { diff --git a/lms/static/js/spec/discovery/views/course_card_spec.js b/lms/static/js/spec/discovery/views/course_card_spec.js index 2e3c71c17a..97f49a09c2 100644 --- a/lms/static/js/spec/discovery/views/course_card_spec.js +++ b/lms/static/js/spec/discovery/views/course_card_spec.js @@ -43,8 +43,8 @@ define([ it('renders', function () { var data = this.view.model.attributes; expect(this.view.$el).toContainHtml(data.content.display_name); - expect(this.view.$el).toContain('a[href="/courses/' + data.course + '/about"]'); - expect(this.view.$el).toContain('img[src="' + data.image_url + '"]'); + expect(this.view.$el).toContainElement('a[href="/courses/' + data.course + '/about"]'); + expect(this.view.$el).toContainElement('img[src="' + data.image_url + '"]'); expect(this.view.$el.find('.course-name')).toContainHtml(data.org); expect(this.view.$el.find('.course-name')).toContainHtml(data.content.number); expect(this.view.$el.find('.course-name')).toContainHtml(data.content.display_name); diff --git a/lms/static/js/spec/discovery/views/courses_listing_spec.js b/lms/static/js/spec/discovery/views/courses_listing_spec.js index 2bd4d38b76..0001561773 100644 --- a/lms/static/js/spec/discovery/views/courses_listing_spec.js +++ b/lms/static/js/spec/discovery/views/courses_listing_spec.js @@ -34,7 +34,7 @@ define([ describe('discovery.views.CoursesListing', function () { beforeEach(function () { - jasmine.Clock.useMock(); + jasmine.clock().install(); loadFixtures('js/fixtures/discovery.html'); TemplateHelpers.installTemplate('templates/discovery/course_card'); var collection = new Backbone.Collection( @@ -44,10 +44,14 @@ define([ var mock = { collection: collection, latest: function () { return this.collection.last(20); } - } + }; this.view = new CoursesListing({ model: mock }); }); + afterEach(function() { + jasmine.clock().uninstall(); + }); + it('renders search results', function () { this.view.render(); expect($('.courses-listing article').length).toEqual(1); @@ -62,13 +66,13 @@ define([ this.view.render(); window.scroll(0, $(document).height()); $(window).trigger('scroll'); - jasmine.Clock.tick(500); + jasmine.clock().tick(500); expect(this.onNext).toHaveBeenCalled(); // should not be triggered again (while it is loading) $(window).trigger('scroll'); - jasmine.Clock.tick(500); - expect(this.onNext.calls.length).toEqual(1); + jasmine.clock().tick(500); + expect(this.onNext.calls.count()).toEqual(1); }); }); diff --git a/lms/static/js/spec/edxnotes/custom_matchers.js b/lms/static/js/spec/edxnotes/custom_matchers.js deleted file mode 100644 index c5309bd6c9..0000000000 --- a/lms/static/js/spec/edxnotes/custom_matchers.js +++ /dev/null @@ -1,32 +0,0 @@ -define(['jquery'], function($) { - 'use strict'; - return function (that) { - that.addMatchers({ - toContainText: function (text) { - var trimmedText = $.trim($(this.actual).text()); - - if (text && $.isFunction(text.test)) { - return text.test(trimmedText); - } else { - return trimmedText.indexOf(text) !== -1; - } - }, - - toHaveLength: function (number) { - return $(this.actual).length === number; - }, - - toHaveIndex: function (number) { - return $(this.actual).index() === number; - }, - - toBeInRange: function (min, max) { - return min <= this.actual && this.actual <= max; - }, - - toBeFocused: function () { - return $(this.actual)[0] === $(this.actual)[0].ownerDocument.activeElement; - } - }); - }; -}); diff --git a/lms/static/js/spec/edxnotes/plugins/accessibility_spec.js b/lms/static/js/spec/edxnotes/plugins/accessibility_spec.js index f4128df9b7..e4abb6122a 100644 --- a/lms/static/js/spec/edxnotes/plugins/accessibility_spec.js +++ b/lms/static/js/spec/edxnotes/plugins/accessibility_spec.js @@ -1,6 +1,6 @@ define([ - 'jquery', 'underscore', 'annotator_1.2.9', 'logger', 'js/edxnotes/views/notes_factory', 'js/spec/edxnotes/custom_matchers' -], function($, _, Annotator, Logger, NotesFactory, customMatchers) { + 'jquery', 'underscore', 'annotator_1.2.9', 'logger', 'js/edxnotes/views/notes_factory' +], function($, _, Annotator, Logger, NotesFactory) { 'use strict'; describe('EdxNotes Accessibility Plugin', function() { function keyDownEvent (key) { @@ -25,7 +25,6 @@ define([ beforeEach(function() { this.KEY = $.ui.keyCode; - customMatchers(this); loadFixtures('js/fixtures/edxnotes/edxnotes_wrapper.html'); this.annotator = NotesFactory.factory( $('div#edx-notes-wrapper-123').get(0), { @@ -45,7 +44,7 @@ define([ describe('destroy', function () { it('should unbind all events', function () { spyOn($.fn, 'off'); - spyOn(this.annotator, 'unsubscribe').andCallThrough(); + spyOn(this.annotator, 'unsubscribe').and.callThrough(); this.plugin.destroy(); expect(this.annotator.unsubscribe).toHaveBeenCalledWith( 'annotationViewerTextField', this.plugin.addAriaAttributes @@ -82,7 +81,7 @@ define([ this.annotator.viewer.load([annotation]); note = $('.annotator-note'); expect(note).toExist(); - expect(note).toHaveAttr('tabindex', -1); + expect(note).toHaveAttr('tabindex', "-1"); expect(note).toHaveAttr('role', 'note'); expect(note).toHaveAttr('class', 'annotator-note'); }); @@ -116,9 +115,9 @@ define([ highlights: [highlight.get(0)] }; highlight.data('annotation', annotation); - spyOn(this.annotator, 'showViewer').andCallThrough(); - spyOn(this.annotator.viewer, 'hide').andCallThrough(); - spyOn(this.plugin, 'focusOnGrabber').andCallThrough(); + spyOn(this.annotator, 'showViewer').and.callThrough(); + spyOn(this.annotator.viewer, 'hide').and.callThrough(); + spyOn(this.plugin, 'focusOnGrabber').and.callThrough(); }); it('should open the viewer on SPACE keydown and focus on note', function () { @@ -175,7 +174,7 @@ define([ edit= this.annotator.element.find('.annotator-edit').first(); del = this.annotator.element.find('.annotator-delete').first(); close = this.annotator.element.find('.annotator-close').first(); - spyOn(this.annotator.viewer, 'hide').andCallThrough(); + spyOn(this.annotator.viewer, 'hide').and.callThrough(); }); it('should give focus to Note on Listing TAB keydown', function () { @@ -221,7 +220,7 @@ define([ control.focus(); control.trigger(keyDownEvent(this.KEY.ESCAPE)); }, this); - expect(this.annotator.viewer.hide.callCount).toBe(5); + expect(this.annotator.viewer.hide.calls.count()).toBe(5); }); }); @@ -243,8 +242,8 @@ define([ tags = annotatorItems.first().next().children('input'); save = this.annotator.element.find('.annotator-save'); cancel = this.annotator.element.find('.annotator-cancel'); - spyOn(this.annotator.editor, 'submit').andCallThrough(); - spyOn(this.annotator.editor, 'hide').andCallThrough(); + spyOn(this.annotator.editor, 'submit').and.callThrough(); + spyOn(this.annotator.editor, 'hide').and.callThrough(); }); it('should give focus to TextArea on Form TAB keydown', function () { @@ -287,7 +286,7 @@ define([ save.focus(); save.trigger(keyDownEvent(this.KEY.ENTER)); expect(this.annotator.editor.submit).toHaveBeenCalled(); - this.annotator.editor.submit.reset(); + this.annotator.editor.submit.calls.reset(); save.focus(); save.trigger(keyDownEvent(this.KEY.SPACE)); expect(this.annotator.editor.submit).toHaveBeenCalled(); @@ -297,7 +296,7 @@ define([ textArea.focus(); textArea.trigger(enterMetaKeyEvent()); expect(this.annotator.editor.submit).toHaveBeenCalled(); - this.annotator.editor.submit.reset(); + this.annotator.editor.submit.calls.reset(); textArea.focus(); textArea.trigger(enterControlKeyEvent()); expect(this.annotator.editor.submit).toHaveBeenCalled(); @@ -307,7 +306,7 @@ define([ cancel.focus(); cancel.trigger(keyDownEvent(this.KEY.ENTER)); expect(this.annotator.editor.hide).toHaveBeenCalled(); - this.annotator.editor.hide.reset(); + this.annotator.editor.hide.calls.reset(); cancel.focus(); save.trigger(keyDownEvent(this.KEY.SPACE)); expect(this.annotator.editor.hide).toHaveBeenCalled(); @@ -320,7 +319,7 @@ define([ control.focus(); control.trigger(keyDownEvent(this.KEY.ESCAPE)); }, this); - expect(this.annotator.editor.hide.callCount).toBe(3); + expect(this.annotator.editor.hide.calls.count()).toBe(3); }); }); }); diff --git a/lms/static/js/spec/edxnotes/plugins/caret_navigation_spec.js b/lms/static/js/spec/edxnotes/plugins/caret_navigation_spec.js index 4bd20371bf..544b6881a3 100644 --- a/lms/static/js/spec/edxnotes/plugins/caret_navigation_spec.js +++ b/lms/static/js/spec/edxnotes/plugins/caret_navigation_spec.js @@ -87,10 +87,10 @@ define([ this.mockSubscriber = jasmine.createSpy(); this.annotator.subscribe('annotationCreated', this.mockSubscriber); - spyOn($.fn, 'position').andReturn(this.mockOffset); - spyOn(this.annotator, 'createAnnotation').andReturn(this.annotation); - spyOn(this.annotator, 'setupAnnotation').andReturn(this.annotation); - spyOn(this.annotator, 'getSelectedRanges').andReturn([{}]); + spyOn($.fn, 'position').and.returnValue(this.mockOffset); + spyOn(this.annotator, 'createAnnotation').and.returnValue(this.annotation); + spyOn(this.annotator, 'setupAnnotation').and.returnValue(this.annotation); + spyOn(this.annotator, 'getSelectedRanges').and.returnValue([{}]); spyOn(this.annotator, 'deleteAnnotation'); spyOn(this.annotator, 'showEditor'); spyOn(Annotator.Util, 'readRangeViaSelection'); @@ -100,7 +100,7 @@ define([ it('should create a new annotation', function () { triggerEvent(this.element); - expect(this.annotator.createAnnotation.callCount).toBe(1); + expect(this.annotator.createAnnotation.calls.count()).toBe(1); }); it('should set up the annotation', function () { @@ -111,25 +111,25 @@ define([ }); it('should display the Annotation#editor correctly if the Annotation#adder is hidden', function () { - spyOn($.fn, 'is').andReturn(false); + spyOn($.fn, 'is').and.returnValue(false); triggerEvent(this.element); - expect($('annotator-hl-temporary').position.callCount).toBe(1); + expect($('annotator-hl-temporary').position.calls.count()).toBe(1); expect(this.annotator.showEditor).toHaveBeenCalledWith( this.annotation, this.mockOffset ); }); it('should display the Annotation#editor in the same place as the Annotation#adder', function () { - spyOn($.fn, 'is').andReturn(true); + spyOn($.fn, 'is').and.returnValue(true); triggerEvent(this.element); - expect(this.annotator.adder.position.callCount).toBe(1); + expect(this.annotator.adder.position.calls.count()).toBe(1); expect(this.annotator.showEditor).toHaveBeenCalledWith( this.annotation, this.mockOffset ); }); it('should hide the Annotation#adder', function () { - spyOn($.fn, 'is').andReturn(true); + spyOn($.fn, 'is').and.returnValue(true); spyOn($.fn, 'hide'); triggerEvent(this.element); expect(this.annotator.adder.hide).toHaveBeenCalled(); @@ -187,13 +187,13 @@ define([ }); it('should do nothing if empty selection', function () { - this.annotator.getSelectedRanges.andReturn([]); + this.annotator.getSelectedRanges.and.returnValue([]); triggerEvent(this.element); expect(this.annotator.showEditor).not.toHaveBeenCalled(); }); it('should do nothing if selection is in Annotator', function () { - spyOn(this.annotator, 'isAnnotator').andReturn(true); + spyOn(this.annotator, 'isAnnotator').and.returnValue(true); triggerEvent(this.element); expect(this.annotator.showEditor).not.toHaveBeenCalled(); }); diff --git a/lms/static/js/spec/edxnotes/plugins/scroller_spec.js b/lms/static/js/spec/edxnotes/plugins/scroller_spec.js index 77c1d7eeb2..49c54dda6c 100644 --- a/lms/static/js/spec/edxnotes/plugins/scroller_spec.js +++ b/lms/static/js/spec/edxnotes/plugins/scroller_spec.js @@ -1,7 +1,6 @@ define([ - 'jquery', 'underscore', 'annotator_1.2.9', 'js/edxnotes/views/notes_factory', - 'js/spec/edxnotes/custom_matchers' -], function($, _, Annotator, NotesFactory, customMatchers) { + 'jquery', 'underscore', 'annotator_1.2.9', 'js/edxnotes/views/notes_factory' +], function($, _, Annotator, NotesFactory) { 'use strict'; describe('EdxNotes Scroll Plugin', function() { var annotators, highlights; @@ -19,7 +18,6 @@ define([ } beforeEach(function() { - customMatchers(this); loadFixtures('js/fixtures/edxnotes/edxnotes_wrapper.html'); annotators = [ NotesFactory.factory($('div#edx-notes-wrapper-123').get(0), { @@ -31,9 +29,9 @@ define([ ]; highlights = _.map(annotators, function(annotator) { - spyOn(annotator, 'onHighlightClick').andCallThrough(); - spyOn(annotator, 'onHighlightMouseover').andCallThrough(); - spyOn(annotator, 'startViewerHideTimer').andCallThrough(); + spyOn(annotator, 'onHighlightClick').and.callThrough(); + spyOn(annotator, 'onHighlightMouseover').and.callThrough(); + spyOn(annotator, 'startViewerHideTimer').and.callThrough(); return $('', { 'class': 'annotator-hl', 'tabindex': -1, @@ -41,8 +39,8 @@ define([ }).appendTo(annotator.element); }); - spyOn(annotators[0].plugins.Scroller, 'getIdFromLocationHash').andReturn('abc123'); - spyOn($.fn, 'unbind').andCallThrough(); + spyOn(annotators[0].plugins.Scroller, 'getIdFromLocationHash').and.returnValue('abc123'); + spyOn($.fn, 'unbind').and.callThrough(); }); afterEach(function () { @@ -56,7 +54,7 @@ define([ id: 'abc123', highlights: [highlights[0]] }]); - annotators[0].onHighlightMouseover.reset(); + annotators[0].onHighlightMouseover.calls.reset(); expect(highlights[0]).toBeFocused(); highlights[0].mouseover(); highlights[0].mouseout(); diff --git a/lms/static/js/spec/edxnotes/utils/logger_spec.js b/lms/static/js/spec/edxnotes/utils/logger_spec.js index a84bad0eac..802ec55e72 100644 --- a/lms/static/js/spec/edxnotes/utils/logger_spec.js +++ b/lms/static/js/spec/edxnotes/utils/logger_spec.js @@ -1,6 +1,6 @@ define([ - 'logger', 'js/edxnotes/utils/logger', 'js/spec/edxnotes/custom_matchers' -], function(Logger, NotesLogger, customMatchers) { + 'logger', 'js/edxnotes/utils/logger' +], function(Logger, NotesLogger) { 'use strict'; describe('Edxnotes NotesLogger', function() { var getLogger = function(id, mode) { @@ -11,7 +11,6 @@ define([ spyOn(window.console, 'log'); spyOn(window.console, 'error'); spyOn(Logger, 'log'); - customMatchers(this); }); it('keeps a correct history of logs', function() { @@ -94,11 +93,11 @@ define([ it('can use timers', function() { var logger = getLogger('id', 1), logs, log; - spyOn(performance, 'now').andReturn(1); - spyOn(Date, 'now').andReturn(1); + spyOn(performance, 'now').and.returnValue(1); + spyOn(Date, 'now').and.returnValue(1); logger.time('timer'); - performance.now.andReturn(201); - Date.now.andReturn(201); + performance.now.and.returnValue(201); + Date.now.and.returnValue(201); logger.timeEnd('timer'); logs = logger.getHistory(); diff --git a/lms/static/js/spec/edxnotes/views/note_item_spec.js b/lms/static/js/spec/edxnotes/views/note_item_spec.js index 84ea75a39f..4b3a0af123 100644 --- a/lms/static/js/spec/edxnotes/views/note_item_spec.js +++ b/lms/static/js/spec/edxnotes/views/note_item_spec.js @@ -2,10 +2,8 @@ define([ 'jquery', 'underscore', 'common/js/spec_helpers/ajax_helpers', 'common/js/spec_helpers/template_helpers', 'js/spec/edxnotes/helpers', 'logger', 'js/edxnotes/models/note', 'js/edxnotes/views/note_item', - 'js/spec/edxnotes/custom_matchers' ], function( - $, _, AjaxHelpers, TemplateHelpers, Helpers, Logger, NoteModel, NoteItemView, - customMatchers + $, _, AjaxHelpers, TemplateHelpers, Helpers, Logger, NoteModel, NoteItemView ) { 'use strict'; describe('EdxNotes NoteItemView', function() { @@ -27,16 +25,15 @@ define([ }; beforeEach(function() { - customMatchers(this); TemplateHelpers.installTemplate('templates/edxnotes/note-item'); - spyOn(Logger, 'log').andCallThrough(); + spyOn(Logger, 'log').and.callThrough(); }); it('can be rendered properly', function() { var view = getView(), unitLink = view.$('.reference-unit-link').get(0); - expect(view.$el).toContain('.note-excerpt-more-link'); + expect(view.$el).toContainElement('.note-excerpt-more-link'); expect(view.$el).toContainText(Helpers.PRUNED_TEXT); expect(view.$el).toContainText('More'); view.$('.note-excerpt-more-link').click(); diff --git a/lms/static/js/spec/edxnotes/views/notes_factory_spec.js b/lms/static/js/spec/edxnotes/views/notes_factory_spec.js index dda98b8b59..0865da6ee0 100644 --- a/lms/static/js/spec/edxnotes/views/notes_factory_spec.js +++ b/lms/static/js/spec/edxnotes/views/notes_factory_spec.js @@ -1,11 +1,10 @@ define([ 'annotator_1.2.9', 'js/edxnotes/views/notes_factory', 'common/js/spec_helpers/ajax_helpers', - 'js/spec/edxnotes/helpers', 'js/spec/edxnotes/custom_matchers' -], function(Annotator, NotesFactory, AjaxHelpers, Helpers, customMatchers) { + 'js/spec/edxnotes/helpers' +], function(Annotator, NotesFactory, AjaxHelpers, Helpers) { 'use strict'; describe('EdxNotes NotesFactory', function() { beforeEach(function() { - customMatchers(this); loadFixtures('js/fixtures/edxnotes/edxnotes_wrapper.html'); this.wrapper = document.getElementById('edx-notes-wrapper-123'); }); diff --git a/lms/static/js/spec/edxnotes/views/notes_page_spec.js b/lms/static/js/spec/edxnotes/views/notes_page_spec.js index 2c2ad249bf..79388f9081 100644 --- a/lms/static/js/spec/edxnotes/views/notes_page_spec.js +++ b/lms/static/js/spec/edxnotes/views/notes_page_spec.js @@ -1,14 +1,13 @@ define([ 'jquery', 'underscore', 'common/js/spec_helpers/template_helpers', 'common/js/spec_helpers/ajax_helpers', 'js/spec/edxnotes/helpers', - 'js/edxnotes/views/page_factory', 'js/spec/edxnotes/custom_matchers' -], function($, _, TemplateHelpers, AjaxHelpers, Helpers, NotesFactory, customMatchers) { + 'js/edxnotes/views/page_factory' +], function($, _, TemplateHelpers, AjaxHelpers, Helpers, NotesFactory) { 'use strict'; describe('EdxNotes NotesPage', function() { var notes = Helpers.getDefaultNotes(); beforeEach(function() { - customMatchers(this); loadFixtures('js/fixtures/edxnotes/edxnotes.html'); TemplateHelpers.installTemplates([ 'templates/edxnotes/note-item', 'templates/edxnotes/tab-item' diff --git a/lms/static/js/spec/edxnotes/views/notes_visibility_factory_spec.js b/lms/static/js/spec/edxnotes/views/notes_visibility_factory_spec.js index cf2f3fa7ff..26e1db8008 100644 --- a/lms/static/js/spec/edxnotes/views/notes_visibility_factory_spec.js +++ b/lms/static/js/spec/edxnotes/views/notes_visibility_factory_spec.js @@ -1,9 +1,8 @@ define([ 'jquery', 'underscore', 'annotator_1.2.9', 'common/js/spec_helpers/ajax_helpers', - 'js/edxnotes/views/notes_visibility_factory', 'js/spec/edxnotes/helpers', - 'js/spec/edxnotes/custom_matchers', 'jasmine-jquery' + 'js/edxnotes/views/notes_visibility_factory', 'js/spec/edxnotes/helpers' ], function( - $, _, Annotator, AjaxHelpers, NotesVisibilityFactory, Helpers, customMatchers + $, _, Annotator, AjaxHelpers, NotesVisibilityFactory, Helpers ) { 'use strict'; describe('EdxNotes ToggleNotesFactory', function() { @@ -17,7 +16,6 @@ define([ }; beforeEach(function() { - customMatchers(this); loadFixtures( 'js/fixtures/edxnotes/edxnotes_wrapper.html', 'js/fixtures/edxnotes/toggle_notes.html' @@ -32,7 +30,7 @@ define([ this.button = $('.action-toggle-notes'); this.label = this.button.find('.utility-control-label'); this.toggleMessage = $('.action-toggle-message'); - spyOn(this.toggleNotes, 'toggleHandler').andCallThrough(); + spyOn(this.toggleNotes, 'toggleHandler').and.callThrough(); }); afterEach(function () { diff --git a/lms/static/js/spec/edxnotes/views/search_box_spec.js b/lms/static/js/spec/edxnotes/views/search_box_spec.js index 3b1e780fcd..9c7bfceba5 100644 --- a/lms/static/js/spec/edxnotes/views/search_box_spec.js +++ b/lms/static/js/spec/edxnotes/views/search_box_spec.js @@ -1,7 +1,7 @@ define([ 'jquery', 'underscore', 'common/js/spec_helpers/ajax_helpers', 'js/edxnotes/views/search_box', - 'js/edxnotes/collections/notes', 'js/spec/edxnotes/custom_matchers', 'js/spec/edxnotes/helpers', 'jasmine-jquery' -], function($, _, AjaxHelpers, SearchBoxView, NotesCollection, customMatchers, Helpers) { + 'js/edxnotes/collections/notes', 'js/spec/edxnotes/helpers' +], function($, _, AjaxHelpers, SearchBoxView, NotesCollection, Helpers) { 'use strict'; describe('EdxNotes SearchBoxView', function() { var getSearchBox, submitForm, assertBoxIsEnabled, assertBoxIsDisabled, searchResponse; @@ -47,7 +47,6 @@ define([ }; beforeEach(function () { - customMatchers(this); loadFixtures('js/fixtures/edxnotes/edxnotes.html'); spyOn(Logger, 'log'); this.searchBox = getSearchBox(); diff --git a/lms/static/js/spec/edxnotes/views/shim_spec.js b/lms/static/js/spec/edxnotes/views/shim_spec.js index c568f6cb13..37795ce8cb 100644 --- a/lms/static/js/spec/edxnotes/views/shim_spec.js +++ b/lms/static/js/spec/edxnotes/views/shim_spec.js @@ -1,5 +1,5 @@ define([ - 'jquery', 'underscore', 'annotator_1.2.9', 'js/edxnotes/views/notes_factory', 'jasmine-jquery' + 'jquery', 'underscore', 'annotator_1.2.9', 'js/edxnotes/views/notes_factory' ], function($, _, Annotator, NotesFactory) { 'use strict'; describe('EdxNotes Shim', function() { @@ -38,11 +38,11 @@ define([ ]; _.each(annotators, function(annotator) { highlights.push($('').appendTo(annotator.element)); - spyOn(annotator, 'onHighlightClick').andCallThrough(); - spyOn(annotator, 'onHighlightMouseover').andCallThrough(); - spyOn(annotator, 'startViewerHideTimer').andCallThrough(); + spyOn(annotator, 'onHighlightClick').and.callThrough(); + spyOn(annotator, 'onHighlightMouseover').and.callThrough(); + spyOn(annotator, 'startViewerHideTimer').and.callThrough(); }); - spyOn($.fn, 'off').andCallThrough(); + spyOn($.fn, 'off').and.callThrough(); }); afterEach(function () { @@ -59,9 +59,9 @@ define([ }); it('clicking on highlights does not open the viewer when the editor is opened', function() { - spyOn(annotators[1].editor, 'isShown').andReturn(false); + spyOn(annotators[1].editor, 'isShown').and.returnValue(false); highlights[0].click(); - annotators[1].editor.isShown.andReturn(true); + annotators[1].editor.isShown.and.returnValue(true); highlights[1].click(); expect($('#edx-notes-wrapper-123 .annotator-viewer')).not.toHaveClass('annotator-hide'); expect($('#edx-notes-wrapper-456 .annotator-viewer')).toHaveClass('annotator-hide'); @@ -76,7 +76,7 @@ define([ // in turn calls onHighlightMouseover. // To test if onHighlightMouseover is called or not on // mouseover, we'll have to reset onHighlightMouseover. - annotators[0].onHighlightMouseover.reset(); + annotators[0].onHighlightMouseover.calls.reset(); // Check that both instances of annotator are frozen _.invoke(highlights, 'mouseover'); _.invoke(highlights, 'mouseout'); @@ -86,7 +86,7 @@ define([ it('clicking twice reverts to default behavior', function() { highlights[0].click(); $(document).click(); - annotators[0].onHighlightMouseover.reset(); + annotators[0].onHighlightMouseover.calls.reset(); // Check that both instances of annotator are unfrozen _.invoke(highlights, 'mouseover'); @@ -116,7 +116,7 @@ define([ 'and unbinds one document click.edxnotes:freeze event handlers', function() { // Freeze all instances highlights[0].click(); - annotators[0].onHighlightMouseover.reset(); + annotators[0].onHighlightMouseover.calls.reset(); // Destroy second instance annotators[1].destroy(); @@ -163,17 +163,17 @@ define([ element: element }; - mockViewer.on = jasmine.createSpy().andReturn(mockViewer); - mockViewer.hide = jasmine.createSpy().andReturn(mockViewer); - mockViewer.destroy = jasmine.createSpy().andReturn(mockViewer); - mockViewer.addField = jasmine.createSpy().andCallFake(function (options) { + mockViewer.on = jasmine.createSpy().and.returnValue(mockViewer); + mockViewer.hide = jasmine.createSpy().and.returnValue(mockViewer); + mockViewer.destroy = jasmine.createSpy().and.returnValue(mockViewer); + mockViewer.addField = jasmine.createSpy().and.callFake(function (options) { mockViewer.fields.push(options); return mockViewer; }); - spyOn(element, 'bind').andReturn(element); - spyOn(element, 'appendTo').andReturn(element); - spyOn(Annotator, 'Viewer').andReturn(mockViewer); + spyOn(element, 'bind').and.returnValue(element); + spyOn(element, 'appendTo').and.returnValue(element); + spyOn(Annotator, 'Viewer').and.returnValue(mockViewer); annotators[0]._setupViewer(); }); @@ -183,13 +183,13 @@ define([ }); it('should hide the annotator on creation', function () { - expect(mockViewer.hide.callCount).toBe(1); + expect(mockViewer.hide.calls.count()).toBe(1); }); it('should setup the default text field', function () { - var args = mockViewer.addField.mostRecentCall.args[0]; + var args = mockViewer.addField.calls.mostRecent().args[0]; - expect(mockViewer.addField.callCount).toBe(1); + expect(mockViewer.addField.calls.count()).toBe(1); expect(_.isFunction(args.load)).toBeTruthy(); }); diff --git a/lms/static/js/spec/edxnotes/views/tab_item_spec.js b/lms/static/js/spec/edxnotes/views/tab_item_spec.js index d455f2d6f9..4e7cc208f3 100644 --- a/lms/static/js/spec/edxnotes/views/tab_item_spec.js +++ b/lms/static/js/spec/edxnotes/views/tab_item_spec.js @@ -1,11 +1,10 @@ define([ 'jquery', 'common/js/spec_helpers/template_helpers', 'js/edxnotes/collections/tabs', - 'js/edxnotes/views/tabs_list', 'js/spec/edxnotes/custom_matchers', 'jasmine-jquery' -], function($, TemplateHelpers, TabsCollection, TabsListView, customMatchers) { + 'js/edxnotes/views/tabs_list' +], function($, TemplateHelpers, TabsCollection, TabsListView) { 'use strict'; describe('EdxNotes TabItemView', function() { beforeEach(function () { - customMatchers(this); TemplateHelpers.installTemplate('templates/edxnotes/tab-item'); this.collection = new TabsCollection([ {identifier: 'first-item'}, diff --git a/lms/static/js/spec/edxnotes/views/tab_view_spec.js b/lms/static/js/spec/edxnotes/views/tab_view_spec.js index 690d5f3339..6fb7400c27 100644 --- a/lms/static/js/spec/edxnotes/views/tab_view_spec.js +++ b/lms/static/js/spec/edxnotes/views/tab_view_spec.js @@ -1,9 +1,8 @@ define([ 'jquery', 'backbone', 'common/js/spec_helpers/template_helpers', 'js/edxnotes/collections/tabs', - 'js/edxnotes/views/tabs_list', 'js/edxnotes/views/tab_view', - 'js/spec/edxnotes/custom_matchers', 'jasmine-jquery' + 'js/edxnotes/views/tabs_list', 'js/edxnotes/views/tab_view' ], function( - $, Backbone, TemplateHelpers, TabsCollection, TabsListView, TabView, customMatchers + $, Backbone, TemplateHelpers, TabsCollection, TabsListView, TabView ) { 'use strict'; describe('EdxNotes TabView', function() { @@ -41,7 +40,6 @@ define([ }; beforeEach(function () { - customMatchers(this); loadFixtures('js/fixtures/edxnotes/edxnotes.html'); TemplateHelpers.installTemplates([ 'templates/edxnotes/note-item', 'templates/edxnotes/tab-item' diff --git a/lms/static/js/spec/edxnotes/views/tabs/course_structure_spec.js b/lms/static/js/spec/edxnotes/views/tabs/course_structure_spec.js index 39b01573bd..f372118456 100644 --- a/lms/static/js/spec/edxnotes/views/tabs/course_structure_spec.js +++ b/lms/static/js/spec/edxnotes/views/tabs/course_structure_spec.js @@ -1,11 +1,9 @@ define([ 'jquery', 'underscore', 'common/js/spec_helpers/template_helpers', 'js/spec/edxnotes/helpers', 'js/edxnotes/collections/notes', 'js/edxnotes/collections/tabs', - 'js/edxnotes/views/tabs/course_structure', 'js/spec/edxnotes/custom_matchers', - 'jasmine-jquery' + 'js/edxnotes/views/tabs/course_structure' ], function( - $, _, TemplateHelpers, Helpers, NotesCollection, TabsCollection, CourseStructureView, - customMatchers + $, _, TemplateHelpers, Helpers, NotesCollection, TabsCollection, CourseStructureView ) { 'use strict'; describe('EdxNotes CourseStructureView', function() { @@ -34,7 +32,6 @@ define([ }; beforeEach(function () { - customMatchers(this); loadFixtures('js/fixtures/edxnotes/edxnotes.html'); TemplateHelpers.installTemplates([ 'templates/edxnotes/note-item', 'templates/edxnotes/tab-item' diff --git a/lms/static/js/spec/edxnotes/views/tabs/recent_activity_spec.js b/lms/static/js/spec/edxnotes/views/tabs/recent_activity_spec.js index fa18680809..de731caf34 100644 --- a/lms/static/js/spec/edxnotes/views/tabs/recent_activity_spec.js +++ b/lms/static/js/spec/edxnotes/views/tabs/recent_activity_spec.js @@ -1,9 +1,9 @@ define([ 'jquery', 'common/js/spec_helpers/template_helpers', 'common/js/spec_helpers/ajax_helpers', 'js/edxnotes/collections/notes', 'js/edxnotes/collections/tabs', 'js/edxnotes/views/tabs/recent_activity', - 'js/spec/edxnotes/custom_matchers', 'js/spec/edxnotes/helpers', 'jasmine-jquery' + 'js/spec/edxnotes/helpers' ], function( - $, TemplateHelpers, AjaxHelpers, NotesCollection, TabsCollection, RecentActivityView, customMatchers, Helpers + $, TemplateHelpers, AjaxHelpers, NotesCollection, TabsCollection, RecentActivityView, Helpers ) { 'use strict'; describe('EdxNotes RecentActivityView', function() { @@ -64,7 +64,6 @@ define([ recentActivityTabId = '#recent-panel'; beforeEach(function () { - customMatchers(this); loadFixtures('js/fixtures/edxnotes/edxnotes.html'); TemplateHelpers.installTemplates([ 'templates/edxnotes/note-item', 'templates/edxnotes/tab-item' diff --git a/lms/static/js/spec/edxnotes/views/tabs/search_results_spec.js b/lms/static/js/spec/edxnotes/views/tabs/search_results_spec.js index 58286bf1e8..df24fda839 100644 --- a/lms/static/js/spec/edxnotes/views/tabs/search_results_spec.js +++ b/lms/static/js/spec/edxnotes/views/tabs/search_results_spec.js @@ -1,10 +1,9 @@ define([ 'jquery', 'underscore', 'common/js/spec_helpers/template_helpers', 'common/js/spec_helpers/ajax_helpers', 'logger', 'js/edxnotes/collections/tabs', 'js/edxnotes/views/tabs/search_results', - 'js/spec/edxnotes/custom_matchers', 'js/spec/edxnotes/helpers', 'jasmine-jquery' + 'js/spec/edxnotes/helpers' ], function( - $, _, TemplateHelpers, AjaxHelpers, Logger, TabsCollection, SearchResultsView, - customMatchers, Helpers + $, _, TemplateHelpers, AjaxHelpers, Logger, TabsCollection, SearchResultsView, Helpers ) { 'use strict'; describe('EdxNotes SearchResultsView', function() { @@ -69,7 +68,6 @@ define([ searchResultsTabId = "#search-results-panel"; beforeEach(function () { - customMatchers(this); loadFixtures('js/fixtures/edxnotes/edxnotes.html'); TemplateHelpers.installTemplates([ 'templates/edxnotes/note-item', 'templates/edxnotes/tab-item' @@ -146,7 +144,7 @@ define([ it('can clear search results if tab is closed', function () { var view = getView(this.tabsCollection), requests = AjaxHelpers.requests(this); - spyOn(view.searchBox, 'clearInput').andCallThrough(); + spyOn(view.searchBox, 'clearInput').and.callThrough(); submitForm(view.searchBox, 'test_query'); Helpers.respondToRequest(requests, responseJson, true); diff --git a/lms/static/js/spec/edxnotes/views/tabs/tags_spec.js b/lms/static/js/spec/edxnotes/views/tabs/tags_spec.js index 811167f589..fdeeec1dde 100644 --- a/lms/static/js/spec/edxnotes/views/tabs/tags_spec.js +++ b/lms/static/js/spec/edxnotes/views/tabs/tags_spec.js @@ -1,11 +1,9 @@ define([ 'jquery', 'underscore', 'common/js/spec_helpers/template_helpers', 'js/spec/edxnotes/helpers', 'js/edxnotes/collections/notes', 'js/edxnotes/collections/tabs', - 'js/edxnotes/views/tabs/tags', 'js/spec/edxnotes/custom_matchers', - 'jasmine-jquery' + 'js/edxnotes/views/tabs/tags' ], function( - $, _, TemplateHelpers, Helpers, NotesCollection, TabsCollection, TagsView, - customMatchers + $, _, TemplateHelpers, Helpers, NotesCollection, TabsCollection, TagsView ) { 'use strict'; describe('EdxNotes TagsView', function() { @@ -38,7 +36,6 @@ define([ }; beforeEach(function () { - customMatchers(this); loadFixtures('js/fixtures/edxnotes/edxnotes.html'); TemplateHelpers.installTemplates([ 'templates/edxnotes/note-item', 'templates/edxnotes/tab-item' diff --git a/lms/static/js/spec/edxnotes/views/tabs_list_spec.js b/lms/static/js/spec/edxnotes/views/tabs_list_spec.js index 35bddcd34d..5109405c79 100644 --- a/lms/static/js/spec/edxnotes/views/tabs_list_spec.js +++ b/lms/static/js/spec/edxnotes/views/tabs_list_spec.js @@ -1,11 +1,10 @@ define([ 'jquery', 'common/js/spec_helpers/template_helpers', 'js/edxnotes/collections/tabs', - 'js/edxnotes/views/tabs_list', 'js/spec/edxnotes/custom_matchers', 'jasmine-jquery' -], function($, TemplateHelpers, TabsCollection, TabsListView, customMatchers) { + 'js/edxnotes/views/tabs_list' +], function($, TemplateHelpers, TabsCollection, TabsListView) { 'use strict'; describe('EdxNotes TabsListView', function() { beforeEach(function () { - customMatchers(this); TemplateHelpers.installTemplate('templates/edxnotes/tab-item'); this.collection = new TabsCollection([ {identifier: 'first-item'}, diff --git a/lms/static/js/spec/edxnotes/views/visibility_decorator_spec.js b/lms/static/js/spec/edxnotes/views/visibility_decorator_spec.js index ddd9c651b1..3aa99b33dc 100644 --- a/lms/static/js/spec/edxnotes/views/visibility_decorator_spec.js +++ b/lms/static/js/spec/edxnotes/views/visibility_decorator_spec.js @@ -1,7 +1,7 @@ define([ 'annotator_1.2.9', 'js/edxnotes/views/visibility_decorator', - 'js/spec/edxnotes/helpers', 'js/spec/edxnotes/custom_matchers' -], function(Annotator, VisibilityDecorator, Helpers, customMatchers) { + 'js/spec/edxnotes/helpers' +], function(Annotator, VisibilityDecorator, Helpers) { 'use strict'; describe('EdxNotes VisibilityDecorator', function() { var params = { @@ -14,7 +14,6 @@ define([ }; beforeEach(function() { - customMatchers(this); loadFixtures('js/fixtures/edxnotes/edxnotes_wrapper.html'); this.wrapper = document.getElementById('edx-notes-wrapper-123'); }); diff --git a/lms/static/js/spec/financial-assistance/financial_assistance_form_view_spec.js b/lms/static/js/spec/financial-assistance/financial_assistance_form_view_spec.js index 2aca04e9f6..cc1a68fcd3 100644 --- a/lms/static/js/spec/financial-assistance/financial_assistance_form_view_spec.js +++ b/lms/static/js/spec/financial-assistance/financial_assistance_form_view_spec.js @@ -108,7 +108,7 @@ define([ view.$('#financial-assistance-course').val(selectValue); view.$('#financial-assistance-income').val(1312); - view.$('textarea').html('w'.repeat(801)); + view.$('textarea').html(Array(802).join("w")); }; validSubmission = function() { diff --git a/lms/static/js/spec/instructor_dashboard/certificates_bulk_exception_spec.js b/lms/static/js/spec/instructor_dashboard/certificates_bulk_exception_spec.js index ce9d81658c..9763baee7a 100644 --- a/lms/static/js/spec/instructor_dashboard/certificates_bulk_exception_spec.js +++ b/lms/static/js/spec/instructor_dashboard/certificates_bulk_exception_spec.js @@ -31,7 +31,7 @@ define([ it('bind the ajax call and the result will be success', function() { var submitCallback; - spyOn($, "ajax").andCallFake(function(params) { + spyOn($, "ajax").and.callFake(function(params) { params.success({ row_errors: {}, general_errors: [], @@ -41,7 +41,7 @@ define([ always: function() {} }; }); - submitCallback = jasmine.createSpy().andReturn(); + submitCallback = jasmine.createSpy().and.returnValue(); this.view.$el.find(SELECTORS.bulk_white_list_exception_form).submit(submitCallback); this.view.$el.find(SELECTORS.upload_csv_button).click(); expect($(SELECTORS.bulk_exception_results).text()).toContain('1 learner is successfully added to the ' + @@ -50,7 +50,7 @@ define([ it('bind the ajax call and the result will be general error', function() { var submitCallback; - spyOn($, "ajax").andCallFake(function(params) { + spyOn($, "ajax").and.callFake(function(params) { params.success({ row_errors: {}, general_errors: ["File is not attached."], @@ -60,7 +60,7 @@ define([ always: function() {} }; }); - submitCallback = jasmine.createSpy().andReturn(); + submitCallback = jasmine.createSpy().and.returnValue(); this.view.$el.find(SELECTORS.bulk_white_list_exception_form).submit(submitCallback); this.view.$el.find(SELECTORS.upload_csv_button).click(); expect($(SELECTORS.bulk_exception_results).text()).toContain('File is not attached.'); @@ -68,7 +68,7 @@ define([ it('bind the ajax call and the result will be singular form of row errors', function() { var submitCallback; - spyOn($, "ajax").andCallFake(function(params) { + spyOn($, "ajax").and.callFake(function(params) { params.success({ general_errors: [], row_errors: { @@ -83,7 +83,7 @@ define([ always: function() {} }; }); - submitCallback = jasmine.createSpy().andReturn(); + submitCallback = jasmine.createSpy().and.returnValue(); this.view.$el.find(SELECTORS.bulk_white_list_exception_form).submit(submitCallback); this.view.$el.find(SELECTORS.upload_csv_button).click(); expect($(SELECTORS.bulk_exception_results).text()).toContain('1 record is not in correct format'); @@ -95,7 +95,7 @@ define([ it('bind the ajax call and the result will be plural form of row errors', function() { var submitCallback; - spyOn($, "ajax").andCallFake(function(params) { + spyOn($, "ajax").and.callFake(function(params) { params.success({ general_errors: [], row_errors: { @@ -110,7 +110,7 @@ define([ always: function() {} }; }); - submitCallback = jasmine.createSpy().andReturn(); + submitCallback = jasmine.createSpy().and.returnValue(); this.view.$el.find(SELECTORS.bulk_white_list_exception_form).submit(submitCallback); this.view.$el.find(SELECTORS.upload_csv_button).click(); expect($(SELECTORS.bulk_exception_results).text()).toContain('2 records are not in correct format'); @@ -122,7 +122,7 @@ define([ it('toggle message details', function() { var submitCallback; - spyOn($, "ajax").andCallFake(function(params) { + spyOn($, "ajax").and.callFake(function(params) { params.success({ row_errors: {}, general_errors: [], @@ -132,7 +132,7 @@ define([ always: function() {} }; }); - submitCallback = jasmine.createSpy().andReturn(); + submitCallback = jasmine.createSpy().and.returnValue(); this.view.$el.find(SELECTORS.bulk_white_list_exception_form).submit(submitCallback); this.view.$el.find(SELECTORS.upload_csv_button).click(); expect(this.view.$el.find("div.message > .successfully-added")).toBeHidden(); diff --git a/lms/static/js/spec/instructor_dashboard/certificates_spec.js b/lms/static/js/spec/instructor_dashboard/certificates_spec.js index 6db15104dd..870ca8202b 100644 --- a/lms/static/js/spec/instructor_dashboard/certificates_spec.js +++ b/lms/static/js/spec/instructor_dashboard/certificates_spec.js @@ -65,21 +65,21 @@ define([ }); it("does not regenerate certificates if user cancels operation in confirm popup", function() { - spyOn(window, 'confirm').andReturn(false); + spyOn(window, 'confirm').and.returnValue(false); $regenerate_certificates_button.click(); expect(window.confirm).toHaveBeenCalled(); AjaxHelpers.expectNoRequests(requests); }); it("sends regenerate certificates request if user accepts operation in confirm popup", function() { - spyOn(window, 'confirm').andReturn(true); + spyOn(window, 'confirm').and.returnValue(true); $regenerate_certificates_button.click(); expect(window.confirm).toHaveBeenCalled(); AjaxHelpers.expectRequest(requests, 'POST', expected.url); }); it("sends regenerate certificates request with selected certificate statuses", function() { - spyOn(window, 'confirm').andReturn(true); + spyOn(window, 'confirm').and.returnValue(true); select_options(expected.selected_statuses); @@ -88,7 +88,7 @@ define([ }); it("displays error message in case of server side error", function() { - spyOn(window, 'confirm').andReturn(true); + spyOn(window, 'confirm').and.returnValue(true); select_options(expected.selected_statuses); $regenerate_certificates_button.click(); @@ -97,7 +97,7 @@ define([ }); it("displays error message returned by the server in case of unsuccessful request", function() { - spyOn(window, 'confirm').andReturn(true); + spyOn(window, 'confirm').and.returnValue(true); select_options(expected.selected_statuses); $regenerate_certificates_button.click(); @@ -106,7 +106,7 @@ define([ }); it("displays success message returned by the server in case of successful request", function() { - spyOn(window, 'confirm').andReturn(true); + spyOn(window, 'confirm').and.returnValue(true); select_options(expected.selected_statuses); $regenerate_certificates_button.click(); diff --git a/lms/static/js/spec/instructor_dashboard/ecommerce_spec.js b/lms/static/js/spec/instructor_dashboard/ecommerce_spec.js index 273fbd6f53..c2c8d7cb8c 100644 --- a/lms/static/js/spec/instructor_dashboard/ecommerce_spec.js +++ b/lms/static/js/spec/instructor_dashboard/ecommerce_spec.js @@ -24,7 +24,7 @@ define(['backbone', 'jquery', 'js/instructor_dashboard/ecommerce'], var target = expiryCouponView.$el.find('input[type="checkbox"]'); target.attr("checked","checked"); target.click(); - expect(expiryCouponView.$el.find('#coupon_expiration_date')).toHaveAttr('style','display: inline;'); + expect(expiryCouponView.$el.find('#coupon_expiration_date').is(':visible')).toBe(true); }); it("hides the input field when the checkbox is unchecked", function () { diff --git a/lms/static/js/spec/instructor_dashboard/student_admin_spec.js b/lms/static/js/spec/instructor_dashboard/student_admin_spec.js index fe432883c5..662930be63 100644 --- a/lms/static/js/spec/instructor_dashboard/student_admin_spec.js +++ b/lms/static/js/spec/instructor_dashboard/student_admin_spec.js @@ -17,7 +17,7 @@ define(['jquery', 'coffee/src/instructor_dashboard/student_admin', 'common/js/sp dashboard_api_url = '/courses/PU/FSc/2014_T4/instructor/api'; unique_student_identifier = "test@example.com"; alert_msg = ''; - spyOn(window, 'alert').andCallFake(function(message) { + spyOn(window, 'alert').and.callFake(function(message) { alert_msg = message; }); diff --git a/lms/static/js/spec/learner_dashboard/program_card_view_spec.js b/lms/static/js/spec/learner_dashboard/program_card_view_spec.js index f0151c8ba8..43eac9542f 100644 --- a/lms/static/js/spec/learner_dashboard/program_card_view_spec.js +++ b/lms/static/js/spec/learner_dashboard/program_card_view_spec.js @@ -67,7 +67,7 @@ define([ }); it('should handle exceptions from reEvaluatePicture', function(){ - spyOn(view, 'reEvaluatePicture').andCallFake(function(){ + spyOn(view, 'reEvaluatePicture').and.callFake(function(){ throw {name:'Picturefill had exceptions'}; }); view.reLoadBannerImage(); diff --git a/lms/static/js/spec/main.js b/lms/static/js/spec/main.js index f25edd870b..b8942877cd 100644 --- a/lms/static/js/spec/main.js +++ b/lms/static/js/spec/main.js @@ -1,6 +1,8 @@ (function(requirejs, define) { // TODO: how can we share the vast majority of this config that is in common with CMS? requirejs.config({ + baseUrl: '/base/', + paths: { 'gettext': 'xmodule_js/common_static/js/test/i18n', 'codemirror': 'xmodule_js/common_static/js/vendor/CodeMirror/codemirror', @@ -29,8 +31,8 @@ 'moment': 'xmodule_js/common_static/js/vendor/moment.min', 'moment-with-locales': 'xmodule_js/common_static/js/vendor/moment-with-locales.min', 'text': 'xmodule_js/common_static/js/vendor/requirejs/text', - 'underscore': 'xmodule_js/common_static/common/js/vendor/underscore', - 'underscore.string': 'xmodule_js/common_static/common/js/vendor/underscore.string', + 'underscore': 'common/js/vendor/underscore', + 'underscore.string': 'common/js/vendor/underscore.string', 'backbone': 'xmodule_js/common_static/js/vendor/backbone-min', 'backbone.associations': 'xmodule_js/common_static/js/vendor/backbone-associations-min', 'backbone.paginator': 'xmodule_js/common_static/js/vendor/backbone.paginator.min', @@ -43,10 +45,10 @@ 'accessibility': 'xmodule_js/common_static/js/src/accessibility_tools', 'sinon': 'xmodule_js/common_static/js/vendor/sinon-1.17.0', 'squire': 'xmodule_js/common_static/js/vendor/Squire', - 'jasmine-jquery': 'xmodule_js/common_static/js/vendor/jasmine-jquery', 'jasmine-imagediff': 'xmodule_js/common_static/js/vendor/jasmine-imagediff', 'jasmine-stealth': 'xmodule_js/common_static/js/vendor/jasmine-stealth', - 'jasmine.async': 'xmodule_js/common_static/js/vendor/jasmine.async', + 'jasmine-waituntil': 'xmodule_js/common_static/js/libs/jasmine-waituntil', + 'jasmine-extensions': 'xmodule_js/common_static/js/libs/jasmine-extensions', 'domReady': 'xmodule_js/common_static/js/vendor/domReady', 'mathjax': '//cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // jshint ignore:line 'youtube': '//www.youtube.com/player_api?noext', @@ -102,8 +104,8 @@ // Common edx utils 'common/js/utils/edx.utils.validate': 'xmodule_js/common_static/common/js/utils/edx.utils.validate', - 'slick.grid': 'xmodule_js/common_static/js/vendor/slick.grid', - 'slick.core': 'xmodule_js/common_static/js/vendor/slick.core' + 'slick.core': 'xmodule_js/common_static/js/vendor/slick.core', + 'slick.grid': 'xmodule_js/common_static/js/vendor/slick.grid' }, shim: { 'gettext': { @@ -256,18 +258,15 @@ 'sinon': { exports: 'sinon' }, - 'jasmine-jquery': { - deps: ['jasmine'] - }, - 'jasmine-imagediff': { - deps: ['jasmine'] - }, + 'jasmine-imagediff': {}, 'jasmine-stealth': { - deps: ['jasmine'] + deps: ['underscore', 'underscore.string'] }, - 'jasmine.async': { - deps: ['jasmine'], - exports: 'AsyncSpec' + 'jasmine-waituntil': { + deps: ['jquery'] + }, + 'jasmine-extensions': { + deps: ['jquery'] }, 'xblock/core': { exports: 'XBlock', @@ -366,11 +365,18 @@ deps: [ 'jquery', 'underscore', 'underscore.string', 'backbone', 'gettext' ], init: function() { // Set global variables that the payment code is expecting to be defined - window._ = require('underscore'); - window._.str = require('underscore.string'); - window.edx = edx || {}; - window.edx.HtmlUtils = require('edx-ui-toolkit/js/utils/html-utils'); - window.edx.StringUtils = require('edx-ui-toolkit/js/utils/string-utils'); + require([ + 'underscore', + 'underscore.string', + 'edx-ui-toolkit/js/utils/html-utils', + 'edx-ui-toolkit/js/utils/string-utils' + ], function (_, str, HtmlUtils, StringUtils) { + window._ = _; + window._.str = str; + window.edx = edx || {}; + window.edx.HtmlUtils = HtmlUtils; + window.edx.StringUtils = StringUtils; + }); } }, 'js/verify_student/views/intro_step_view': { @@ -495,8 +501,10 @@ exports: 'DiscussionUtil', init: function() { // Set global variables that the discussion code is expecting to be defined - window.Backbone = require('backbone'); - window.URI = require('URI'); + require(['backbone', 'URI'], function (Backbone, URI) { + window.Backbone = Backbone; + window.URI = URI; + }); } }, 'xmodule_js/common_static/coffee/src/discussion/content': { @@ -550,13 +558,15 @@ }, 'xmodule_js/common_static/coffee/src/discussion/views/discussion_thread_show_view': { deps: [ - 'xmodule_js/common_static/coffee/src/discussion/utils' + 'xmodule_js/common_static/coffee/src/discussion/utils', + 'xmodule_js/common_static/coffee/src/discussion/views/discussion_content_view' ], exports: 'DiscussionThreadShowView' }, 'xmodule_js/common_static/coffee/src/discussion/views/discussion_thread_view': { deps: [ - 'xmodule_js/common_static/coffee/src/discussion/utils' + 'xmodule_js/common_static/coffee/src/discussion/utils', + 'xmodule_js/common_static/coffee/src/discussion/views/discussion_content_view' ], exports: 'DiscussionThreadView' }, @@ -638,124 +648,131 @@ } }); - // TODO: why do these need 'lms/include' at the front but the CMS equivalent logic doesn't? - define([ - // Run the LMS tests - 'lms/include/js/spec/components/header/header_spec.js', - 'lms/include/js/spec/components/card/card_spec.js', - 'lms/include/js/spec/staff_debug_actions_spec.js', - 'lms/include/js/spec/views/notification_spec.js', - 'lms/include/js/spec/views/file_uploader_spec.js', - 'lms/include/js/spec/dashboard/donation.js', - 'lms/include/js/spec/dashboard/dropdown_spec.js', - 'lms/include/js/spec/dashboard/track_events_spec.js', - 'lms/include/js/spec/groups/views/cohorts_spec.js', - 'lms/include/js/spec/shoppingcart/shoppingcart_spec.js', - 'lms/include/js/spec/instructor_dashboard/ecommerce_spec.js', - 'lms/include/js/spec/instructor_dashboard/student_admin_spec.js', - 'lms/include/js/spec/instructor_dashboard/certificates_exception_spec.js', - 'lms/include/js/spec/instructor_dashboard/certificates_invalidation_spec.js', - 'lms/include/js/spec/instructor_dashboard/certificates_bulk_exception_spec.js', - 'lms/include/js/spec/instructor_dashboard/certificates_spec.js', - 'lms/include/js/spec/student_account/account_spec.js', - 'lms/include/js/spec/student_account/access_spec.js', - 'lms/include/js/spec/student_account/logistration_factory_spec.js', - 'lms/include/js/spec/student_account/finish_auth_spec.js', - 'lms/include/js/spec/student_account/hinted_login_spec.js', - 'lms/include/js/spec/student_account/login_spec.js', - 'lms/include/js/spec/student_account/institution_login_spec.js', - 'lms/include/js/spec/student_account/register_spec.js', - 'lms/include/js/spec/student_account/password_reset_spec.js', - 'lms/include/js/spec/student_account/enrollment_spec.js', - 'lms/include/js/spec/student_account/emailoptin_spec.js', - 'lms/include/js/spec/student_account/shoppingcart_spec.js', - 'lms/include/js/spec/student_account/account_settings_factory_spec.js', - 'lms/include/js/spec/student_account/account_settings_fields_spec.js', - 'lms/include/js/spec/student_account/account_settings_view_spec.js', - 'lms/include/js/spec/views/fields_spec.js', - 'lms/include/js/spec/student_profile/learner_profile_factory_spec.js', - 'lms/include/js/spec/student_profile/learner_profile_view_spec.js', - 'lms/include/js/spec/student_profile/learner_profile_fields_spec.js', - 'lms/include/js/spec/student_profile/share_modal_view_spec.js', - 'lms/include/js/spec/student_profile/badge_view_spec.js', - 'lms/include/js/spec/student_profile/section_two_tab_spec.js', - 'lms/include/js/spec/student_profile/badge_list_view_spec.js', - 'lms/include/js/spec/student_profile/badge_list_container_spec.js', - 'lms/include/js/spec/verify_student/pay_and_verify_view_spec.js', - 'lms/include/js/spec/verify_student/reverify_view_spec.js', - 'lms/include/js/spec/verify_student/webcam_photo_view_spec.js', - 'lms/include/js/spec/verify_student/image_input_spec.js', - 'lms/include/js/spec/verify_student/review_photos_step_view_spec.js', - 'lms/include/js/spec/verify_student/make_payment_step_view_spec.js', - 'lms/include/js/spec/verify_student/make_payment_step_view_ab_testing_spec.js', - 'lms/include/js/spec/edxnotes/utils/logger_spec.js', - 'lms/include/js/spec/edxnotes/views/notes_factory_spec.js', - 'lms/include/js/spec/edxnotes/views/shim_spec.js', - 'lms/include/js/spec/edxnotes/views/note_item_spec.js', - 'lms/include/js/spec/edxnotes/views/notes_page_spec.js', - 'lms/include/js/spec/edxnotes/views/search_box_spec.js', - 'lms/include/js/spec/edxnotes/views/tabs_list_spec.js', - 'lms/include/js/spec/edxnotes/views/tab_item_spec.js', - 'lms/include/js/spec/edxnotes/views/tab_view_spec.js', - 'lms/include/js/spec/edxnotes/views/tabs/search_results_spec.js', - 'lms/include/js/spec/edxnotes/views/tabs/recent_activity_spec.js', - 'lms/include/js/spec/edxnotes/views/tabs/course_structure_spec.js', - 'lms/include/js/spec/edxnotes/views/tabs/tags_spec.js', - 'lms/include/js/spec/edxnotes/views/visibility_decorator_spec.js', - 'lms/include/js/spec/edxnotes/views/notes_visibility_factory_spec.js', - 'lms/include/js/spec/edxnotes/models/tab_spec.js', - 'lms/include/js/spec/edxnotes/models/note_spec.js', - 'lms/include/js/spec/edxnotes/plugins/accessibility_spec.js', - 'lms/include/js/spec/edxnotes/plugins/events_spec.js', - 'lms/include/js/spec/edxnotes/plugins/scroller_spec.js', - 'lms/include/js/spec/edxnotes/plugins/caret_navigation_spec.js', - 'lms/include/js/spec/edxnotes/plugins/store_error_handler_spec.js', - 'lms/include/js/spec/edxnotes/collections/notes_spec.js', - 'lms/include/js/spec/search/search_spec.js', - 'lms/include/js/spec/navigation_spec.js', - 'lms/include/js/spec/courseware/updates_visibility.js', - 'lms/include/js/spec/discovery/collections/filters_spec.js', - 'lms/include/js/spec/discovery/models/course_card_spec.js', - 'lms/include/js/spec/discovery/models/course_directory_spec.js', - 'lms/include/js/spec/discovery/models/facet_option_spec.js', - 'lms/include/js/spec/discovery/models/filter_spec.js', - 'lms/include/js/spec/discovery/models/search_state_spec.js', - 'lms/include/js/spec/discovery/views/course_card_spec.js', - 'lms/include/js/spec/discovery/views/courses_listing_spec.js', - 'lms/include/js/spec/discovery/views/filter_bar_spec.js', - 'lms/include/js/spec/discovery/views/refine_sidebar_spec.js', - 'lms/include/js/spec/discovery/views/search_form_spec.js', - 'lms/include/js/spec/discovery/discovery_factory_spec.js', - 'lms/include/js/spec/ccx/schedule_spec.js', - 'lms/include/support/js/spec/collections/enrollment_spec.js', - 'lms/include/support/js/spec/models/enrollment_spec.js', - 'lms/include/support/js/spec/views/enrollment_modal_spec.js', - 'lms/include/support/js/spec/views/enrollment_spec.js', - 'lms/include/support/js/spec/views/certificates_spec.js', - 'lms/include/teams/js/spec/collections/topic_collection_spec.js', - 'lms/include/teams/js/spec/teams_tab_factory_spec.js', - 'lms/include/teams/js/spec/views/edit_team_spec.js', - 'lms/include/teams/js/spec/views/edit_team_members_spec.js', - 'lms/include/teams/js/spec/views/instructor_tools_spec.js', - 'lms/include/teams/js/spec/views/my_teams_spec.js', - 'lms/include/teams/js/spec/views/team_card_spec.js', - 'lms/include/teams/js/spec/views/team_discussion_spec.js', - 'lms/include/teams/js/spec/views/team_profile_spec.js', - 'lms/include/teams/js/spec/views/teams_spec.js', - 'lms/include/teams/js/spec/views/teams_tab_spec.js', - 'lms/include/teams/js/spec/views/topic_card_spec.js', - 'lms/include/teams/js/spec/views/topic_teams_spec.js', - 'lms/include/teams/js/spec/views/topics_spec.js', - 'lms/include/teams/js/spec/views/team_profile_header_actions_spec.js', - 'lms/include/js/spec/financial-assistance/financial_assistance_form_view_spec.js', - 'lms/include/js/spec/bookmarks/bookmarks_list_view_spec.js', - 'lms/include/js/spec/bookmarks/bookmark_button_view_spec.js', - 'lms/include/js/spec/views/message_banner_spec.js', - 'lms/include/js/spec/markdown_editor_spec.js', - 'lms/include/js/spec/learner_dashboard/collection_list_view_spec.js', - 'lms/include/js/spec/learner_dashboard/sidebar_view_spec.js', - 'lms/include/js/spec/learner_dashboard/program_card_view_spec.js', - 'lms/include/js/spec/learner_dashboard/certificate_view_spec.js' - ]); + var testFiles = [ + 'js/spec/components/header/header_spec.js', + 'js/spec/components/card/card_spec.js', + 'js/spec/staff_debug_actions_spec.js', + 'js/spec/views/notification_spec.js', + 'js/spec/views/file_uploader_spec.js', + 'js/spec/dashboard/donation.js', + 'js/spec/dashboard/dropdown_spec.js', + 'js/spec/dashboard/track_events_spec.js', + 'js/spec/groups/views/cohorts_spec.js', + 'js/spec/shoppingcart/shoppingcart_spec.js', + 'js/spec/instructor_dashboard/ecommerce_spec.js', + 'js/spec/instructor_dashboard/student_admin_spec.js', + 'js/spec/instructor_dashboard/certificates_exception_spec.js', + 'js/spec/instructor_dashboard/certificates_invalidation_spec.js', + 'js/spec/instructor_dashboard/certificates_bulk_exception_spec.js', + 'js/spec/instructor_dashboard/certificates_spec.js', + 'js/spec/student_account/account_spec.js', + 'js/spec/student_account/access_spec.js', + 'js/spec/student_account/logistration_factory_spec.js', + 'js/spec/student_account/finish_auth_spec.js', + 'js/spec/student_account/hinted_login_spec.js', + 'js/spec/student_account/login_spec.js', + 'js/spec/student_account/institution_login_spec.js', + 'js/spec/student_account/register_spec.js', + 'js/spec/student_account/password_reset_spec.js', + 'js/spec/student_account/enrollment_spec.js', + 'js/spec/student_account/emailoptin_spec.js', + 'js/spec/student_account/shoppingcart_spec.js', + 'js/spec/student_account/account_settings_factory_spec.js', + 'js/spec/student_account/account_settings_fields_spec.js', + 'js/spec/student_account/account_settings_view_spec.js', + 'js/spec/views/fields_spec.js', + 'js/spec/student_profile/learner_profile_factory_spec.js', + 'js/spec/student_profile/learner_profile_view_spec.js', + 'js/spec/student_profile/learner_profile_fields_spec.js', + 'js/spec/student_profile/share_modal_view_spec.js', + 'js/spec/student_profile/badge_view_spec.js', + 'js/spec/student_profile/section_two_tab_spec.js', + 'js/spec/student_profile/badge_list_view_spec.js', + 'js/spec/student_profile/badge_list_container_spec.js', + 'js/spec/verify_student/pay_and_verify_view_spec.js', + 'js/spec/verify_student/reverify_view_spec.js', + 'js/spec/verify_student/webcam_photo_view_spec.js', + 'js/spec/verify_student/image_input_spec.js', + 'js/spec/verify_student/review_photos_step_view_spec.js', + 'js/spec/verify_student/make_payment_step_view_spec.js', + 'js/spec/verify_student/make_payment_step_view_ab_testing_spec.js', + 'js/spec/edxnotes/utils/logger_spec.js', + 'js/spec/edxnotes/views/notes_factory_spec.js', + 'js/spec/edxnotes/views/shim_spec.js', + 'js/spec/edxnotes/views/note_item_spec.js', + 'js/spec/edxnotes/views/notes_page_spec.js', + 'js/spec/edxnotes/views/search_box_spec.js', + 'js/spec/edxnotes/views/tabs_list_spec.js', + 'js/spec/edxnotes/views/tab_item_spec.js', + 'js/spec/edxnotes/views/tab_view_spec.js', + 'js/spec/edxnotes/views/tabs/search_results_spec.js', + 'js/spec/edxnotes/views/tabs/recent_activity_spec.js', + 'js/spec/edxnotes/views/tabs/course_structure_spec.js', + 'js/spec/edxnotes/views/tabs/tags_spec.js', + 'js/spec/edxnotes/views/visibility_decorator_spec.js', + 'js/spec/edxnotes/views/notes_visibility_factory_spec.js', + 'js/spec/edxnotes/models/tab_spec.js', + 'js/spec/edxnotes/models/note_spec.js', + 'js/spec/edxnotes/plugins/accessibility_spec.js', + 'js/spec/edxnotes/plugins/events_spec.js', + 'js/spec/edxnotes/plugins/scroller_spec.js', + 'js/spec/edxnotes/plugins/caret_navigation_spec.js', + 'js/spec/edxnotes/plugins/store_error_handler_spec.js', + 'js/spec/edxnotes/collections/notes_spec.js', + 'js/spec/search/search_spec.js', + 'js/spec/navigation_spec.js', + 'js/spec/courseware/updates_visibility.js', + 'js/spec/discovery/collections/filters_spec.js', + 'js/spec/discovery/models/course_card_spec.js', + 'js/spec/discovery/models/course_directory_spec.js', + 'js/spec/discovery/models/facet_option_spec.js', + 'js/spec/discovery/models/filter_spec.js', + 'js/spec/discovery/models/search_state_spec.js', + 'js/spec/discovery/views/course_card_spec.js', + 'js/spec/discovery/views/courses_listing_spec.js', + 'js/spec/discovery/views/filter_bar_spec.js', + 'js/spec/discovery/views/refine_sidebar_spec.js', + 'js/spec/discovery/views/search_form_spec.js', + 'js/spec/discovery/discovery_factory_spec.js', + 'js/spec/ccx/schedule_spec.js', + 'support/js/spec/collections/enrollment_spec.js', + 'support/js/spec/models/enrollment_spec.js', + 'support/js/spec/views/enrollment_modal_spec.js', + 'support/js/spec/views/enrollment_spec.js', + 'support/js/spec/views/certificates_spec.js', + 'teams/js/spec/collections/topic_collection_spec.js', + 'teams/js/spec/teams_tab_factory_spec.js', + 'teams/js/spec/views/edit_team_spec.js', + 'teams/js/spec/views/edit_team_members_spec.js', + 'teams/js/spec/views/instructor_tools_spec.js', + 'teams/js/spec/views/my_teams_spec.js', + 'teams/js/spec/views/team_card_spec.js', + 'teams/js/spec/views/team_discussion_spec.js', + 'teams/js/spec/views/team_profile_spec.js', + 'teams/js/spec/views/teams_spec.js', + 'teams/js/spec/views/teams_tab_spec.js', + 'teams/js/spec/views/topic_card_spec.js', + 'teams/js/spec/views/topic_teams_spec.js', + 'teams/js/spec/views/topics_spec.js', + 'teams/js/spec/views/team_profile_header_actions_spec.js', + 'js/spec/financial-assistance/financial_assistance_form_view_spec.js', + 'js/spec/bookmarks/bookmarks_list_view_spec.js', + 'js/spec/bookmarks/bookmark_button_view_spec.js', + 'js/spec/views/message_banner_spec.js', + 'js/spec/markdown_editor_spec.js', + 'js/spec/learner_dashboard/collection_list_view_spec.js', + 'js/spec/learner_dashboard/sidebar_view_spec.js', + 'js/spec/learner_dashboard/program_card_view_spec.js', + 'js/spec/learner_dashboard/certificate_view_spec.js' + ]; + + for (var i = 0; i < testFiles.length; i++) { + testFiles[i] = '/base/' + testFiles[i]; + } + + require(testFiles, function () { + // start test run, once Require.js is done + window.__karma__.start(); + }); }).call(this, requirejs, define); diff --git a/lms/static/js/spec/main_requirejs_coffee.js b/lms/static/js/spec/main_requirejs_coffee.js new file mode 100644 index 0000000000..0597f1e952 --- /dev/null +++ b/lms/static/js/spec/main_requirejs_coffee.js @@ -0,0 +1,23 @@ +(function(requirejs) { + 'use strict'; + requirejs.config({ + baseUrl: '/base/', + paths: { + "moment": "xmodule_js/common_static/js/vendor/moment.min", + "modernizr": "xmodule_js/common_static/edx-pattern-library/js/modernizr-custom", + "afontgarde": "xmodule_js/common_static/edx-pattern-library/js/afontgarde", + "edxicons": "xmodule_js/common_static/edx-pattern-library/js/edx-icons", + "draggabilly": "xmodule_js/common_static/js/vendor/draggabilly" + }, + "moment": { + exports: "moment" + }, + "modernizr": { + exports: "Modernizr" + }, + "afontgarde": { + exports: "AFontGarde" + } + }); + +}).call(this, requirejs, define); // jshint ignore:line diff --git a/lms/static/js/spec/navigation_spec.js b/lms/static/js/spec/navigation_spec.js index d0c51cd049..12e2964c59 100644 --- a/lms/static/js/spec/navigation_spec.js +++ b/lms/static/js/spec/navigation_spec.js @@ -15,7 +15,7 @@ define(['jquery', 'js/utils/navigation'], function($) { chapterMenu = accordion.children('.chapter-content-container').children('.chapter-menu'); this.KEY = $.ui.keyCode; - spyOn($.fn, 'focus').andCallThrough(); + spyOn($.fn, 'focus').and.callThrough(); edx.util.navigation.init(); }); diff --git a/lms/static/js/spec/search/search_spec.js b/lms/static/js/spec/search/search_spec.js index dce93d0ea3..7e18043dc0 100644 --- a/lms/static/js/spec/search/search_spec.js +++ b/lms/static/js/spec/search/search_spec.js @@ -77,14 +77,14 @@ define([ var collection = new SearchCollection([]); spyOn($, 'ajax'); collection.performSearch('search string'); - expect($.ajax.mostRecentCall.args[0].url).toEqual('/search/'); + expect($.ajax.calls.mostRecent().args[0].url).toEqual('/search/'); }); it('sends a request with course ID', function () { var collection = new SearchCollection([], { courseId: 'edx101' }); spyOn($, 'ajax'); collection.performSearch('search string'); - expect($.ajax.mostRecentCall.args[0].url).toEqual('/search/edx101'); + expect($.ajax.calls.mostRecent().args[0].url).toEqual('/search/edx101'); }); it('sends a request and parses the json result', function () { @@ -139,10 +139,10 @@ define([ AjaxHelpers.respondWithJson(requests, response); spyOn($, 'ajax'); this.collection.loadNextPage(); - expect($.ajax.mostRecentCall.args[0].url).toEqual(this.collection.url); - expect($.ajax.mostRecentCall.args[0].data.search_string).toEqual(searchString); - expect($.ajax.mostRecentCall.args[0].data.page_size).toEqual(this.collection.pageSize); - expect($.ajax.mostRecentCall.args[0].data.page_index).toEqual(2); + expect($.ajax.calls.mostRecent().args[0].url).toEqual(this.collection.url); + expect($.ajax.calls.mostRecent().args[0].data.search_string).toEqual(searchString); + expect($.ajax.calls.mostRecent().args[0].data.page_size).toEqual(this.collection.pageSize); + expect($.ajax.calls.mostRecent().args[0].data.page_index).toEqual(2); }); it('has next page', function () { @@ -164,18 +164,18 @@ define([ this.collection.performSearch('new search'); AjaxHelpers.skipResetRequest(requests); AjaxHelpers.respondWithJson(requests, response); - expect(this.onSearch.calls.length).toEqual(1); + expect(this.onSearch.calls.count()).toEqual(1); this.collection.performSearch('old search'); this.collection.cancelSearch(); AjaxHelpers.skipResetRequest(requests); - expect(this.onSearch.calls.length).toEqual(1); + expect(this.onSearch.calls.count()).toEqual(1); this.collection.loadNextPage(); this.collection.loadNextPage(); AjaxHelpers.skipResetRequest(requests); AjaxHelpers.respondWithJson(requests, response); - expect(this.onNext.calls.length).toEqual(1); + expect(this.onNext.calls.count()).toEqual(1); }); describe('reset state', function () { @@ -261,7 +261,7 @@ define([ function rendersItem() { expect(this.item.$el).toHaveAttr('role', 'region'); expect(this.item.$el).toHaveAttr('aria-label', 'search result'); - expect(this.item.$el).toContain('a[href="' + this.model.get('url') + '"]'); + expect(this.item.$el).toContainElement('a[href="' + this.model.get('url') + '"]'); expect(this.item.$el.find('.result-type')).toContainHtml(this.model.get('content_type')); expect(this.item.$el.find('.result-excerpt')).toContainHtml(this.model.get('excerpt')); expect(this.item.$el.find('.result-location')).toContainHtml('section ▸ subsection ▸ unit'); @@ -270,7 +270,7 @@ define([ function rendersSequentialItem() { expect(this.seqItem.$el).toHaveAttr('role', 'region'); expect(this.seqItem.$el).toHaveAttr('aria-label', 'search result'); - expect(this.seqItem.$el).toContain('a[href="' + this.seqModel.get('url') + '"]'); + expect(this.seqItem.$el).toContainElement('a[href="' + this.seqModel.get('url') + '"]'); expect(this.seqItem.$el.find('.result-type')).toBeEmpty(); expect(this.seqItem.$el.find('.result-excerpt')).toBeEmpty(); expect(this.seqItem.$el.find('.result-location')).toContainHtml('section ▸ subsection'); @@ -280,8 +280,8 @@ define([ this.model.collection = new SearchCollection([this.model], { course_id: 'edx101' }); this.item.render(); // Mock the redirect call - spyOn(this.item, 'redirect').andCallFake( function() {} ); - spyOn(Logger, 'log').andReturn($.Deferred().resolve()); + spyOn(this.item, 'redirect').and.callFake( function() {} ); + spyOn(Logger, 'log').and.returnValue($.Deferred().resolve()); this.item.$el.find('a').trigger('click'); expect(this.item.redirect).toHaveBeenCalled(); this.item.$el.trigger('click'); @@ -498,7 +498,6 @@ define([ 'templates/search/dashboard_search_item', 'templates/search/course_search_results', 'templates/search/dashboard_search_results', - 'templates/search/search_list', 'templates/search/search_loading', 'templates/search/search_error' ]); @@ -601,9 +600,9 @@ define([ function updatesNavigationHistory () { $('.search-field').val('edx'); $('.search-button').trigger('click'); - expect(Backbone.history.navigate.calls[0].args).toContain('search/edx'); + expect(Backbone.history.navigate.calls.mostRecent().args[0]).toContain('search/edx'); $('.cancel-button').trigger('click'); - expect(Backbone.history.navigate.calls[1].args).toContain(''); + expect(Backbone.history.navigate.calls.argsFor(1)[0]).toBe(''); } function cancelsSearchRequest () { diff --git a/lms/static/js/spec/shoppingcart/shoppingcart_spec.js b/lms/static/js/spec/shoppingcart/shoppingcart_spec.js index 1f0da04fc8..0f86f7c9f8 100644 --- a/lms/static/js/spec/shoppingcart/shoppingcart_spec.js +++ b/lms/static/js/spec/shoppingcart/shoppingcart_spec.js @@ -13,7 +13,7 @@ define(['common/js/spec_helpers/ajax_helpers', 'js/shoppingcart/shoppingcart'], el: $('.confirm-enrollment.cart-view form') }); - spyOn(view, 'responseFromServer').andCallFake(function() {}); + spyOn(view, 'responseFromServer').and.callFake(function() {}); // Spy on AJAX requests requests = AjaxHelpers.requests(this); @@ -36,7 +36,7 @@ define(['common/js/spec_helpers/ajax_helpers', 'js/shoppingcart/shoppingcart'], }); expect(view.responseFromServer).toHaveBeenCalled(); - var data = view.responseFromServer.mostRecentCall.args[0] + var data = view.responseFromServer.calls.mostRecent().args[0]; expect(data.is_course_enrollment_closed).toBe(true); }); @@ -50,7 +50,7 @@ define(['common/js/spec_helpers/ajax_helpers', 'js/shoppingcart/shoppingcart'], }); expect(view.responseFromServer).toHaveBeenCalled(); - var data = view.responseFromServer.mostRecentCall.args[0] + var data = view.responseFromServer.calls.mostRecent().args[0]; expect(data.is_course_enrollment_closed).toBe(false); }); diff --git a/lms/static/js/spec/staff_debug_actions_spec.js b/lms/static/js/spec/staff_debug_actions_spec.js index af92c098d6..3486fd7267 100644 --- a/lms/static/js/spec/staff_debug_actions_spec.js +++ b/lms/static/js/spec/staff_debug_actions_spec.js @@ -5,6 +5,8 @@ define([ 'common/js/spec_helpers/ajax_helpers' ], function (Backbone, $, tmp, AjaxHelpers) { + 'use strict'; + var StaffDebug = window.StaffDebug; describe('StaffDebugActions', function () { var location = 'i4x://edX/Open_DemoX/edx_demo_course/problem/test_loc'; @@ -20,8 +22,10 @@ define([ describe('get_url ', function () { it('defines url to courseware ajax entry point', function () { - spyOn(StaffDebug, "get_current_url").andReturn("/courses/edX/Open_DemoX/edx_demo_course/courseware/stuff"); - expect(StaffDebug.get_url('rescore_problem')).toBe('/courses/edX/Open_DemoX/edx_demo_course/instructor/api/rescore_problem'); + spyOn(StaffDebug, "get_current_url") + .and.returnValue("/courses/edX/Open_DemoX/edx_demo_course/courseware/stuff"); + expect(StaffDebug.get_url('rescore_problem')) + .toBe('/courses/edX/Open_DemoX/edx_demo_course/instructor/api/rescore_problem'); }); }); @@ -87,13 +91,13 @@ define([ spyOn($, 'ajax'); StaffDebug.reset(locationName, location); - expect($.ajax.mostRecentCall.args[0]['type']).toEqual('GET'); - expect($.ajax.mostRecentCall.args[0]['data']).toEqual({ + expect($.ajax.calls.mostRecent().args[0].type).toEqual('GET'); + expect($.ajax.calls.mostRecent().args[0].data).toEqual({ 'problem_to_reset': location, 'unique_student_identifier': 'userman', 'delete_module': false }); - expect($.ajax.mostRecentCall.args[0]['url']).toEqual( + expect($.ajax.calls.mostRecent().args[0].url).toEqual( '/instructor/api/reset_student_attempts' ); $('#' + fixture_id).remove(); @@ -106,13 +110,13 @@ define([ spyOn($, 'ajax'); StaffDebug.sdelete(locationName, location); - expect($.ajax.mostRecentCall.args[0]['type']).toEqual('GET'); - expect($.ajax.mostRecentCall.args[0]['data']).toEqual({ + expect($.ajax.calls.mostRecent().args[0].type).toEqual('GET'); + expect($.ajax.calls.mostRecent().args[0].data).toEqual({ 'problem_to_reset': location, 'unique_student_identifier': 'userman', 'delete_module': true }); - expect($.ajax.mostRecentCall.args[0]['url']).toEqual( + expect($.ajax.calls.mostRecent().args[0].url).toEqual( '/instructor/api/reset_student_attempts' ); @@ -126,13 +130,13 @@ define([ spyOn($, 'ajax'); StaffDebug.rescore(locationName, location); - expect($.ajax.mostRecentCall.args[0]['type']).toEqual('GET'); - expect($.ajax.mostRecentCall.args[0]['data']).toEqual({ + expect($.ajax.calls.mostRecent().args[0].type).toEqual('GET'); + expect($.ajax.calls.mostRecent().args[0].data).toEqual({ 'problem_to_reset': location, 'unique_student_identifier': 'userman', 'delete_module': false }); - expect($.ajax.mostRecentCall.args[0]['url']).toEqual( + expect($.ajax.calls.mostRecent().args[0].url).toEqual( '/instructor/api/rescore_problem' ); $('#' + fixture_id).remove(); diff --git a/lms/static/js/spec/student_account/access_spec.js b/lms/static/js/spec/student_account/access_spec.js index 88a73c1506..1f6c334984 100644 --- a/lms/static/js/spec/student_account/access_spec.js +++ b/lms/static/js/spec/student_account/access_spec.js @@ -78,11 +78,11 @@ view = new AccessView(_.extend(options, {el: $logistrationElement})); // Mock the redirect call - spyOn( view, 'redirect' ).andCallFake( function() {} ); + spyOn( view, 'redirect' ).and.callFake( function() {} ); // Mock the enrollment and shopping cart interfaces - spyOn( EnrollmentInterface, 'enroll' ).andCallFake( function() {} ); - spyOn( ShoppingCartInterface, 'addCourseToCart' ).andCallFake( function() {} ); + spyOn( EnrollmentInterface, 'enroll' ).and.callFake( function() {} ); + spyOn( ShoppingCartInterface, 'addCourseToCart' ).and.callFake( function() {} ); }; var assertForms = function(visibleType, hiddenType) { @@ -101,6 +101,7 @@ }; beforeEach(function() { + spyOn(window.history, 'pushState'); setFixtures('
'); TemplateHelpers.installTemplate('templates/student_account/access'); TemplateHelpers.installTemplate('templates/student_account/login'); @@ -139,9 +140,6 @@ it('toggles between the login and registration forms', function() { ajaxSpyAndInitialize(this, 'login'); - // Prevent URL from updating - spyOn(history, 'pushState').andCallFake( function() {} ); - // Simulate selection of the registration form selectForm('register'); assertForms('#register-form', '#login-form'); diff --git a/lms/static/js/spec/student_account/account_settings_fields_spec.js b/lms/static/js/spec/student_account/account_settings_fields_spec.js index 9d5b95616b..626c5b2f83 100644 --- a/lms/static/js/spec/student_account/account_settings_fields_spec.js +++ b/lms/static/js/spec/student_account/account_settings_fields_spec.js @@ -16,7 +16,11 @@ define(['backbone', 'jquery', 'underscore', 'common/js/spec_helpers/ajax_helpers beforeEach(function () { timerCallback = jasmine.createSpy('timerCallback'); - jasmine.Clock.useMock(); + jasmine.clock().install(); + }); + + afterEach(function() { + jasmine.clock().uninstall(); }); it("sends request to reset password on clicking link in PasswordFieldView", function() { diff --git a/lms/static/js/spec/student_account/account_spec.js b/lms/static/js/spec/student_account/account_spec.js index 3262192baf..bbca8f8ee2 100644 --- a/lms/static/js/spec/student_account/account_spec.js +++ b/lms/static/js/spec/student_account/account_spec.js @@ -104,7 +104,7 @@ define(['js/student_account/account'], var assertAjax = function(url, method, data) { expect($.ajax).toHaveBeenCalled(); - var ajaxArgs = $.ajax.mostRecentCall.args[0]; + var ajaxArgs = $.ajax.calls.mostRecent().args[0]; expect(ajaxArgs.url).toEqual(url); expect(ajaxArgs.type).toEqual(method); expect(ajaxArgs.data).toEqual(data); @@ -127,7 +127,7 @@ define(['js/student_account/account'], view = new edx.student.account.AccountView().render(); // Stub Ajax calls to return success/failure - spyOn($, "ajax").andCallFake(function() { + spyOn($, "ajax").and.callFake(function() { return $.Deferred(function(defer) { if (ajaxSuccess) { defer.resolve(); diff --git a/lms/static/js/spec/student_account/enrollment_spec.js b/lms/static/js/spec/student_account/enrollment_spec.js index 27cfdc9106..ac36790367 100644 --- a/lms/static/js/spec/student_account/enrollment_spec.js +++ b/lms/static/js/spec/student_account/enrollment_spec.js @@ -11,7 +11,7 @@ define(['common/js/spec_helpers/ajax_helpers', 'js/student_account/enrollment'], beforeEach(function() { // Mock the redirect call - spyOn(EnrollmentInterface, 'redirect').andCallFake(function() {}); + spyOn(EnrollmentInterface, 'redirect').and.callFake(function() {}); }); it('enrolls a user in a course', function() { diff --git a/lms/static/js/spec/student_account/finish_auth_spec.js b/lms/static/js/spec/student_account/finish_auth_spec.js index 2086526631..53565ef157 100644 --- a/lms/static/js/spec/student_account/finish_auth_spec.js +++ b/lms/static/js/spec/student_account/finish_auth_spec.js @@ -27,13 +27,13 @@ view = new FinishAuthView({}); // Mock the redirect call - spyOn( view, 'redirect' ).andCallFake( function() {} ); + spyOn( view, 'redirect' ).and.callFake( function() {} ); // Mock the enrollment and shopping cart interfaces - spyOn( EnrollmentInterface, 'enroll' ).andCallFake( function() {} ); - spyOn( ShoppingCartInterface, 'addCourseToCart' ).andCallFake( function() {} ); + spyOn( EnrollmentInterface, 'enroll' ).and.callFake( function() {} ); + spyOn( ShoppingCartInterface, 'addCourseToCart' ).and.callFake( function() {} ); spyOn( EmailOptInInterface, 'setPreference' ) - .andCallFake( function() { return {'always': function(r) { r(); }}; } ); + .and.callFake( function() { return {'always': function(r) { r(); }}; } ); view.render(); }; @@ -45,7 +45,7 @@ * should be prefixed with '?' */ var setFakeQueryParams = function( params ) { - spyOn( $, 'url' ).andCallFake(function( requestedParam ) { + spyOn( $, 'url' ).and.callFake(function( requestedParam ) { if ( params.hasOwnProperty(requestedParam) ) { return params[requestedParam]; } diff --git a/lms/static/js/spec/student_account/hinted_login_spec.js b/lms/static/js/spec/student_account/hinted_login_spec.js index 2a751b32d2..f21f1a8129 100644 --- a/lms/static/js/spec/student_account/hinted_login_spec.js +++ b/lms/static/js/spec/student_account/hinted_login_spec.js @@ -51,7 +51,7 @@ }); // Mock the redirect call - spyOn( view, 'redirect' ).andCallFake( function() {} ); + spyOn( view, 'redirect' ).and.callFake( function() {} ); view.render(); }; diff --git a/lms/static/js/spec/student_account/login_spec.js b/lms/static/js/spec/student_account/login_spec.js index a94ada61a0..9bd5d9ba33 100644 --- a/lms/static/js/spec/student_account/login_spec.js +++ b/lms/static/js/spec/student_account/login_spec.js @@ -127,7 +127,7 @@ // spying on `view.validate` twice if ( !_.isUndefined(validationSuccess) ) { // Force validation to return as expected - spyOn(view, 'validate').andReturn({ + spyOn(view, 'validate').and.returnValue({ isValid: validationSuccess, message: 'Submission was validated.' }); @@ -173,7 +173,7 @@ // Simulate that the user is attempting to enroll in a course // by setting the course_id query string param. - spyOn($, 'url').andCallFake(function( param ) { + spyOn($, 'url').and.callFake(function( param ) { if (param === '?course_id') { return encodeURIComponent( COURSE_ID ); } diff --git a/lms/static/js/spec/student_account/password_reset_spec.js b/lms/static/js/spec/student_account/password_reset_spec.js index b3ebbc4e69..35aa6fb228 100644 --- a/lms/static/js/spec/student_account/password_reset_spec.js +++ b/lms/static/js/spec/student_account/password_reset_spec.js @@ -58,7 +58,7 @@ // spying on `view.validate` twice if ( !_.isUndefined(validationSuccess) ) { // Force validation to return as expected - spyOn(view, 'validate').andReturn({ + spyOn(view, 'validate').and.returnValue({ isValid: validationSuccess, message: 'Submission was validated.' }); diff --git a/lms/static/js/spec/student_account/register_spec.js b/lms/static/js/spec/student_account/register_spec.js index f827e13e9d..5ba2e68bfa 100644 --- a/lms/static/js/spec/student_account/register_spec.js +++ b/lms/static/js/spec/student_account/register_spec.js @@ -220,7 +220,7 @@ // spying on `view.validate` twice if ( !_.isUndefined(validationSuccess) ) { // Force validation to return as expected - spyOn(view, 'validate').andReturn({ + spyOn(view, 'validate').and.returnValue({ isValid: validationSuccess, message: 'Submission was validated.' }); @@ -265,7 +265,7 @@ // Simulate that the user is attempting to enroll in a course // by setting the course_id query string param. - spyOn($, 'url').andCallFake(function( param ) { + spyOn($, 'url').and.callFake(function( param ) { if (param === '?course_id') { return encodeURIComponent( COURSE_ID ); } diff --git a/lms/static/js/spec/student_account/shoppingcart_spec.js b/lms/static/js/spec/student_account/shoppingcart_spec.js index 9048951dd2..8102781352 100644 --- a/lms/static/js/spec/student_account/shoppingcart_spec.js +++ b/lms/static/js/spec/student_account/shoppingcart_spec.js @@ -10,7 +10,7 @@ define(['common/js/spec_helpers/ajax_helpers', 'js/student_account/shoppingcart' beforeEach(function() { // Mock the redirect call - spyOn(ShoppingCartInterface, 'redirect').andCallFake(function() {}); + spyOn(ShoppingCartInterface, 'redirect').and.callFake(function() {}); }); it('adds a course to the cart', function() { diff --git a/lms/static/js/spec/student_profile/badge_view_spec.js b/lms/static/js/spec/student_profile/badge_view_spec.js index 41159423d8..d40258fcd7 100644 --- a/lms/static/js/spec/student_profile/badge_view_spec.js +++ b/lms/static/js/spec/student_profile/badge_view_spec.js @@ -52,7 +52,7 @@ define(['backbone', 'jquery', 'underscore', expect(view.createModal).toHaveBeenCalled(); }); - it("click on share button calls shows the dialog", function () { + it("click on share button calls shows the dialog", function (done) { view = createView(true); expect(view.context.ownProfile).toBeTruthy(); var shareButton = view.$el.find('button.share-button'); @@ -63,9 +63,9 @@ define(['backbone', 'jquery', 'underscore', shareButton.click(); // Note: this element should have appeared in the dom during: shareButton.click(); modalElement = $('.badges-modal'); - waitsFor(function () { + jasmine.waitUntil(function () { return modalElement.is(":visible"); - }, '', 1000); + }).always(done); }); var testBadgeNameIsDisplayed = function (ownProfile) { diff --git a/lms/static/js/spec/student_profile/section_two_tab_spec.js b/lms/static/js/spec/student_profile/section_two_tab_spec.js index b553a0735f..a0236b885a 100644 --- a/lms/static/js/spec/student_profile/section_two_tab_spec.js +++ b/lms/static/js/spec/student_profile/section_two_tab_spec.js @@ -50,7 +50,7 @@ define(['backbone', 'jquery', 'underscore', it("profile field parts are actually rendered for public profile", function () { var view = createSectionTwoView(false, true); _.each(view.options.viewList, function (fieldView) { - spyOn(fieldView, "render").andCallThrough(); + spyOn(fieldView, "render").and.callThrough(); }); view.render(); _.each(view.options.viewList, function (fieldView) { diff --git a/lms/static/js/spec/verify_student/image_input_spec.js b/lms/static/js/spec/verify_student/image_input_spec.js index 233159a859..81af419611 100644 --- a/lms/static/js/spec/verify_student/image_input_spec.js +++ b/lms/static/js/spec/verify_student/image_input_spec.js @@ -22,51 +22,41 @@ define([ }).render(); }; - var uploadImage = function( view, fileType, callback ) { - var imageCapturedEvent = false, - errorEvent = false; + var uploadImage = function( view, fileType ) { + var deferred = $.Deferred(); // Since image upload is an asynchronous process, // we need to wait for the upload to complete // before checking the outcome. - runs(function() { - var fakeFile, - fakeEvent = { target: { files: [] } }; + var fakeFile, + fakeEvent = { target: { files: [] } }; - // If no file type is specified, don't add any files. - // This simulates what happens when the user clicks - // "cancel" after clicking the input. - if ( fileType !== null) { - fakeFile = new Blob( - [ IMAGE_DATA ], - { type: 'image/' + fileType } - ); - fakeEvent.target.files = [ fakeFile ]; - } + // If no file type is specified, don't add any files. + // This simulates what happens when the user clicks + // "cancel" after clicking the input. + if ( fileType !== null) { + fakeFile = new Blob( + [ IMAGE_DATA ], + { type: 'image/' + fileType } + ); + fakeEvent.target.files = [ fakeFile ]; + } - // Wait for either a successful upload or an error - view.on( 'imageCaptured', function() { - imageCapturedEvent = true; - }); - view.on( 'error', function() { - errorEvent = true; - }); - - // Trigger the file input change - // It's impossible to trigger this directly due - // to browser security restrictions, so we call - // the handler instead. - view.handleInputChange( fakeEvent ); + // Wait for either a successful upload or an error + view.on( 'imageCaptured', function() { + deferred.resolve(); + }); + view.on( 'error', function() { + deferred.resolve(); }); - // Check that the image upload has completed, - // either successfully or with an error. - waitsFor(function() { - return ( imageCapturedEvent || errorEvent ); - }); + // Trigger the file input change + // It's impossible to trigger this directly due + // to browser security restrictions, so we call + // the handler instead. + view.handleInputChange( fakeEvent ); - // Execute the callback to check expectations. - runs( callback ); + return deferred.promise(); }; var expectPreview = function( view, fileType ) { @@ -112,45 +102,45 @@ define([ expectSubmitEnabled( false ); }); - it( 'uploads a png image', function() { + it( 'uploads a png image', function(done) { var view = createView(); - uploadImage( view, 'png', function() { + uploadImage( view, 'png').then(function() { expectPreview( view, 'png' ); expectSubmitEnabled( true ); expectImageData( view, 'png' ); - }); + }).always(done); }); - it( 'uploads a jpeg image', function() { + it( 'uploads a jpeg image', function(done) { var view = createView(); - uploadImage( view, 'jpeg', function() { + uploadImage( view, 'jpeg').then(function() { expectPreview( view, 'jpeg' ); expectSubmitEnabled( true ); expectImageData( view, 'jpeg' ); - } ); + }).always(done); }); - it( 'hides the preview when the user cancels the upload', function() { + it( 'hides the preview when the user cancels the upload', function(done) { var view = createView(); - uploadImage( view, null, function() { + uploadImage( view, null).then(function() { expectPreview( view, null ); expectSubmitEnabled( false ); expectImageData( view, null ); - } ); + }).always(done); }); - it( 'shows an error if the file type is not supported', function() { + it( 'shows an error if the file type is not supported', function(done) { var view = createView(); - uploadImage( view, 'txt', function() { + uploadImage( view, 'txt').then(function() { expectPreview( view, null ); expectError( view ); expectSubmitEnabled( false ); expectImageData( view, null ); - } ); + }).always(done); }); }); }); diff --git a/lms/static/js/spec/verify_student/make_payment_step_view_ab_testing_spec.js b/lms/static/js/spec/verify_student/make_payment_step_view_ab_testing_spec.js index 27fa12573f..dbb5cf6e0e 100644 --- a/lms/static/js/spec/verify_student/make_payment_step_view_ab_testing_spec.js +++ b/lms/static/js/spec/verify_student/make_payment_step_view_ab_testing_spec.js @@ -37,7 +37,7 @@ define([ }).render(); // Stub the payment form submission - spyOn( view, 'submitForm' ).andCallFake( function() {} ); + spyOn( view, 'submitForm' ).and.callFake( function() {} ); return view; }; @@ -97,7 +97,7 @@ define([ var form; expect(view.submitForm).toHaveBeenCalled(); - form = view.submitForm.mostRecentCall.args[0]; + form = view.submitForm.calls.mostRecent().args[0]; expect(form.serialize()).toEqual($.param(params)); expect(form.attr('method')).toEqual('POST'); diff --git a/lms/static/js/spec/verify_student/make_payment_step_view_spec.js b/lms/static/js/spec/verify_student/make_payment_step_view_spec.js index cda80071fe..31389ed5f3 100644 --- a/lms/static/js/spec/verify_student/make_payment_step_view_spec.js +++ b/lms/static/js/spec/verify_student/make_payment_step_view_spec.js @@ -34,7 +34,7 @@ define([ }).render(); // Stub the payment form submission - spyOn( view, 'submitForm' ).andCallFake( function() {} ); + spyOn( view, 'submitForm' ).and.callFake( function() {} ); return view; }; @@ -91,7 +91,7 @@ define([ var form; expect(view.submitForm).toHaveBeenCalled(); - form = view.submitForm.mostRecentCall.args[0]; + form = view.submitForm.calls.mostRecent().args[0]; expect(form.serialize()).toEqual($.param(params)); expect(form.attr('method')).toEqual("POST"); diff --git a/lms/static/js/spec/verify_student/pay_and_verify_view_spec.js b/lms/static/js/spec/verify_student/pay_and_verify_view_spec.js index 8fb53b910f..53f4b1fd8b 100644 --- a/lms/static/js/spec/verify_student/pay_and_verify_view_spec.js +++ b/lms/static/js/spec/verify_student/pay_and_verify_view_spec.js @@ -68,6 +68,7 @@ define(['jquery', 'common/js/spec_helpers/template_helpers', 'js/verify_student/ beforeEach(function() { window.analytics = jasmine.createSpyObj('analytics', ['track', 'page', 'trackLink']); + navigator.getUserMedia = jasmine.createSpy(); setFixtures(''); $.each( TEMPLATES, function( index, templateName ) { diff --git a/lms/static/js/spec/verify_student/reverify_view_spec.js b/lms/static/js/spec/verify_student/reverify_view_spec.js index b22236fb2b..e932ea116f 100644 --- a/lms/static/js/spec/verify_student/reverify_view_spec.js +++ b/lms/static/js/spec/verify_student/reverify_view_spec.js @@ -1,8 +1,9 @@ /** * Tests for the reverification view. **/ -define(['jquery', 'common/js/spec_helpers/template_helpers', 'js/verify_student/views/reverify_view'], - function( $, TemplateHelpers, ReverifyView ) { +define(['jquery', 'common/js/spec_helpers/template_helpers', 'js/verify_student/views/review_photos_step_view', + 'js/verify_student/views/reverify_view'], + function( $, TemplateHelpers, ReviewPhotosStepView, ReverifyView ) { 'use strict'; describe( 'edx.verify_student.ReverifyView', function() { @@ -45,6 +46,7 @@ define(['jquery', 'common/js/spec_helpers/template_helpers', 'js/verify_student/ beforeEach(function() { window.analytics = jasmine.createSpyObj('analytics', ['track', 'page', 'trackLink']); + navigator.getUserMedia = jasmine.createSpy(); setFixtures(''); $.each( TEMPLATES, function( index, templateName ) { diff --git a/lms/static/js/spec/verify_student/review_photos_step_view_spec.js b/lms/static/js/spec/verify_student/review_photos_step_view_spec.js index 59f07447f1..6ae60b7c01 100644 --- a/lms/static/js/spec/verify_student/review_photos_step_view_spec.js +++ b/lms/static/js/spec/verify_student/review_photos_step_view_spec.js @@ -42,7 +42,7 @@ define([ // Simulate the server response if ( succeeds ) { - AjaxHelpers.respondWithJson( requests ); + AjaxHelpers.respondWithJson( requests, {} ); } else { AjaxHelpers.respondWithTextError( requests, 400, SERVER_ERROR_MSG ); } diff --git a/lms/static/js/spec/verify_student/webcam_photo_view_spec.js b/lms/static/js/spec/verify_student/webcam_photo_view_spec.js index 8d734dfda4..1ef1322095 100644 --- a/lms/static/js/spec/verify_student/webcam_photo_view_spec.js +++ b/lms/static/js/spec/verify_student/webcam_photo_view_spec.js @@ -94,7 +94,7 @@ define([ var view = createView( new StubBackend( "html5" ) ); // Spy on the backend - spyOn( view.backend, 'snapshot' ).andCallThrough(); + spyOn( view.backend, 'snapshot' ).and.callThrough(); // Initially, only the snapshot button is shown expectButtonShown({ @@ -125,7 +125,7 @@ define([ var view = createView( new StubBackend( "html5" ) ); // Spy on the backend - spyOn( view.backend, 'reset' ).andCallThrough(); + spyOn( view.backend, 'reset' ).and.callThrough(); // Take the snapshot, then reset takeSnapshot(); diff --git a/lms/static/js/spec/views/fields_helpers.js b/lms/static/js/spec/views/fields_helpers.js index 6248656d33..fc089d579f 100644 --- a/lms/static/js/spec/views/fields_helpers.js +++ b/lms/static/js/spec/views/fields_helpers.js @@ -118,7 +118,7 @@ define(['backbone', 'jquery', 'underscore', 'common/js/spec_helpers/ajax_helpers expectMessageContains(view, view.helpMessage); view.showSuccessMessage(); expectMessageContains(view, view.indicators.success); - jasmine.Clock.tick(7000); + jasmine.clock().tick(7000); // Message gets reset expectMessageContains(view, view.helpMessage); @@ -126,7 +126,7 @@ define(['backbone', 'jquery', 'underscore', 'common/js/spec_helpers/ajax_helpers expectMessageContains(view, view.indicators.success); // But if we change the message, it should not get reset. view.showHelpMessage("Do not reset this!"); - jasmine.Clock.tick(7000); + jasmine.clock().tick(7000); expectMessageContains(view, "Do not reset this!"); }; diff --git a/lms/static/js/spec/views/fields_spec.js b/lms/static/js/spec/views/fields_spec.js index 3dd02806b8..0fd4810b21 100644 --- a/lms/static/js/spec/views/fields_spec.js +++ b/lms/static/js/spec/views/fields_spec.js @@ -25,7 +25,11 @@ define(['backbone', 'jquery', 'underscore', 'common/js/spec_helpers/ajax_helpers beforeEach(function () { timerCallback = jasmine.createSpy('timerCallback'); - jasmine.Clock.useMock(); + jasmine.clock().install(); + }); + + afterEach(function() { + jasmine.clock().uninstall(); }); it("updates messages correctly for all fields", function() { diff --git a/lms/static/js/student_account/account.js b/lms/static/js/student_account/account.js index f8ad63d5e3..e05339663d 100644 --- a/lms/static/js/student_account/account.js +++ b/lms/static/js/student_account/account.js @@ -178,11 +178,15 @@ var edx = edx || {}; this.$passwordResetStatus .removeClass('error') .text(""); - }, + } }); - return new edx.student.account.AccountView({ - el: $('#account-container') - }).render(); + try { + new edx.student.account.AccountView({ + el: $('#account-container') + }).render(); + } catch (e) { + // TODO: handle exception + } })(jQuery, _, Backbone, gettext); diff --git a/lms/static/js_test.yml b/lms/static/js_test.yml index 63b1aec2c2..e38db0e302 100644 --- a/lms/static/js_test.yml +++ b/lms/static/js_test.yml @@ -31,7 +31,6 @@ lib_paths: - xmodule_js/common_static/js/test/i18n.js - xmodule_js/common_static/coffee/src/ajax_prefix.js - xmodule_js/common_static/js/src/logger.js - - xmodule_js/common_static/js/vendor/jasmine-jquery.js - xmodule_js/common_static/js/vendor/jasmine-imagediff.js - xmodule_js/common_static/js/vendor/requirejs/require.js - js/RequireJS-namespace-undefine.js diff --git a/lms/static/js_test_coffee.yml b/lms/static/js_test_coffee.yml index 34013670ca..82e1f58195 100644 --- a/lms/static/js_test_coffee.yml +++ b/lms/static/js_test_coffee.yml @@ -31,19 +31,21 @@ lib_paths: - xmodule_js/common_static/js/test/i18n.js - xmodule_js/common_static/coffee/src/ajax_prefix.js - xmodule_js/common_static/js/src/logger.js - - xmodule_js/common_static/js/vendor/jasmine-jquery.js + - xmodule_js/common_static/js/vendor/underscore-min.js - xmodule_js/common_static/js/vendor/jasmine-imagediff.js - xmodule_js/common_static/js/vendor/requirejs/require.js - js/RequireJS-namespace-undefine.js - - xmodule_js/common_static/js/vendor/jquery.min.js - xmodule_js/common_static/js/vendor/jquery-ui.min.js - xmodule_js/common_static/js/vendor/jquery.cookie.js - xmodule_js/common_static/js/vendor/flot/jquery.flot.js + - xmodule_js/common_static/js/vendor/moment.min.js + - xmodule_js/common_static/js/vendor/moment-with-locales.min.js - xmodule_js/common_static/js/vendor/CodeMirror/codemirror.js - xmodule_js/common_static/js/vendor/URI.min.js - xmodule_js/common_static/coffee/src/jquery.immediateDescendents.js - xmodule_js/common_static/js/xblock - xmodule_js/common_static/coffee/src/xblock + - moment_requirejs.js - xmodule_js/src/capa/ - xmodule_js/src/video/ - xmodule_js/src/xmodule.js @@ -75,7 +77,7 @@ fixture_paths: # When loading many files, this can be slow, so # exclude any files you don't need. #exclude_from_page: -# - path/to/lib/exclude/* +# - coffee/spec/helper.js # Regular expression used to guarantee that a *.js file # is included in the test runner page. diff --git a/lms/static/karma_lms.conf.js b/lms/static/karma_lms.conf.js new file mode 100644 index 0000000000..a0523e67e0 --- /dev/null +++ b/lms/static/karma_lms.conf.js @@ -0,0 +1,154 @@ +// LMS JavaScript tests, using RequireJS. +// +// To run all the tests and print results to the console: +// +// karma start lms/static/karma_lms.conf.js +// +// +// To run the tests for debugging: Debugging can be done in any browser but +// Chrome's developer console debugging experience is best. +// +// karma start lms/static/karma_lms.conf.js --browsers=BROWSER --single-run=false +// +// +// To run the tests with coverage and junit reports: +// +// karma start lms/static/karma_lms.conf.js --browsers=BROWSER +// --coverage --junitreportpath=