Changing search_reindex call to be more inline with DRF convention
This commit is contained in:
committed by
Martyn James
parent
b280e44fe1
commit
b597df2e39
@@ -1,7 +1,7 @@
|
||||
define(["jquery", "js/common_helpers/ajax_helpers", "js/views/utils/view_utils", "js/views/pages/course_outline",
|
||||
define(["jquery", "sinon", "js/common_helpers/ajax_helpers", "js/views/utils/view_utils", "js/views/pages/course_outline",
|
||||
"js/models/xblock_outline_info", "js/utils/date_utils", "js/spec_helpers/edit_helpers",
|
||||
"js/common_helpers/template_helpers"],
|
||||
function($, AjaxHelpers, ViewUtils, CourseOutlinePage, XBlockOutlineInfo, DateUtils, EditHelpers, TemplateHelpers) {
|
||||
function($, Sinon, AjaxHelpers, ViewUtils, CourseOutlinePage, XBlockOutlineInfo, DateUtils, EditHelpers, TemplateHelpers) {
|
||||
|
||||
describe("CourseOutlinePage", function() {
|
||||
var createCourseOutlinePage, displayNameInput, model, outlinePage, requests,
|
||||
@@ -90,16 +90,16 @@ define(["jquery", "js/common_helpers/ajax_helpers", "js/views/utils/view_utils",
|
||||
|
||||
createMockIndexJSON = function(option) {
|
||||
if(option){
|
||||
return {
|
||||
status: 200,
|
||||
responseText: ''
|
||||
};
|
||||
return JSON.stringify({
|
||||
"developer_message" : "Course has been successfully reindexed.",
|
||||
"user_message": "Course has been successfully reindexed."
|
||||
});
|
||||
}
|
||||
else {
|
||||
return {
|
||||
status: 500,
|
||||
responseText: JSON.stringify('Could not index item: course/slashes:mock+item')
|
||||
};
|
||||
return JSON.stringify({
|
||||
"developer_message" : "Could not reindex course.",
|
||||
"user_message": "Could not reindex course."
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -324,12 +324,12 @@ define(["jquery", "js/common_helpers/ajax_helpers", "js/views/utils/view_utils",
|
||||
verifyItemsExpanded('section', true);
|
||||
});
|
||||
|
||||
it('can start reindex of a course - respond success', function() {
|
||||
it('can start reindex of a course', function() {
|
||||
createCourseOutlinePage(this, mockSingleSectionCourseJSON);
|
||||
var reindexSpy = spyOn(outlinePage, 'startReIndex').andCallThrough();
|
||||
var successSpy = spyOn(outlinePage, 'onIndexSuccess').andCallThrough();
|
||||
var reindexButton = outlinePage.$('.button.button-reindex');
|
||||
var test_url = '/course_search_index/5';
|
||||
var test_url = '/course/5/search_reindex';
|
||||
reindexButton.attr('href', test_url)
|
||||
reindexButton.trigger('click');
|
||||
AjaxHelpers.expectJsonRequest(requests, 'GET', test_url);
|
||||
@@ -338,16 +338,18 @@ define(["jquery", "js/common_helpers/ajax_helpers", "js/views/utils/view_utils",
|
||||
expect(successSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('can start reindex of a course - respond fail', function() {
|
||||
it('shows an error message when reindexing fails', function() {
|
||||
createCourseOutlinePage(this, mockSingleSectionCourseJSON);
|
||||
var reindexSpy = spyOn(outlinePage, 'startReIndex').andCallThrough();
|
||||
var errorSpy = spyOn(outlinePage, 'onIndexError').andCallThrough();
|
||||
var reindexButton = outlinePage.$('.button.button-reindex');
|
||||
var test_url = '/course_search_index/5';
|
||||
var test_url = '/course/5/search_reindex';
|
||||
reindexButton.attr('href', test_url)
|
||||
reindexButton.trigger('click');
|
||||
AjaxHelpers.expectJsonRequest(requests, 'GET', test_url);
|
||||
AjaxHelpers.respondWithJson(requests, createMockIndexJSON(false));
|
||||
AjaxHelpers.respondWithError(requests, 500, createMockIndexJSON(false));
|
||||
expect(reindexSpy).toHaveBeenCalled();
|
||||
expect(errorSpy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
* This page is used to show the user an outline of the course.
|
||||
*/
|
||||
define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views/utils/xblock_utils",
|
||||
"js/views/course_outline", "js/views/utils/view_utils", "js/views/feedback_alert"],
|
||||
function ($, _, gettext, BasePage, XBlockViewUtils, CourseOutlineView, ViewUtils, AlertView) {
|
||||
"js/views/course_outline", "js/views/utils/view_utils", "js/views/feedback_alert",
|
||||
"js/views/feedback_notification"],
|
||||
function ($, _, gettext, BasePage, XBlockViewUtils, CourseOutlineView, ViewUtils, AlertView, NoteView) {
|
||||
var expandedLocators, CourseOutlinePage;
|
||||
|
||||
CourseOutlinePage = BasePage.extend({
|
||||
@@ -111,21 +112,33 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views
|
||||
var target = $(event.currentTarget);
|
||||
target.css('cursor', 'wait');
|
||||
this.startReIndex(target.attr('href'))
|
||||
.done(function() {self.onIndexSuccess();})
|
||||
.done(function(data) {self.onIndexSuccess(data);})
|
||||
.fail(function(data) {self.onIndexError(data);})
|
||||
.always(function() {target.css('cursor', 'pointer');});
|
||||
},
|
||||
|
||||
startReIndex: function(reindex_url) {
|
||||
return $.ajax({
|
||||
url: reindex_url,
|
||||
method: 'GET'
|
||||
url: reindex_url,
|
||||
method: 'GET',
|
||||
global: false,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json"
|
||||
});
|
||||
},
|
||||
|
||||
onIndexSuccess: function() {
|
||||
onIndexSuccess: function(data) {
|
||||
var msg = new AlertView.Announcement({
|
||||
title: gettext('Course Index'),
|
||||
message: gettext('Course has been successfully reindexed.')
|
||||
message: data.user_message
|
||||
});
|
||||
msg.show();
|
||||
},
|
||||
|
||||
onIndexError: function(data) {
|
||||
var msg = new NoteView.Error({
|
||||
title: gettext('There were errors reindexing course.'),
|
||||
message: data.user_message
|
||||
});
|
||||
msg.show();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user