From 545af7e854a72f4403ce545091ce4dcc215c9dc7 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Thu, 5 Sep 2013 14:16:44 +0300 Subject: [PATCH 1/3] Jasmine test to verify that only one check for YT is made. We test for the number of ajax calls made when there are 3 videos on the page. --- .../js/fixtures/video_yt_multiple.html | 171 ++++++++++++++++++ .../xmodule/js/spec/video/general_spec.js | 33 ++++ 2 files changed, 204 insertions(+) create mode 100644 common/lib/xmodule/xmodule/js/fixtures/video_yt_multiple.html diff --git a/common/lib/xmodule/xmodule/js/fixtures/video_yt_multiple.html b/common/lib/xmodule/xmodule/js/fixtures/video_yt_multiple.html new file mode 100644 index 0000000000..26325b45e1 --- /dev/null +++ b/common/lib/xmodule/xmodule/js/fixtures/video_yt_multiple.html @@ -0,0 +1,171 @@ +
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
diff --git a/common/lib/xmodule/xmodule/js/spec/video/general_spec.js b/common/lib/xmodule/xmodule/js/spec/video/general_spec.js index 9f3ab5916a..c1548fd2be 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/general_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/general_spec.js @@ -186,6 +186,39 @@ }); }); + describe('multiple YT on page', function () { + beforeEach(function () { + $.ajax.calls.length = 0; + $.ajaxWithPrefix.calls = 0; + + loadFixtures('video_yt_multiple.html'); + + state1 = new Video('#example1'); + + spyOn($, 'ajaxWithPrefix'); + + state2 = new Video('#example2'); + state3 = new Video('#example3'); + }); + + it('check for YT availability is performed only once', function () { + var numAjaxCalls = 0; + + // Total ajax calls made. + numAjaxCalls = $.ajax.calls.length; + + // Subtract ajax calls to get captions. + numAjaxCalls -= $.ajaxWithPrefix.calls.length; + + // Subtract ajax calls to get metadata for each video. + numAjaxCalls -= 3; + + // This should leave just one call. It was made to check + // for YT availability. + expect(numAjaxCalls).toBe(1); + }); + }); + describe('setSpeed', function () { describe('YT', function () { beforeEach(function () { From 8ffd16366f936e734498d370b96063cf99e947c0 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Thu, 5 Sep 2013 14:29:26 +0300 Subject: [PATCH 2/3] Fix for test. Must clear the state youtubeXhr variable before counting number of ajax calls. --- .../xmodule/xmodule/js/spec/video/general_spec.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/spec/video/general_spec.js b/common/lib/xmodule/xmodule/js/spec/video/general_spec.js index c1548fd2be..3daa8cb4bd 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/general_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/general_spec.js @@ -188,15 +188,20 @@ describe('multiple YT on page', function () { beforeEach(function () { - $.ajax.calls.length = 0; - $.ajaxWithPrefix.calls = 0; - loadFixtures('video_yt_multiple.html'); - state1 = new Video('#example1'); - spyOn($, 'ajaxWithPrefix'); + $.ajax.calls.length = 0; + $.ajaxWithPrefix.calls.length = 0; + + // Because several other tests have run, the variable + // that stores the value of the first ajax request must be + // cleared so that we test a pristine state of the video + // module. + Video.clearYoutubeXhr(); + + state1 = new Video('#example1'); state2 = new Video('#example2'); state3 = new Video('#example3'); }); From b2c605a18728387d7bb8365b000d9bef597cb20f Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Fri, 6 Sep 2013 14:02:28 +0300 Subject: [PATCH 3/3] Addressing comments by Jean Michel for PR 867. Forgot to include local variables in var statement. --- common/lib/xmodule/xmodule/js/spec/video/general_spec.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/lib/xmodule/xmodule/js/spec/video/general_spec.js b/common/lib/xmodule/xmodule/js/spec/video/general_spec.js index 3daa8cb4bd..3444f5389f 100644 --- a/common/lib/xmodule/xmodule/js/spec/video/general_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/video/general_spec.js @@ -187,6 +187,8 @@ }); describe('multiple YT on page', function () { + var state1, state2, state3; + beforeEach(function () { loadFixtures('video_yt_multiple.html');