soft delete video from video uploads page
TNL-5899
This commit is contained in:
@@ -1,29 +1,81 @@
|
||||
define(
|
||||
['jquery', 'underscore', 'backbone', 'js/views/previous_video_upload_list', 'common/js/spec_helpers/template_helpers'],
|
||||
function($, _, Backbone, PreviousVideoUploadListView, TemplateHelpers) {
|
||||
['jquery', 'underscore', 'backbone', 'js/views/previous_video_upload_list',
|
||||
'common/js/spec_helpers/template_helpers', 'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers'],
|
||||
function($, _, Backbone, PreviousVideoUploadListView, TemplateHelpers, AjaxHelpers) {
|
||||
'use strict';
|
||||
describe('PreviousVideoUploadListView', function() {
|
||||
var videoHandlerUrl = '/videos/course-v1:org.0+course_0+Run_0',
|
||||
render = function(numModels) {
|
||||
var modelData = {
|
||||
client_video_id: 'foo.mp4',
|
||||
duration: 42,
|
||||
created: '2014-11-25T23:13:05',
|
||||
edx_video_id: 'dummy_id',
|
||||
status: 'uploading'
|
||||
};
|
||||
var collection = new Backbone.Collection(
|
||||
_.map(
|
||||
_.range(numModels),
|
||||
function(num, index) {
|
||||
return new Backbone.Model(
|
||||
_.extend({}, modelData, {edx_video_id: 'dummy_id_' + index})
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
var view = new PreviousVideoUploadListView({
|
||||
collection: collection,
|
||||
videoHandlerUrl: videoHandlerUrl
|
||||
});
|
||||
return view.render().$el;
|
||||
},
|
||||
verifyVideosInfo;
|
||||
|
||||
beforeEach(function() {
|
||||
TemplateHelpers.installTemplate('previous-video-upload', true);
|
||||
setFixtures('<div id="page-prompt"></div>');
|
||||
TemplateHelpers.installTemplate('previous-video-upload');
|
||||
TemplateHelpers.installTemplate('previous-video-upload-list');
|
||||
});
|
||||
|
||||
var render = function(numModels) {
|
||||
var modelData = {
|
||||
client_video_id: 'foo.mp4',
|
||||
duration: 42,
|
||||
created: '2014-11-25T23:13:05',
|
||||
edx_video_id: 'dummy_id',
|
||||
status: 'uploading'
|
||||
};
|
||||
var collection = new Backbone.Collection(
|
||||
_.map(
|
||||
_.range(numModels),
|
||||
function() { return new Backbone.Model(modelData); }
|
||||
)
|
||||
);
|
||||
var view = new PreviousVideoUploadListView({collection: collection});
|
||||
return view.render().$el;
|
||||
verifyVideosInfo = function(test, confirmRemove) {
|
||||
var firstVideo,
|
||||
numVideos = 5,
|
||||
$el = render(numVideos),
|
||||
firstVideoId = 'dummy_id_0',
|
||||
requests = AjaxHelpers.requests(test),
|
||||
firstVideoSelector = '.js-table-body tr:first-child';
|
||||
|
||||
// total number of videos should be 5 before remove
|
||||
expect($el.find('.js-table-body tr').length).toEqual(numVideos);
|
||||
|
||||
// get first video element
|
||||
firstVideo = $el.find(firstVideoSelector);
|
||||
|
||||
// verify first video id before removal
|
||||
expect(firstVideo.find('.video-id-col').text()).toEqual(firstVideoId);
|
||||
|
||||
// remove first video in the table
|
||||
firstVideo.find('.remove-video-button.action-button').click();
|
||||
|
||||
if (confirmRemove) {
|
||||
// click on Remove button on confirmation popup
|
||||
$('.action-primary').click();
|
||||
AjaxHelpers.expectJsonRequest(requests, 'DELETE', videoHandlerUrl + '/dummy_id_0');
|
||||
AjaxHelpers.respondWithNoContent(requests);
|
||||
numVideos -= 1;
|
||||
firstVideoId = 'dummy_id_1';
|
||||
} else {
|
||||
// click on Cancel button on confirmation popup
|
||||
$('.action-secondary').click();
|
||||
expect(requests.length).toEqual(0);
|
||||
}
|
||||
|
||||
// verify total number of videos after Remove/Cancel
|
||||
expect($el.find('.js-table-body tr').length).toEqual(numVideos);
|
||||
|
||||
// verify first video id after Remove/Cancel
|
||||
firstVideo = $el.find(firstVideoSelector);
|
||||
expect(firstVideo.find('.video-id-col').text()).toEqual(firstVideoId);
|
||||
};
|
||||
|
||||
it('should render an empty collection', function() {
|
||||
@@ -37,6 +89,16 @@ define(
|
||||
expect($el.find('.js-table-body').length).toEqual(1);
|
||||
expect($el.find('.js-table-body tr').length).toEqual(5);
|
||||
});
|
||||
|
||||
it('removes video upon click on Remove button', function() {
|
||||
// Remove a video from list and verify that correct video is removed
|
||||
verifyVideosInfo(this, true);
|
||||
});
|
||||
|
||||
it('does nothing upon click on Cancel button', function() {
|
||||
// Verify that nothing changes when we click on Cancel button on confirmation popup
|
||||
verifyVideosInfo(this, false);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
define(
|
||||
['jquery', 'backbone', 'js/views/previous_video_upload', 'common/js/spec_helpers/template_helpers'],
|
||||
function($, Backbone, PreviousVideoUploadView, TemplateHelpers) {
|
||||
['jquery', 'underscore', 'backbone', 'js/views/previous_video_upload', 'common/js/spec_helpers/template_helpers',
|
||||
'common/js/spec_helpers/view_helpers'],
|
||||
function($, _, Backbone, PreviousVideoUploadView, TemplateHelpers, ViewHelpers) {
|
||||
'use strict';
|
||||
describe('PreviousVideoUploadView', function() {
|
||||
beforeEach(function() {
|
||||
TemplateHelpers.installTemplate('previous-video-upload', true);
|
||||
});
|
||||
|
||||
var render = function(modelData) {
|
||||
var defaultData = {
|
||||
client_video_id: 'foo.mp4',
|
||||
duration: 42,
|
||||
created: '2014-11-25T23:13:05',
|
||||
edx_video_id: 'dummy_id',
|
||||
status: 'uploading'
|
||||
};
|
||||
var view = new PreviousVideoUploadView(
|
||||
{model: new Backbone.Model($.extend({}, defaultData, modelData))}
|
||||
);
|
||||
client_video_id: 'foo.mp4',
|
||||
duration: 42,
|
||||
created: '2014-11-25T23:13:05',
|
||||
edx_video_id: 'dummy_id',
|
||||
status: 'uploading'
|
||||
},
|
||||
view = new PreviousVideoUploadView({
|
||||
model: new Backbone.Model($.extend({}, defaultData, modelData)),
|
||||
videoHandlerUrl: '/videos/course-v1:org.0+course_0+Run_0'
|
||||
});
|
||||
return view.render().$el;
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
setFixtures('<div id="page-prompt"></div><div id="page-notification"></div>');
|
||||
TemplateHelpers.installTemplate('previous-video-upload', false);
|
||||
});
|
||||
|
||||
it('should render video name correctly', function() {
|
||||
var testName = 'test name';
|
||||
var $el = render({client_video_id: testName});
|
||||
@@ -70,6 +73,35 @@ define(
|
||||
var $el = render({status: testStatus});
|
||||
expect($el.find('.status-col').text()).toEqual(testStatus);
|
||||
});
|
||||
|
||||
it('should render remove button correctly', function() {
|
||||
var $el = render(),
|
||||
removeButton = $el.find('.actions-list .action-remove a.remove-video-button');
|
||||
|
||||
expect(removeButton.data('tooltip')).toEqual('Remove this video');
|
||||
expect(removeButton.find('.sr').text()).toEqual('Remove foo.mp4 video');
|
||||
});
|
||||
|
||||
it('shows a confirmation popup when the remove button is clicked', function() {
|
||||
var $el = render();
|
||||
$el.find('a.remove-video-button').click();
|
||||
expect($('.prompt.warning .title').text()).toEqual('Are you sure you want to remove this video from the list?'); // eslint-disable-line max-len
|
||||
expect(
|
||||
$('.prompt.warning .message').text()
|
||||
).toEqual(
|
||||
'Removing a video from this list does not affect course content. Any content that uses a previously uploaded video ID continues to display in the course.' // eslint-disable-line max-len
|
||||
);
|
||||
expect($('.prompt.warning .action-primary').text()).toEqual('Remove');
|
||||
expect($('.prompt.warning .action-secondary').text()).toEqual('Cancel');
|
||||
});
|
||||
|
||||
it('shows a notification when the remove button is clicked', function() {
|
||||
var notificationSpy = ViewHelpers.createNotificationSpy(),
|
||||
$el = render();
|
||||
$el.find('a.remove-video-button').click();
|
||||
$('.action-primary').click();
|
||||
ViewHelpers.verifyNotificationShowing(notificationSpy, /Removing/);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user