Commit ad16f9f9 by cahrens

Optimize search usages.

parent eff80bae
...@@ -1212,8 +1212,6 @@ courseware_js = ( ...@@ -1212,8 +1212,6 @@ courseware_js = (
sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/modules/**/*.js')) sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/modules/**/*.js'))
) )
courseware_search_js = ['js/search/course/main.js']
# Before a student accesses courseware, we do not # Before a student accesses courseware, we do not
# need many of the JS dependencies. This includes # need many of the JS dependencies. This includes
...@@ -1252,7 +1250,6 @@ base_application_js = [ ...@@ -1252,7 +1250,6 @@ base_application_js = [
dashboard_js = ( dashboard_js = (
sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/dashboard/**/*.js')) sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/dashboard/**/*.js'))
) )
dashboard_search_js = ['js/search/dashboard/main.js']
discussion_js = sorted(rooted_glob(COMMON_ROOT / 'static', 'coffee/src/discussion/**/*.js')) discussion_js = sorted(rooted_glob(COMMON_ROOT / 'static', 'coffee/src/discussion/**/*.js'))
staff_grading_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/staff_grading/**/*.js')) staff_grading_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/staff_grading/**/*.js'))
open_ended_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/open_ended/**/*.js')) open_ended_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/open_ended/**/*.js'))
...@@ -1338,8 +1335,6 @@ incourse_reverify_js = [ ...@@ -1338,8 +1335,6 @@ incourse_reverify_js = [
ccx_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/ccx/**/*.js')) ccx_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/ccx/**/*.js'))
discovery_js = ['js/discovery/main.js']
certificates_web_view_js = [ certificates_web_view_js = [
'js/vendor/jquery.min.js', 'js/vendor/jquery.min.js',
'js/vendor/jquery.cookie.js', 'js/vendor/jquery.cookie.js',
...@@ -1504,10 +1499,6 @@ PIPELINE_JS = { ...@@ -1504,10 +1499,6 @@ PIPELINE_JS = {
'source_filenames': courseware_js, 'source_filenames': courseware_js,
'output_filename': 'js/lms-courseware.js', 'output_filename': 'js/lms-courseware.js',
}, },
'courseware_search': {
'source_filenames': courseware_search_js,
'output_filename': 'js/lms-courseware-search.js',
},
'base_vendor': { 'base_vendor': {
'source_filenames': base_vendor_js, 'source_filenames': base_vendor_js,
'output_filename': 'js/lms-base-vendor.js', 'output_filename': 'js/lms-base-vendor.js',
...@@ -1548,10 +1539,6 @@ PIPELINE_JS = { ...@@ -1548,10 +1539,6 @@ PIPELINE_JS = {
'source_filenames': dashboard_js, 'source_filenames': dashboard_js,
'output_filename': 'js/dashboard.js' 'output_filename': 'js/dashboard.js'
}, },
'dashboard_search': {
'source_filenames': dashboard_search_js,
'output_filename': 'js/dashboard-search.js',
},
'student_account': { 'student_account': {
'source_filenames': student_account_js, 'source_filenames': student_account_js,
'output_filename': 'js/student_account.js' 'output_filename': 'js/student_account.js'
...@@ -1576,10 +1563,6 @@ PIPELINE_JS = { ...@@ -1576,10 +1563,6 @@ PIPELINE_JS = {
'source_filenames': ['js/footer-edx.js'], 'source_filenames': ['js/footer-edx.js'],
'output_filename': 'js/footer-edx.js' 'output_filename': 'js/footer-edx.js'
}, },
'discovery': {
'source_filenames': discovery_js,
'output_filename': 'js/discovery.js'
},
'certificates_wv': { 'certificates_wv': {
'source_filenames': certificates_web_view_js, 'source_filenames': certificates_web_view_js,
'output_filename': 'js/certificates/web_view.js' 'output_filename': 'js/certificates/web_view.js'
......
;(function (define) { ;(function (define) {
define(['backbone', 'course_discovery_meanings'], function(Backbone, meanings) {
'use strict'; 'use strict';
return function (Collection, Form, ResultListView, FilterBarView, FacetsBarView, searchQuery) { define(['backbone', 'js/discovery/collection', 'js/discovery/form', 'js/discovery/result_list_view',
//facet types configuration - set default display names 'js/discovery/filter_bar_view', 'js/discovery/search_facets_view'],
var facetsTypes = meanings; function(Backbone, Collection, Form, ResultListView, FilterBarView, FacetsBarView) {
var collection = new Collection([]); return function (meanings, searchQuery) {
var results = new ResultListView({ collection: collection }); //facet types configuration - set default display names
var dispatcher = _.clone(Backbone.Events); var facetsTypes = meanings;
var form = new Form();
var filters = new FilterBarView();
var facetsBarView = new FacetsBarView(facetsTypes);
dispatcher.listenTo(form, 'search', function (query) { var collection = new Collection([]);
form.showLoadingIndicator(); var results = new ResultListView({ collection: collection });
filters.changeQueryFilter(query); var dispatcher = _.clone(Backbone.Events);
}); var form = new Form();
var filters = new FilterBarView();
var facetsBarView = new FacetsBarView(facetsTypes);
dispatcher.listenTo(filters, 'search', function (searchTerm, facets) { dispatcher.listenTo(form, 'search', function (query) {
collection.performSearch(searchTerm, facets); form.showLoadingIndicator();
form.showLoadingIndicator(); filters.changeQueryFilter(query);
}); });
dispatcher.listenTo(filters, 'clear', function () { dispatcher.listenTo(filters, 'search', function (searchTerm, facets) {
form.clearSearch(); collection.performSearch(searchTerm, facets);
collection.performSearch(); form.showLoadingIndicator();
filters.hideClearAllButton(); });
});
dispatcher.listenTo(results, 'next', function () { dispatcher.listenTo(filters, 'clear', function () {
collection.loadNextPage(); form.clearSearch();
form.showLoadingIndicator(); collection.performSearch();
}); filters.hideClearAllButton();
});
dispatcher.listenTo(collection, 'search', function () { dispatcher.listenTo(results, 'next', function () {
if (collection.length > 0) { collection.loadNextPage();
form.showFoundMessage(collection.totalCount); form.showLoadingIndicator();
results.render(); });
}
else {
form.showNotFoundMessage(collection.searchTerm);
}
facetsBarView.renderFacets(collection.facets);
form.hideLoadingIndicator();
});
dispatcher.listenTo(collection, 'next', function () { dispatcher.listenTo(collection, 'search', function () {
results.renderNext(); if (collection.length > 0) {
form.hideLoadingIndicator(); form.showFoundMessage(collection.totalCount);
}); results.render();
}
else {
form.showNotFoundMessage(collection.searchTerm);
}
facetsBarView.renderFacets(collection.facets);
form.hideLoadingIndicator();
});
dispatcher.listenTo(collection, 'error', function () { dispatcher.listenTo(collection, 'next', function () {
form.showErrorMessage(); results.renderNext();
form.hideLoadingIndicator(); form.hideLoadingIndicator();
}); });
dispatcher.listenTo(facetsBarView, 'addFilter', function (data) { dispatcher.listenTo(collection, 'error', function () {
filters.addFilter(data); form.showErrorMessage();
}); form.hideLoadingIndicator();
});
// kick off search on page refresh dispatcher.listenTo(facetsBarView, 'addFilter', function (data) {
form.doSearch(searchQuery); filters.addFilter(data);
});
}; // kick off search on page refresh
form.doSearch(searchQuery);
}); };
});
})(define || RequireJS.define); })(define || RequireJS.define);
RequireJS.require([
'jquery',
'backbone',
'js/discovery/app',
'js/discovery/collection',
'js/discovery/form',
'js/discovery/result_list_view',
'js/discovery/filter_bar_view',
'js/discovery/search_facets_view'
], function ($, Backbone, App, Collection, DiscoveryForm, ResultListView, FilterBarView, FacetsBarView) {
'use strict';
var app = new App(
Collection,
DiscoveryForm,
ResultListView,
FilterBarView,
FacetsBarView,
getParameterByName('search_query')
);
});
;(function (define) { ;(function (define) {
define(['backbone'], function(Backbone) {
'use strict'; 'use strict';
return function (courseId, SearchRouter, SearchForm, SearchCollection, SearchListView) { define(['backbone', 'js/search/base/routers/search_router', 'js/search/course/views/search_form',
'js/search/base/collections/search_collection', 'js/search/course/views/search_results_view'],
function(Backbone, SearchRouter, CourseSearchForm, SearchCollection, SearchResultsView) {
var router = new SearchRouter(); return function (courseId) {
var form = new SearchForm();
var collection = new SearchCollection([], { courseId: courseId });
var results = new SearchListView({ collection: collection });
var dispatcher = _.clone(Backbone.Events);
dispatcher.listenTo(router, 'search', function (query) { var router = new SearchRouter();
form.doSearch(query); var form = new CourseSearchForm();
}); var collection = new SearchCollection([], { courseId: courseId });
var results = new SearchResultsView({ collection: collection });
var dispatcher = _.clone(Backbone.Events);
dispatcher.listenTo(form, 'search', function (query) { dispatcher.listenTo(router, 'search', function (query) {
results.showLoadingMessage(); form.doSearch(query);
collection.performSearch(query); });
router.navigate('search/' + query, { replace: true });
});
dispatcher.listenTo(form, 'clear', function () { dispatcher.listenTo(form, 'search', function (query) {
collection.cancelSearch(); results.showLoadingMessage();
results.clear(); collection.performSearch(query);
router.navigate(''); router.navigate('search/' + query, { replace: true });
}); });
dispatcher.listenTo(results, 'next', function () { dispatcher.listenTo(form, 'clear', function () {
collection.loadNextPage(); collection.cancelSearch();
}); results.clear();
router.navigate('');
});
dispatcher.listenTo(collection, 'search', function () { dispatcher.listenTo(results, 'next', function () {
results.render(); collection.loadNextPage();
}); });
dispatcher.listenTo(collection, 'next', function () { dispatcher.listenTo(collection, 'search', function () {
results.renderNext(); results.render();
}); });
dispatcher.listenTo(collection, 'error', function () { dispatcher.listenTo(collection, 'next', function () {
results.showErrorMessage(); results.renderNext();
}); });
}; dispatcher.listenTo(collection, 'error', function () {
results.showErrorMessage();
});
}); };
});
})(define || RequireJS.define); })(define || RequireJS.define);
RequireJS.require([
'jquery',
'backbone',
'js/search/course/search_app',
'js/search/base/routers/search_router',
'js/search/course/views/search_form',
'js/search/base/collections/search_collection',
'js/search/course/views/search_results_view'
], function ($, Backbone, SearchApp, SearchRouter, CourseSearchForm, SearchCollection, CourseSearchResultsView) {
'use strict';
var courseId = $('#courseware-search-results').data('courseId');
var app = new SearchApp(
courseId,
SearchRouter,
CourseSearchForm,
SearchCollection,
CourseSearchResultsView
);
Backbone.history.start();
});
;(function (define) { ;(function (define) {
define(['backbone'], function(Backbone) {
'use strict'; 'use strict';
return function (SearchRouter, SearchForm, SearchCollection, SearchListView) { define(['backbone', 'js/search/base/routers/search_router', 'js/search/dashboard/views/search_form',
'js/search/base/collections/search_collection', 'js/search/dashboard/views/search_results_view'],
function(Backbone, SearchRouter, SearchForm, SearchCollection, SearchListView) {
var router = new SearchRouter(); return function () {
var form = new SearchForm();
var collection = new SearchCollection([]);
var results = new SearchListView({ collection: collection });
var dispatcher = _.clone(Backbone.Events);
dispatcher.listenTo(router, 'search', function (query) { var router = new SearchRouter();
form.doSearch(query); var form = new SearchForm();
}); var collection = new SearchCollection([]);
var results = new SearchListView({ collection: collection });
var dispatcher = _.clone(Backbone.Events);
dispatcher.listenTo(form, 'search', function (query) { dispatcher.listenTo(router, 'search', function (query) {
results.showLoadingMessage(); form.doSearch(query);
collection.performSearch(query); });
router.navigate('search/' + query, { replace: true });
});
dispatcher.listenTo(form, 'clear', function () { dispatcher.listenTo(form, 'search', function (query) {
collection.cancelSearch(); results.showLoadingMessage();
results.clear(); collection.performSearch(query);
router.navigate(''); router.navigate('search/' + query, { replace: true });
}); });
dispatcher.listenTo(results, 'next', function () { dispatcher.listenTo(form, 'clear', function () {
collection.loadNextPage(); collection.cancelSearch();
}); results.clear();
router.navigate('');
});
dispatcher.listenTo(results, 'reset', function () { dispatcher.listenTo(results, 'next', function () {
form.resetSearchForm(); collection.loadNextPage();
}); });
dispatcher.listenTo(collection, 'search', function () { dispatcher.listenTo(results, 'reset', function () {
results.render(); form.resetSearchForm();
}); });
dispatcher.listenTo(collection, 'next', function () { dispatcher.listenTo(collection, 'search', function () {
results.renderNext(); results.render();
}); });
dispatcher.listenTo(collection, 'error', function () { dispatcher.listenTo(collection, 'next', function () {
results.showErrorMessage(); results.renderNext();
}); });
}; dispatcher.listenTo(collection, 'error', function () {
results.showErrorMessage();
});
}); };
});
})(define || RequireJS.define); })(define || RequireJS.define);
RequireJS.require([
'backbone',
'js/search/dashboard/search_app',
'js/search/base/routers/search_router',
'js/search/dashboard/views/search_form',
'js/search/base/collections/search_collection',
'js/search/dashboard/views/search_results_view'
], function (Backbone, SearchApp, SearchRouter, DashSearchForm, SearchCollection, DashSearchResultsView) {
'use strict';
var app = new SearchApp(
SearchRouter,
DashSearchForm,
SearchCollection,
DashSearchResultsView
);
Backbone.history.start();
});
define({
org: {
name: 'Organization',
terms: {
edX1: "edX_1"
}
},
modes: {
name: 'Course Type',
terms: {
honor: 'Honor',
verified: 'Verified'
}
},
language: {
en: 'English',
hr: 'Croatian'
}
});
...@@ -4,7 +4,7 @@ define([ ...@@ -4,7 +4,7 @@ define([
'logger', 'logger',
'common/js/spec_helpers/ajax_helpers', 'common/js/spec_helpers/ajax_helpers',
'common/js/spec_helpers/template_helpers', 'common/js/spec_helpers/template_helpers',
'js/discovery/app', 'js/discovery/discovery_factory',
'js/discovery/collection', 'js/discovery/collection',
'js/discovery/form', 'js/discovery/form',
'js/discovery/result', 'js/discovery/result',
...@@ -14,16 +14,14 @@ define([ ...@@ -14,16 +14,14 @@ define([
'js/discovery/filters', 'js/discovery/filters',
'js/discovery/filter_bar_view', 'js/discovery/filter_bar_view',
'js/discovery/filter_view', 'js/discovery/filter_view',
'js/discovery/search_facets_view', 'js/discovery/search_facets_view'
'js/discovery/facet_view',
'js/discovery/facets_view'
], function( ], function(
$, $,
Backbone, Backbone,
Logger, Logger,
AjaxHelpers, AjaxHelpers,
TemplateHelpers, TemplateHelpers,
App, DiscoveryFactory,
Collection, Collection,
DiscoveryForm, DiscoveryForm,
ResultItem, ResultItem,
...@@ -33,9 +31,7 @@ define([ ...@@ -33,9 +31,7 @@ define([
FiltersCollection, FiltersCollection,
FiltersBarView, FiltersBarView,
FilterView, FilterView,
SearchFacetView, SearchFacetView
FacetView,
FacetsView
) { ) {
'use strict'; 'use strict';
...@@ -113,126 +109,116 @@ define([ ...@@ -113,126 +109,116 @@ define([
var SEARCH_FILTER = {"type": "search_string", "query": "search3"}; var SEARCH_FILTER = {"type": "search_string", "query": "search3"};
describe('Collection', function () { describe('Course Discovery', function () {
beforeEach(function () { describe('Collection', function () {
this.collection = new Collection();
this.onSearch = jasmine.createSpy('onSearch'); beforeEach(function () {
this.collection.on('search', this.onSearch); this.collection = new Collection();
this.onNext = jasmine.createSpy('onNext'); this.onSearch = jasmine.createSpy('onSearch');
this.collection.on('next', this.onNext); this.collection.on('search', this.onSearch);
this.onError = jasmine.createSpy('onError'); this.onNext = jasmine.createSpy('onNext');
this.collection.on('error', this.onError); this.collection.on('next', this.onNext);
});
it('sends a request and parses the json result', function () {
var requests = AjaxHelpers.requests(this);
this.collection.performSearch('search string');
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE);
expect(this.onSearch).toHaveBeenCalled();
expect(this.collection.totalCount).toEqual(365);
expect(this.collection.latestModels()[0].attributes).toEqual(JSON_RESPONSE.results[0].data);
expect(this.collection.page).toEqual(0);
});
it('handles errors', function () { this.onError = jasmine.createSpy('onError');
var requests = AjaxHelpers.requests(this); this.collection.on('error', this.onError);
this.collection.performSearch('search string');
AjaxHelpers.respondWithError(requests);
expect(this.onSearch).not.toHaveBeenCalled();
expect(this.onError).toHaveBeenCalled();
this.collection.loadNextPage();
AjaxHelpers.respondWithError(requests);
expect(this.onSearch).not.toHaveBeenCalled();
expect(this.onError).toHaveBeenCalled();
});
it('loads next page', function () {
var requests = AjaxHelpers.requests(this);
var response = { total: 35, results: [] };
this.collection.loadNextPage();
AjaxHelpers.respondWithJson(requests, response);
expect(this.onNext).toHaveBeenCalled();
expect(this.onError).not.toHaveBeenCalled();
});
it('sends correct paging parameters', function () {
var requests = AjaxHelpers.requests(this);
var response = { total: 52, results: [] };
this.collection.performSearch('search string');
AjaxHelpers.respondWithJson(requests, response);
this.collection.loadNextPage();
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).toEqual({
search_string : 'search string',
page_size : this.collection.pageSize,
page_index : 2
}); });
});
it('has next page', function () { it('sends a request and parses the json result', function () {
var requests = AjaxHelpers.requests(this); var requests = AjaxHelpers.requests(this);
var response = { total: 35, access_denied_count: 5, results: [] }; this.collection.performSearch('search string');
this.collection.performSearch('search string'); AjaxHelpers.respondWithJson(requests, JSON_RESPONSE);
AjaxHelpers.respondWithJson(requests, response); expect(this.onSearch).toHaveBeenCalled();
expect(this.collection.hasNextPage()).toEqual(true); expect(this.collection.totalCount).toEqual(365);
this.collection.loadNextPage(); expect(this.collection.latestModels()[0].attributes).toEqual(JSON_RESPONSE.results[0].data);
AjaxHelpers.respondWithJson(requests, response); expect(this.collection.page).toEqual(0);
expect(this.collection.hasNextPage()).toEqual(false); });
});
it('resets state when performing new search', function () { it('handles errors', function () {
this.collection.add(new ResultItem()); var requests = AjaxHelpers.requests(this);
expect(this.collection.length).toEqual(1); this.collection.performSearch('search string');
this.collection.performSearch('search string'); AjaxHelpers.respondWithError(requests);
expect(this.collection.length).toEqual(0); expect(this.onSearch).not.toHaveBeenCalled();
expect(this.collection.page).toEqual(0); expect(this.onError).toHaveBeenCalled();
expect(this.collection.totalCount).toEqual(0); this.collection.loadNextPage();
expect(this.collection.latestModelsCount).toEqual(0); AjaxHelpers.respondWithError(requests);
}); expect(this.onSearch).not.toHaveBeenCalled();
expect(this.onError).toHaveBeenCalled();
});
}); it('loads next page', function () {
var requests = AjaxHelpers.requests(this);
var response = { total: 35, results: [] };
this.collection.loadNextPage();
AjaxHelpers.respondWithJson(requests, response);
expect(this.onNext).toHaveBeenCalled();
expect(this.onError).not.toHaveBeenCalled();
});
it('sends correct paging parameters', function () {
var requests = AjaxHelpers.requests(this);
var response = { total: 52, results: [] };
this.collection.performSearch('search string');
AjaxHelpers.respondWithJson(requests, response);
this.collection.loadNextPage();
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).toEqual({
search_string : 'search string',
page_size : this.collection.pageSize,
page_index : 2
});
});
describe('ResultItem', function () { it('has next page', function () {
var requests = AjaxHelpers.requests(this);
var response = { total: 35, access_denied_count: 5, results: [] };
this.collection.performSearch('search string');
AjaxHelpers.respondWithJson(requests, response);
expect(this.collection.hasNextPage()).toEqual(true);
this.collection.loadNextPage();
AjaxHelpers.respondWithJson(requests, response);
expect(this.collection.hasNextPage()).toEqual(false);
});
beforeEach(function () { it('resets state when performing new search', function () {
this.result = new ResultItem(); this.collection.add(new ResultItem());
}); expect(this.collection.length).toEqual(1);
this.collection.performSearch('search string');
expect(this.collection.length).toEqual(0);
expect(this.collection.page).toEqual(0);
expect(this.collection.totalCount).toEqual(0);
expect(this.collection.latestModelsCount).toEqual(0);
});
it('has properties', function () {
expect(this.result.get('modes')).toBeDefined();
expect(this.result.get('course')).toBeDefined();
expect(this.result.get('enrollment_start')).toBeDefined();
expect(this.result.get('number')).toBeDefined();
expect(this.result.get('content')).toEqual({
display_name: '',
number: '',
overview: ''
});
expect(this.result.get('start')).toBeDefined();
expect(this.result.get('image_url')).toBeDefined();
expect(this.result.get('org')).toBeDefined();
expect(this.result.get('id')).toBeDefined();
}); });
});
describe('ResultItem', function () {
describe('ResultItemView', function () { beforeEach(function () {
this.result = new ResultItem();
});
beforeEach(function () { it('has properties', function () {
TemplateHelpers.installTemplate('templates/discovery/result_item'); expect(this.result.get('modes')).toBeDefined();
this.item = new ResultItemView({ expect(this.result.get('course')).toBeDefined();
model: new ResultItem(JSON_RESPONSE.results[0].data) expect(this.result.get('enrollment_start')).toBeDefined();
expect(this.result.get('number')).toBeDefined();
expect(this.result.get('content')).toEqual({
display_name: '',
number: '',
overview: ''
});
expect(this.result.get('start')).toBeDefined();
expect(this.result.get('image_url')).toBeDefined();
expect(this.result.get('org')).toBeDefined();
expect(this.result.get('id')).toBeDefined();
}); });
});
it('renders correctly', function () { it('renders correctly', function () {
var data = this.item.model.attributes; var data = this.item.model.attributes;
...@@ -246,350 +232,383 @@ define([ ...@@ -246,350 +232,383 @@ define([
expect(this.item.$el.find('.course-date')).toContainHtml('Jan 01, 1970'); expect(this.item.$el.find('.course-date')).toContainHtml('Jan 01, 1970');
}); });
});
describe('ResultItemView', function () {
describe('DiscoveryForm', function () { beforeEach(function () {
TemplateHelpers.installTemplate('templates/discovery/result_item');
this.item = new ResultItemView({
model: new ResultItem(JSON_RESPONSE.results[0].data)
});
});
beforeEach(function () { it('renders correctly', function () {
loadFixtures('js/fixtures/discovery.html'); var data = this.item.model.attributes;
this.form = new DiscoveryForm(); this.item.render();
this.onSearch = jasmine.createSpy('onSearch'); expect(this.item.$el).toContainHtml(data.content.display_name);
this.form.on('search', this.onSearch); expect(this.item.$el).toContain('a[href="/courses/' + data.course + '/info"]');
}); expect(this.item.$el).toContain('img[src="' + data.image_url + '"]');
expect(this.item.$el.find('.course-name')).toContainHtml(data.org);
expect(this.item.$el.find('.course-name')).toContainHtml(data.content.number);
expect(this.item.$el.find('.course-name')).toContainHtml(data.content.display_name);
expect(this.item.$el.find('.course-date')).toContainHtml('Jan 01, 1970');
});
it('trims input string', function () {
var term = ' search string ';
$('.discovery-input').val(term);
$('form').trigger('submit');
expect(this.onSearch).toHaveBeenCalledWith($.trim(term));
}); });
it('handles calls to doSearch', function () {
var term = ' search string ';
$('.discovery-input').val(term);
this.form.doSearch(term);
expect(this.onSearch).toHaveBeenCalledWith($.trim(term));
expect($('.discovery-input').val()).toEqual(term);
expect($('#discovery-message')).toBeEmpty();
});
it('clears search', function () { describe('DiscoveryForm', function () {
$('.discovery-input').val('somethig');
this.form.clearSearch();
expect($('.discovery-input').val()).toEqual('');
});
it('shows/hides loading indicator', function () { beforeEach(function () {
this.form.showLoadingIndicator(); loadFixtures('js/fixtures/discovery.html');
expect($('#loading-indicator')).not.toHaveClass('hidden'); this.form = new DiscoveryForm();
this.form.hideLoadingIndicator(); this.onSearch = jasmine.createSpy('onSearch');
expect($('#loading-indicator')).toHaveClass('hidden'); this.form.on('search', this.onSearch);
}); });
it('shows messages', function () { it('trims input string', function () {
this.form.showNotFoundMessage(); var term = ' search string ';
expect($('#discovery-message')).not.toBeEmpty(); $('.discovery-input').val(term);
this.form.showErrorMessage(); $('form').trigger('submit');
expect($('#discovery-message')).not.toBeEmpty(); expect(this.onSearch).toHaveBeenCalledWith($.trim(term));
}); });
}); it('handles calls to doSearch', function () {
var term = ' search string ';
$('.discovery-input').val(term);
this.form.doSearch(term);
expect(this.onSearch).toHaveBeenCalledWith($.trim(term));
expect($('.discovery-input').val()).toEqual(term);
expect($('#discovery-message')).toBeEmpty();
});
describe('FilterBarView', function () { it('clears search', function () {
beforeEach(function () { $('.discovery-input').val('somethig');
loadFixtures('js/fixtures/discovery.html'); this.form.clearSearch();
TemplateHelpers.installTemplates( expect($('.discovery-input').val()).toEqual('');
['templates/discovery/filter_bar', });
'templates/discovery/filter']
);
this.filterBar = new FiltersBarView();
this.onClear = jasmine.createSpy('onClear');
this.filterBar.on('clear', this.onClear);
});
it('view searches for sent facet object', function () { it('shows/hides loading indicator', function () {
expect(this.filterBar.$el.length).toBe(1); this.form.showLoadingIndicator();
this.filterBar.addFilter(FACET_LIST[0]); expect($('#loading-indicator')).not.toHaveClass('hidden');
expect(this.filterBar.$el.find('#clear-all-filters')).toBeVisible(); this.form.hideLoadingIndicator();
}); expect($('#loading-indicator')).toHaveClass('hidden');
});
it('view searches for entered search string', function () { it('shows messages', function () {
spyOn(this.filterBar, 'addFilter').andCallThrough(); this.form.showNotFoundMessage();
expect(this.filterBar.$el.length).toBe(1); expect($('#discovery-message')).not.toBeEmpty();
this.filterBar.changeQueryFilter(SEARCH_FILTER.query); this.form.showErrorMessage();
expect(this.filterBar.$el.find('#clear-all-filters')).toBeVisible(); expect($('#discovery-message')).not.toBeEmpty();
expect(this.filterBar.addFilter).toHaveBeenCalledWith(SEARCH_FILTER); });
});
it('model cleans view on destruction correctly', function () {
this.filterBar.addFilter(SEARCH_FILTER);
var model = this.filterBar.collection.findWhere(SEARCH_FILTER);
expect(this.filterBar.$el.find('.active-filter').length).toBe(1);
model.cleanModelView();
expect(this.filterBar.$el.find('.active-filter').length).toBe(0);
}); });
it('view removes all filters and hides bar if clear all', function () { describe('FilterBarView', function () {
spyOn(this.filterBar, 'clearAll').andCallThrough(); beforeEach(function () {
this.filterBar.delegateEvents(); loadFixtures('js/fixtures/discovery.html');
this.filterBar.addFilter(SEARCH_FILTER); TemplateHelpers.installTemplates(
var clearAll = this.filterBar.$el.find('#clear-all-filters'); ['templates/discovery/filter_bar',
expect(clearAll).toBeVisible(); 'templates/discovery/filter']
clearAll.trigger('click'); );
expect(this.filterBar.clearAll).toHaveBeenCalled(); this.filterBar = new FiltersBarView();
expect(this.onClear).toHaveBeenCalled(); this.onClear = jasmine.createSpy('onClear');
}); this.filterBar.on('clear', this.onClear);
});
it('view hides bar if all filters removed', function () { it('view searches for sent facet object', function () {
spyOn(this.filterBar, 'clearFilter').andCallThrough(); expect(this.filterBar.$el.length).toBe(1);
this.filterBar.delegateEvents(); this.filterBar.addFilter(FACET_LIST[0]);
this.filterBar.addFilter(SEARCH_FILTER); expect(this.filterBar.$el.find('#clear-all-filters')).toBeVisible();
var clearAll = this.filterBar.$el.find('#clear-all-filters'); });
expect(clearAll).toBeVisible();
var filter = this.filterBar.$el.find('li .discovery-button');
filter.trigger('click');
expect(this.filterBar.clearFilter).toHaveBeenCalled();
expect(this.onClear).toHaveBeenCalled();
});
it('view changes query filter', function () { it('view searches for entered search string', function () {
this.filterBar.addFilter(SEARCH_FILTER); spyOn(this.filterBar, 'addFilter').andCallThrough();
var filter = $(this.filterBar.$el.find('li .discovery-button')[0]); expect(this.filterBar.$el.length).toBe(1);
expect(filter.text().trim()).toBe(SEARCH_FILTER.query); this.filterBar.changeQueryFilter(SEARCH_FILTER.query);
// Have to explicitly remove model because events not dispatched expect(this.filterBar.$el.find('#clear-all-filters')).toBeVisible();
var model = this.filterBar.collection.findWhere(SEARCH_FILTER); expect(this.filterBar.addFilter).toHaveBeenCalledWith(SEARCH_FILTER);
model.cleanModelView(); });
this.filterBar.changeQueryFilter(SEARCH_FILTER.query + '2');
filter = $(this.filterBar.$el.find('li .discovery-button')[0]);
expect(filter.text().trim()).toBe(SEARCH_FILTER.query + '2');
});
it('view returns correct search term', function () { it('model cleans view on destruction correctly', function () {
this.filterBar.addFilter(SEARCH_FILTER); this.filterBar.addFilter(SEARCH_FILTER);
expect(this.filterBar.getSearchTerm()).toBe(SEARCH_FILTER.query); var model = this.filterBar.collection.findWhere(SEARCH_FILTER);
}); expect(this.filterBar.$el.find('.active-filter').length).toBe(1);
model.cleanModelView();
expect(this.filterBar.$el.find('.active-filter').length).toBe(0);
});
}); it('view removes all filters and hides bar if clear all', function () {
spyOn(this.filterBar, 'clearAll').andCallThrough();
this.filterBar.delegateEvents();
this.filterBar.addFilter(SEARCH_FILTER);
var clearAll = this.filterBar.$el.find('#clear-all-filters');
expect(clearAll).toBeVisible();
clearAll.trigger('click');
expect(this.filterBar.clearAll).toHaveBeenCalled();
expect(this.onClear).toHaveBeenCalled();
});
describe('SearchFacetView', function () { it('view hides bar if all filters removed', function () {
beforeEach(function () { spyOn(this.filterBar, 'clearFilter').andCallThrough();
loadFixtures('js/fixtures/discovery.html'); this.filterBar.delegateEvents();
TemplateHelpers.installTemplates([ this.filterBar.addFilter(SEARCH_FILTER);
'templates/discovery/search_facet', var clearAll = this.filterBar.$el.find('#clear-all-filters');
'templates/discovery/search_facets_section', expect(clearAll).toBeVisible();
'templates/discovery/search_facets_list', var filter = this.filterBar.$el.find('li .discovery-button');
'templates/discovery/more_less_links' filter.trigger('click');
]); expect(this.filterBar.clearFilter).toHaveBeenCalled();
var facetsTypes = {org: 'Organization', modes: 'Course Type'}; expect(this.onClear).toHaveBeenCalled();
this.searchFacetView = new SearchFacetView(facetsTypes); });
this.searchFacetView.renderFacets(JSON_RESPONSE.facets);
this.onAddFilter = jasmine.createSpy('onAddFilter');
this.searchFacetView.on('addFilter', this.onAddFilter);
});
it('view expands more content on show more click', function () { it('view changes query filter', function () {
var $showMore = this.searchFacetView.$el.find('.show-more'); this.filterBar.addFilter(SEARCH_FILTER);
var $showLess = this.searchFacetView.$el.find('.show-less'); var filter = $(this.filterBar.$el.find('li .discovery-button')[0]);
var $ul = $showMore.parent('div').siblings('ul'); expect(filter.text().trim()).toBe(SEARCH_FILTER.query);
expect($showMore).not.toHaveClass('hidden'); // Have to explicitly remove model because events not dispatched
expect($showLess).toHaveClass('hidden'); var model = this.filterBar.collection.findWhere(SEARCH_FILTER);
expect($ul).toHaveClass('collapse'); model.cleanModelView();
$showMore.trigger('click'); this.filterBar.changeQueryFilter(SEARCH_FILTER.query + '2');
expect($showMore).toHaveClass('hidden'); filter = $(this.filterBar.$el.find('li .discovery-button')[0]);
expect($showLess).not.toHaveClass('hidden'); expect(filter.text().trim()).toBe(SEARCH_FILTER.query + '2');
expect($ul).not.toHaveClass('collapse'); });
});
it('view collapses content on show less click', function () { it('view returns correct search term', function () {
var $showMore = this.searchFacetView.$el.find('.show-more'); this.filterBar.addFilter(SEARCH_FILTER);
var $showLess = this.searchFacetView.$el.find('.show-less'); expect(this.filterBar.getSearchTerm()).toBe(SEARCH_FILTER.query);
var $ul = $showMore.parent('div').siblings('ul'); });
$showMore.trigger('click');
expect($showMore).toHaveClass('hidden');
expect($showLess).not.toHaveClass('hidden');
expect($ul).not.toHaveClass('collapse');
$showLess.trigger('click');
expect($showMore).not.toHaveClass('hidden');
expect($showLess).toHaveClass('hidden');
expect($ul).toHaveClass('collapse');
});
it('view triggers addFilter event if facet is clicked', function () {
this.searchFacetView.delegateEvents();
var $facetLink = this.searchFacetView.$el.find('li [data-value="edX1"]');
var $facet = $facetLink.parent('li');
$facet.trigger('click');
expect(this.onAddFilter).toHaveBeenCalledWith(
{
type: $facet.data('facet'),
query: $facetLink.data('value'),
name : $facetLink.data('text')
}
);
}); });
it('re-render facets on second click', function () { describe('SearchFacetView', function () {
// First search beforeEach(function () {
this.searchFacetView.delegateEvents(); loadFixtures('js/fixtures/discovery.html');
this.searchFacetView.renderFacets(JSON_RESPONSE.facets); TemplateHelpers.installTemplates([
expect(this.searchFacetView.facetViews.length).toBe(2); 'templates/discovery/search_facet',
// Setup spy 'templates/discovery/search_facets_section',
var customView = this.searchFacetView.facetViews[0]; 'templates/discovery/search_facets_list',
spyOn(customView, 'remove').andCallThrough(); 'templates/discovery/more_less_links'
// Second search ]);
this.searchFacetView.renderFacets(JSON_RESPONSE.facets); var facetsTypes = {org: 'Organization', modes: 'Course Type'};
expect(this.searchFacetView.facetViews.length).toBe(2); this.searchFacetView = new SearchFacetView(facetsTypes);
expect(customView.remove).toHaveBeenCalled(); this.searchFacetView.renderFacets(JSON_RESPONSE.facets);
}); this.onAddFilter = jasmine.createSpy('onAddFilter');
this.searchFacetView.on('addFilter', this.onAddFilter);
});
}); it('view expands more content on show more click', function () {
var $showMore = this.searchFacetView.$el.find('.show-more');
var $showLess = this.searchFacetView.$el.find('.show-less');
var $ul = $showMore.parent('div').siblings('ul');
expect($showMore).not.toHaveClass('hidden');
expect($showLess).toHaveClass('hidden');
expect($ul).toHaveClass('collapse');
$showMore.trigger('click');
expect($showMore).toHaveClass('hidden');
expect($showLess).not.toHaveClass('hidden');
expect($ul).not.toHaveClass('collapse');
});
describe('ResultListView', function () { it('view collapses content on show less click', function () {
var $showMore = this.searchFacetView.$el.find('.show-more');
var $showLess = this.searchFacetView.$el.find('.show-less');
var $ul = $showMore.parent('div').siblings('ul');
$showMore.trigger('click');
expect($showMore).toHaveClass('hidden');
expect($showLess).not.toHaveClass('hidden');
expect($ul).not.toHaveClass('collapse');
$showLess.trigger('click');
expect($showMore).not.toHaveClass('hidden');
expect($showLess).toHaveClass('hidden');
expect($ul).toHaveClass('collapse');
});
beforeEach(function () { it('view triggers addFilter event if facet is clicked', function () {
jasmine.Clock.useMock(); this.searchFacetView.delegateEvents();
loadFixtures('js/fixtures/discovery.html'); var $facetLink = this.searchFacetView.$el.find('li [data-value="edX1"]');
TemplateHelpers.installTemplate('templates/discovery/result_item'); var $facet = $facetLink.parent('li');
var collection = new Collection([JSON_RESPONSE.results[0].data]); $facet.trigger('click');
collection.latestModelsCount = 1; expect(this.onAddFilter).toHaveBeenCalledWith(
this.view = new ResultListView({ collection: collection }); {
}); type: $facet.data('facet'),
query: $facetLink.data('value'),
name : $facetLink.data('text')
}
);
});
it('renders search results', function () { it('re-render facets on second click', function () {
this.view.render(); // First search
expect($('.courses-listing article').length).toEqual(1); this.searchFacetView.delegateEvents();
expect($('.courses-listing .course-title')).toContainHtml('edX Demonstration Course'); this.searchFacetView.renderFacets(JSON_RESPONSE.facets);
this.view.renderNext(); expect(this.searchFacetView.facetViews.length).toBe(2);
expect($('.courses-listing article').length).toEqual(2); // Setup spy
}); var customView = this.searchFacetView.facetViews[0];
spyOn(customView, 'remove').andCallThrough();
// Second search
this.searchFacetView.renderFacets(JSON_RESPONSE.facets);
expect(this.searchFacetView.facetViews.length).toBe(2);
expect(customView.remove).toHaveBeenCalled();
});
it('scrolling triggers an event for next page', function () {
this.onNext = jasmine.createSpy('onNext');
this.view.on('next', this.onNext);
spyOn(this.view.collection, 'hasNextPage').andCallFake(function () {
return true;
});
this.view.render();
window.scroll(0, $(document).height());
$(window).trigger('scroll');
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);
}); });
}); describe('ResultListView', function () {
beforeEach(function () {
jasmine.Clock.useMock();
loadFixtures('js/fixtures/discovery.html');
TemplateHelpers.installTemplate('templates/discovery/result_item');
var collection = new Collection([JSON_RESPONSE.results[0].data]);
collection.latestModelsCount = 1;
this.view = new ResultListView({ collection: collection });
});
describe('Discovery App', function () { it('renders search results', function () {
this.view.render();
beforeEach(function () { expect($('.courses-listing article').length).toEqual(1);
loadFixtures('js/fixtures/discovery.html'); expect($('.courses-listing .course-title')).toContainHtml('edX Demonstration Course');
TemplateHelpers.installTemplates([ this.view.renderNext();
'templates/discovery/result_item', expect($('.courses-listing article').length).toEqual(2);
'templates/discovery/filter', });
'templates/discovery/filter_bar',
'templates/discovery/search_facet',
'templates/discovery/search_facets_section',
'templates/discovery/search_facets_list',
'templates/discovery/more_less_links'
]);
this.app = new App(
Collection,
DiscoveryForm,
ResultListView,
FiltersBarView,
SearchFacetView
);
});
it('performs search', function () { it('scrolling triggers an event for next page', function () {
var requests = AjaxHelpers.requests(this); this.onNext = jasmine.createSpy('onNext');
$('.discovery-input').val('test'); this.view.on('next', this.onNext);
$('.discovery-submit').trigger('click'); spyOn(this.view.collection, 'hasNextPage').andCallFake(function () {
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE); return true;
expect($('.courses-listing article').length).toEqual(1); });
expect($('.courses-listing .course-title')).toContainHtml('edX Demonstration Course'); this.view.render();
expect($('.active-filter').length).toBe(1); window.scroll(0, $(document).height());
}); $(window).trigger('scroll');
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);
});
it('loads more', function () {
var requests = AjaxHelpers.requests(this);
jasmine.Clock.useMock();
$('.discovery-input').val('test');
$('.discovery-submit').trigger('click');
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE);
expect($('.courses-listing article').length).toEqual(1);
expect($('.courses-listing .course-title')).toContainHtml('edX Demonstration Course');
window.scroll(0, $(document).height());
$(window).trigger('scroll');
jasmine.Clock.tick(500);
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE);
expect($('.courses-listing article').length).toEqual(2);
}); });
it('displays not found message', function () {
var requests = AjaxHelpers.requests(this);
$('.discovery-input').val('asdfasdf');
$('.discovery-submit').trigger('click');
AjaxHelpers.respondWithJson(requests, {});
expect($('#discovery-message')).not.toBeEmpty();
expect($('.courses-listing')).toBeEmpty();
});
it('displays error message', function () { describe('Discovery App', function () {
var requests = AjaxHelpers.requests(this);
$('.discovery-input').val('asdfasdf'); beforeEach(function () {
$('.discovery-submit').trigger('click'); loadFixtures('js/fixtures/discovery.html');
AjaxHelpers.respondWithError(requests, 404); TemplateHelpers.installTemplates([
expect($('#discovery-message')).not.toBeEmpty(); 'templates/discovery/result_item',
expect($('.courses-listing')).toBeEmpty(); 'templates/discovery/filter',
}); 'templates/discovery/filter_bar',
'templates/discovery/search_facet',
'templates/discovery/search_facets_section',
'templates/discovery/search_facets_list',
'templates/discovery/more_less_links'
]);
DiscoveryFactory(
{
org: {
name: 'Organization',
terms: {
edX1: "edX_1"
}
},
modes: {
name: 'Course Type',
terms: {
honor: 'Honor',
verified: 'Verified'
}
},
language: {
en: 'English',
hr: 'Croatian'
}
}
);
});
it('check filters and bar removed on clear all', function () { it('performs search', function () {
var requests = AjaxHelpers.requests(this); var requests = AjaxHelpers.requests(this);
$('.discovery-input').val('test'); $('.discovery-input').val('test');
$('.discovery-submit').trigger('click'); $('.discovery-submit').trigger('click');
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE); AjaxHelpers.respondWithJson(requests, JSON_RESPONSE);
expect($('.active-filter').length).toBe(1); expect($('.courses-listing article').length).toEqual(1);
expect($('#filter-bar')).not.toHaveClass('hidden'); expect($('.courses-listing .course-title')).toContainHtml('edX Demonstration Course');
$('#clear-all-filters').trigger('click'); expect($('.active-filter').length).toBe(1);
expect($('.active-filter').length).toBe(0); });
expect($('#filter-bar')).toHaveClass('hidden');
});
it('check filters and bar removed on last filter cleared', function () { it('loads more', function () {
var requests = AjaxHelpers.requests(this); var requests = AjaxHelpers.requests(this);
$('.discovery-input').val('test'); jasmine.Clock.useMock();
$('.discovery-submit').trigger('click'); $('.discovery-input').val('test');
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE); $('.discovery-submit').trigger('click');
expect($('.active-filter').length).toBe(1); AjaxHelpers.respondWithJson(requests, JSON_RESPONSE);
var $filter = $('.active-filter'); expect($('.courses-listing article').length).toEqual(1);
$filter.find('.discovery-button').trigger('click'); expect($('.courses-listing .course-title')).toContainHtml('edX Demonstration Course');
expect($('.active-filter').length).toBe(0); window.scroll(0, $(document).height());
}); $(window).trigger('scroll');
jasmine.Clock.tick(500);
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE);
expect($('.courses-listing article').length).toEqual(2);
});
it('filter results by named facet', function () { it('displays not found message', function () {
var requests = AjaxHelpers.requests(this); var requests = AjaxHelpers.requests(this);
$('.discovery-input').val('test'); $('.discovery-input').val('asdfasdf');
$('.discovery-submit').trigger('click'); $('.discovery-submit').trigger('click');
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE); AjaxHelpers.respondWithJson(requests, {});
expect($('.active-filter').length).toBe(1); expect($('#discovery-message')).not.toBeEmpty();
var $facetLink = $('.search-facets li [data-value="edX1"]'); expect($('.courses-listing')).toBeEmpty();
var $facet = $facetLink.parent('li'); });
$facet.trigger('click');
expect($('.active-filter').length).toBe(2);
expect($('.active-filter [data-value="edX1"]').length).toBe(1);
expect($('.active-filter [data-value="edX1"]').text().trim()).toBe("edX_1");
});
}); it('displays error message', function () {
var requests = AjaxHelpers.requests(this);
$('.discovery-input').val('asdfasdf');
$('.discovery-submit').trigger('click');
AjaxHelpers.respondWithError(requests, 404);
expect($('#discovery-message')).not.toBeEmpty();
expect($('.courses-listing')).toBeEmpty();
});
it('check filters and bar removed on clear all', function () {
var requests = AjaxHelpers.requests(this);
$('.discovery-input').val('test');
$('.discovery-submit').trigger('click');
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE);
expect($('.active-filter').length).toBe(1);
expect($('#filter-bar')).not.toHaveClass('hidden');
$('#clear-all-filters').trigger('click');
expect($('.active-filter').length).toBe(0);
expect($('#filter-bar')).toHaveClass('hidden');
});
it('check filters and bar removed on last filter cleared', function () {
var requests = AjaxHelpers.requests(this);
$('.discovery-input').val('test');
$('.discovery-submit').trigger('click');
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE);
expect($('.active-filter').length).toBe(1);
var $filter = $('.active-filter');
$filter.find('.discovery-button').trigger('click');
expect($('.active-filter').length).toBe(0);
});
it('filter results by named facet', function () {
var requests = AjaxHelpers.requests(this);
$('.discovery-input').val('test');
$('.discovery-submit').trigger('click');
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE);
expect($('.active-filter').length).toBe(1);
var $facetLink = $('.search-facets li [data-value="edX1"]');
var $facet = $facetLink.parent('li');
$facet.trigger('click');
expect($('.active-filter').length).toBe(2);
expect($('.active-filter [data-value="edX1"]').length).toBe(1);
expect($('.active-filter [data-value="edX1"]').text().trim()).toBe("edX_1");
});
});
});
}); });
...@@ -84,9 +84,7 @@ ...@@ -84,9 +84,7 @@
'js/ccx/schedule': 'js/ccx/schedule', 'js/ccx/schedule': 'js/ccx/schedule',
// edxnotes // edxnotes
'annotator_1.2.9': 'xmodule_js/common_static/js/vendor/edxnotes/annotator-full.min', 'annotator_1.2.9': 'xmodule_js/common_static/js/vendor/edxnotes/annotator-full.min'
'course_discovery_meanings': 'js/spec/discovery/course_discovery_meanings'
}, },
shim: { shim: {
'gettext': { 'gettext': {
......
...@@ -13,8 +13,8 @@ define([ ...@@ -13,8 +13,8 @@ define([
'js/search/dashboard/views/search_form', 'js/search/dashboard/views/search_form',
'js/search/course/views/search_results_view', 'js/search/course/views/search_results_view',
'js/search/dashboard/views/search_results_view', 'js/search/dashboard/views/search_results_view',
'js/search/course/search_app', 'js/search/course/course_search_factory',
'js/search/dashboard/search_app' 'js/search/dashboard/dashboard_search_factory'
], function( ], function(
$, $,
Sinon, Sinon,
...@@ -30,8 +30,8 @@ define([ ...@@ -30,8 +30,8 @@ define([
DashSearchForm, DashSearchForm,
CourseSearchResultsView, CourseSearchResultsView,
DashSearchResultsView, DashSearchResultsView,
CourseSearchApp, CourseSearchFactory,
DashSearchApp DashboardSearchFactory
) { ) {
'use strict'; 'use strict';
...@@ -681,13 +681,7 @@ define([ ...@@ -681,13 +681,7 @@ define([
this.server = Sinon.fakeServer.create(); this.server = Sinon.fakeServer.create();
var courseId = 'a/b/c'; var courseId = 'a/b/c';
this.app = new CourseSearchApp( CourseSearchFactory(courseId);
courseId,
SearchRouter,
CourseSearchForm,
SearchCollection,
CourseSearchResultsView
);
spyOn(Backbone.history, 'navigate'); spyOn(Backbone.history, 'navigate');
this.$contentElement = $('#course-content'); this.$contentElement = $('#course-content');
this.$searchResults = $('#courseware-search-results'); this.$searchResults = $('#courseware-search-results');
...@@ -718,12 +712,7 @@ define([ ...@@ -718,12 +712,7 @@ define([
loadTemplates.call(this); loadTemplates.call(this);
this.server = Sinon.fakeServer.create(); this.server = Sinon.fakeServer.create();
this.app = new DashSearchApp( DashboardSearchFactory();
SearchRouter,
DashSearchForm,
SearchCollection,
DashSearchResultsView
);
spyOn(Backbone.history, 'navigate'); spyOn(Backbone.history, 'navigate');
this.$contentElement = $('#my-courses'); this.$contentElement = $('#my-courses');
......
...@@ -18,7 +18,10 @@ ...@@ -18,7 +18,10 @@
* done. * done.
*/ */
modules: getModulesList([ modules: getModulesList([
'js/discovery/discovery_factory',
'js/groups/views/cohorts_dashboard_factory', 'js/groups/views/cohorts_dashboard_factory',
'js/search/course/course_search_factory',
'js/search/dashboard/dashboard_search_factory',
'js/student_account/views/account_settings_factory', 'js/student_account/views/account_settings_factory',
'js/student_account/views/finish_auth_factory', 'js/student_account/views/finish_auth_factory',
'js/student_profile/views/learner_profile_factory', 'js/student_profile/views/learner_profile_factory',
...@@ -57,7 +60,7 @@ ...@@ -57,7 +60,7 @@
'underscore': 'empty:', 'underscore': 'empty:',
'logger': 'empty:', 'logger': 'empty:',
'utility': 'empty:', 'utility': 'empty:',
'URI': 'empty:' 'URI': 'empty:',
}, },
/** /**
......
...@@ -2,33 +2,27 @@ ...@@ -2,33 +2,27 @@
import json import json
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from microsite_configuration import microsite from microsite_configuration import microsite
from openedx.core.lib.json_utils import EscapedEdxJSONEncoder
%> %>
<%inherit file="../main.html" /> <%inherit file="../main.html" />
<%namespace name='static' file='../static_content.html'/> <%namespace name='static' file='../static_content.html'/>
% if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
<%block name="header_extras"> <%block name="header_extras">
% if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
% for template_name in ["result_item", "filter_bar", "filter", "search_facets_list", "search_facets_section", "search_facet", "more_less_links"]: % for template_name in ["result_item", "filter_bar", "filter", "search_facets_list", "search_facets_section", "search_facet", "more_less_links"]:
<script type="text/template" id="${template_name}-tpl"> <script type="text/template" id="${template_name}-tpl">
<%static:include path="discovery/${template_name}.underscore" /> <%static:include path="discovery/${template_name}.underscore" />
</script> </script>
% endfor % endfor
<script type="text/javascript">;(function (define) {{ <%static:require_module module_name="js/discovery/discovery_factory" class_name="DiscoveryFactory">
define('course_discovery_meanings', function() {{ DiscoveryFactory(
'use strict'; ${json.dumps(course_discovery_meanings, cls=EscapedEdxJSONEncoder)},
return ${json.dumps(course_discovery_meanings)}; getParameterByName('search_query')
}}); );
}})(define || RequireJS.define); </%static:require_module>
</script>
% endif
</%block>
<%block name="js_extra">
% if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
<%static:js group='discovery'/>
% endif
</%block> </%block>
% endif
<%block name="pagetitle">${_("Courses")}</%block> <%block name="pagetitle">${_("Courses")}</%block>
<% <%
......
...@@ -66,7 +66,10 @@ ${page_title_breadcrumbs(course_name())} ...@@ -66,7 +66,10 @@ ${page_title_breadcrumbs(course_name())}
<%static:js group='courseware'/> <%static:js group='courseware'/>
<%static:js group='discussion'/> <%static:js group='discussion'/>
% if settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH'): % if settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH'):
<%static:js group='courseware_search'/> <%static:require_module module_name="js/search/course/course_search_factory" class_name="CourseSearchFactory">
var courseId = $('#courseware-search-results').data('courseId');
CourseSearchFactory(courseId);
</%static:require_module>
% endif % endif
<%include file="../discussion/_js_body_dependencies.html" /> <%include file="../discussion/_js_body_dependencies.html" />
......
...@@ -45,7 +45,9 @@ from django.core.urlresolvers import reverse ...@@ -45,7 +45,9 @@ from django.core.urlresolvers import reverse
}); });
</script> </script>
% if settings.FEATURES.get('ENABLE_DASHBOARD_SEARCH'): % if settings.FEATURES.get('ENABLE_DASHBOARD_SEARCH'):
<%static:js group='dashboard_search'/> <%static:require_module module_name="js/search/dashboard/dashboard_search_factory" class_name="DashboardSearchFactory">
DashboardSearchFactory();
</%static:require_module>
% endif % endif
</%block> </%block>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment