Merge pull request #12275 from edx/ormsbee/video_state_opt_2

Remove unnecessary VideoModule save_states.
This commit is contained in:
David Ormsbee
2016-05-02 10:54:40 -04:00
4 changed files with 45 additions and 5 deletions

View File

@@ -9,12 +9,14 @@
.createSpy('onTouchBasedDevice')
.and.returnValue(null);
state = jasmine.initializePlayer();
state = jasmine.initializePlayer({
recordedYoutubeIsAvailable: true
});
spyOn(state.storage, 'setItem');
});
afterEach(function () {
$('source').remove();
window.onTouchBasedDevice = oldOTBD;
state.storage.clear();
@@ -199,7 +201,20 @@
expect(state.storage.setItem).toHaveBeenCalledWith('language', 'ua');
});
it('can save information about youtube availability', function () {
it('can save youtube availability', function () {
$.ajax.calls.reset();
// Test the cases where we shouldn't send anything at all -- client
// side code determines that YouTube availability is the same as
// what's already been recorded on the server side.
state.config.recordedYoutubeIsAvailable = true;
state.el.trigger('youtube_availability', [true]);
state.config.recordedYoutubeIsAvailable = false;
state.el.trigger('youtube_availability', [false]);
expect($.ajax).not.toHaveBeenCalled();
// Test that we can go from unavailable -> available
state.config.recordedYoutubeIsAvailable = false;
state.el.trigger('youtube_availability', [true]);
expect($.ajax).toHaveBeenCalledWith({
url: state.config.saveStateUrl,
@@ -208,6 +223,17 @@
dataType: 'json',
data: {youtube_is_available: true}
});
// Test that we can go from available -> unavailable
state.config.recordedYoutubeIsAvailable = true;
state.el.trigger('youtube_availability', [false]);
expect($.ajax).toHaveBeenCalledWith({
url: state.config.saveStateUrl,
type: 'POST',
async: true,
dataType: 'json',
data: {youtube_is_available: false}
});
});
it('can destroy itself', function () {

View File

@@ -84,7 +84,12 @@ define('video/09_save_state_plugin.js', [], function() {
},
onYoutubeAvailability: function (event, youtubeIsAvailable) {
this.saveState(true, {youtube_is_available: youtubeIsAvailable});
// Compare what the client-side code has determined Youtube
// availability to be (true/false) vs. what the LMS recorded for
// this user. The LMS will assume YouTube is available by default.
if (youtubeIsAvailable !== this.state.config.recordedYoutubeIsAvailable) {
this.saveState(true, {youtube_is_available: youtubeIsAvailable});
}
},
saveState: function (async, data) {

View File

@@ -332,7 +332,12 @@ class VideoModule(VideoFields, VideoTranscriptsMixin, VideoStudentViewHandlers,
## There is no option in the "Advanced Editor" to set this option. However,
## this option will have an effect if changed to "True". The code on
## front-end exists.
'autohideHtml5': False
'autohideHtml5': False,
# This is the server's guess at whether youtube is available for
# this user, based on what was recorded the last time we saw the
# user, and defaulting to True.
'recordedYoutubeIsAvailable': self.youtube_is_available,
}
bumperize(self)