Commit afe731cd by Daniel Friedman

Respond to code review feedback

parent e6cca75b
...@@ -15,31 +15,42 @@ define(function (require) { ...@@ -15,31 +15,42 @@ define(function (require) {
LearnersRootView = Marionette.LayoutView.extend({ LearnersRootView = Marionette.LayoutView.extend({
template: _.template(rootTemplate), template: _.template(rootTemplate),
regions: { regions: {
error: '.learners-error-region', error: '.learners-error-region',
header: '.learners-header-region', header: '.learners-header-region',
main: '.learners-main-region' main: '.learners-main-region'
}, },
childEvents: { childEvents: {
appError: 'onAppError', appError: 'onAppError',
clearError: 'onClearError' clearError: 'onClearError',
setFocusToTop: 'onSetFocusToTop'
}, },
initialize: function (options) { initialize: function (options) {
this.options = options || {}; this.options = options || {};
}, },
onRender: function () { onRender: function () {
this.showChildView('header', new HeaderView({ this.showChildView('header', new HeaderView({
model: this.options.pageModel model: this.options.pageModel
})); }));
}, },
onAppError: function (childView, errorMessage) { onAppError: function (childView, errorMessage) {
this.showChildView('error', new AlertView({ this.showChildView('error', new AlertView({
alertType: 'error', alertType: 'error',
title: errorMessage title: errorMessage
})); }));
}, },
onClearError: function () { onClearError: function () {
this.getRegion('error').empty(); this.getRegion('error').empty();
},
onSetFocusToTop: function () {
this.$('#learner-app-focusable').focus();
} }
}); });
......
...@@ -40,5 +40,12 @@ define(function (require) { ...@@ -40,5 +40,12 @@ define(function (require) {
this.rootView.triggerMethod('clearError', 'This is the error copy'); this.rootView.triggerMethod('clearError', 'This is the error copy');
expect(this.rootView.$('.learners-error-region')).not.toHaveText('This is the error copy'); expect(this.rootView.$('.learners-error-region')).not.toHaveText('This is the error copy');
}); });
it('sets focus on setFocusToTop events', function () {
var childView = new Marionette.View();
this.rootView.showChildView('main', childView);
childView.triggerMethod('setFocusToTop');
expect(this.rootView.$('#learner-app-focusable')).toBeFocused();
});
}); });
}); });
...@@ -51,10 +51,11 @@ define(function (require) { ...@@ -51,10 +51,11 @@ define(function (require) {
templateHelpers: function () { templateHelpers: function () {
// 'filterValues' is an array of objects, each having a 'name' key // 'filterValues' is an array of objects, each having a 'name' key
// and a 'displayName' key. 'name' is the canonical name for the // and a 'displayName' key. 'name' is the name of the filter value
// filter, while 'displayName' is the user-facing representation of // (e.g. the cohort name when filtering by cohort), while
// the filter which combines the filter with the number of users // 'displayName' is the user-facing representation of the filter
// belonging to it. // which combines the filter with the number of users belonging to
// it.
var catchAllFilterValue, var catchAllFilterValue,
filterValues, filterValues,
selectedFilterValue; selectedFilterValue;
...@@ -65,12 +66,18 @@ define(function (require) { ...@@ -65,12 +66,18 @@ define(function (require) {
numLearners = filterPair[1]; numLearners = filterPair[1];
return { return {
name: name, name: name,
displayName: _.template('<%= name %> (<%= numLearners %>)')({ displayName: _.template(
// jshint ignore:start
// Translators: 'name' here refers to the name of the filter, while 'numLearners' refers to the number of learners belonging to that filter.
gettext('<%= name %> (<%= numLearners %>)')
// jshint ignore:end
)({
name: name, name: name,
numLearners: Utils.localizeNumber(numLearners, 0) numLearners: Utils.localizeNumber(numLearners, 0)
}) })
}; };
}) })
.sortBy('name')
.value(); .value();
if (filterValues.length) { if (filterValues.length) {
...@@ -109,7 +116,7 @@ define(function (require) { ...@@ -109,7 +116,7 @@ define(function (require) {
$(event.currentTarget).find('option:selected').val() $(event.currentTarget).find('option:selected').val()
); );
this.collection.refresh(); this.collection.refresh();
$('#learner-app-focusable').focus(); this.triggerMethod('setFocusToTop');
} }
}); });
......
...@@ -507,6 +507,34 @@ define(function (require) { ...@@ -507,6 +507,34 @@ define(function (require) {
expect($('option[value="' + filterValue + '"]')).toBeSelected(); expect($('option[value="' + filterValue + '"]')).toBeSelected();
}; };
it('renders filters in alphabetical order', function () {
var options,
rosterView;
rosterView = getRosterView({courseMetadata: {
cohorts: {
zebra: 1,
antelope: 2
}
}});
options = rosterView.$('.learners-filter option');
expect(options[1]).toHaveText('antelope (2)');
expect(options[2]).toHaveText('zebra (1)');
});
it('sets focus after executing a filter', function () {
var rosterView,
spy,
cohortFilterView;
rosterView = getRosterView({courseMetadata: {cohorts: {
mudskipper: 1
}}});
spy = {onFocusTriggered: function () {}};
cohortFilterView = rosterView.controls.currentView.cohortFilter.currentView;
spyOn(cohortFilterView, 'triggerMethod');
expectCanFilterBy('cohort', 'mudskipper');
expect(cohortFilterView.triggerMethod).toHaveBeenCalledWith('setFocusToTop');
});
SpecHelpers.withConfiguration({ SpecHelpers.withConfiguration({
'by cohort': [ 'by cohort': [
'cohort', // filter field name 'cohort', // filter field name
...@@ -560,6 +588,7 @@ define(function (require) { ...@@ -560,6 +588,7 @@ define(function (require) {
_.chain(this.filterOptions) _.chain(this.filterOptions)
.pairs() .pairs()
.sortBy(0) // we expect the filter options to appear in alphabetical order
.zip(_.rest(selectOptions)) .zip(_.rest(selectOptions))
.each(function (filterAndSelectOption) { .each(function (filterAndSelectOption) {
var filterOption = filterAndSelectOption[0], var filterOption = filterAndSelectOption[0],
......
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