Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #815 from mitodl/feature/gs/sort_terms
Browse files Browse the repository at this point in the history
Sorted terms in taxonomy panel
  • Loading branch information
George Schneeloch committed Nov 3, 2015
2 parents 3d66577 + 07e57f7 commit 2e3032a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
76 changes: 42 additions & 34 deletions ui/jstests/test_manage_taxonomies.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2359,22 +2359,21 @@ define(['QUnit', 'jquery', 'lodash', 'manage_taxonomies', 'react',
});

var afterMount = function(component) {
assert.equal(
component.state.vocabularies.length,
0
);
assert.equal(component.state.vocabularies.length, 0);
waitForAjax(2, function() {
assert.equal(
component.state.vocabularies.length,
2
);
assert.equal(
component.state.vocabularies[0].terms.length,
2
assert.equal(component.state.vocabularies.length, 2);
var difficultyVocab = _.find(
component.state.vocabularies, function(vocab) {
return vocab.vocabulary.name === "difficulty";
}
);
assert.equal(difficultyVocab.terms.length, 2);
var difficultTerm = _.find(difficultyVocab.terms, function(term) {
return term.label === 'difficult';
});
var updateTermUrl = "/api/v1/repositories/demo/vocabularies/" +
component.state.vocabularies[0].vocabulary.slug + "/terms/" +
component.state.vocabularies[0].terms[0].slug + "/";
difficultyVocab.vocabulary.slug + "/terms/" +
difficultTerm.slug + "/";
TestUtils.initMockjax({
url: updateTermUrl,
responseText: term,
Expand Down Expand Up @@ -2419,13 +2418,19 @@ define(['QUnit', 'jquery', 'lodash', 'manage_taxonomies', 'react',
component.state.vocabularies.length,
2
);
var difficultyVocab = _.find(
component.state.vocabularies, function(vocab) {
return vocab.vocabulary.name === "difficulty";
}
);
assert.equal(
component.state.vocabularies[0].terms.length,
difficultyVocab.terms.length,
2
);
assert.equal(
component.state.vocabularies[0].terms[0].label,
"TestB"
assert.ok(
_.some(difficultyVocab.terms, function(term) {
return term.label === "TestB";
})
);
done();
});
Expand Down Expand Up @@ -2573,22 +2578,22 @@ define(['QUnit', 'jquery', 'lodash', 'manage_taxonomies', 'react',
};

var afterMount = function(component) {
assert.equal(
component.state.vocabularies.length,
0
);
assert.equal(component.state.vocabularies.length, 0);
waitForAjax(2, function() {
assert.equal(
component.state.vocabularies.length,
1
);
assert.equal(
component.state.vocabularies[0].terms.length,
2
assert.equal(component.state.vocabularies.length, 1);
var difficultyVocab = _.find(component.state.vocabularies,
function(vocab) {
return vocab.vocabulary.name === 'difficulty';
}
);
assert.equal(difficultyVocab.terms.length, 2);
var difficultTerm = _.find(difficultyVocab.terms, function(term) {
return term.label === 'difficult';
});

var updateTermUrl = "/api/v1/repositories/repo/vocabularies/" +
component.state.vocabularies[0].vocabulary.slug + "/terms/" +
component.state.vocabularies[0].terms[0].slug + "/";
difficultyVocab.vocabulary.slug + "/terms/" +
difficultTerm.slug + "/";
TestUtils.initMockjax({
url: updateTermUrl,
type: "DELETE"
Expand All @@ -2605,12 +2610,15 @@ define(['QUnit', 'jquery', 'lodash', 'manage_taxonomies', 'react',
waitForAjax(1, function () {
assert.equal(refreshCount, 1);
//assert term update
assert.equal(
component.state.vocabularies.length,
1
assert.equal(component.state.vocabularies.length, 1);
var difficultyVocab = _.find(component.state.vocabularies,
function(vocab) {
return vocab.vocabulary.name === 'difficulty';
}
);

assert.equal(
component.state.vocabularies[0].terms.length,
difficultyVocab.terms.length,
1
);
done();
Expand Down
5 changes: 4 additions & 1 deletion ui/static/ui/js/manage_taxonomies.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ define('manage_taxonomies', ['react', 'lodash', 'jquery', 'uri',
mixins: [React.addons.LinkedStateMixin],
render: function () {
var thiz = this;
var items = _.map(this.props.terms, function (term) {
var sortedTerms = _.sortBy(this.props.terms, function(term) {
return term.label.trim().toLowerCase();
});
var items = _.map(sortedTerms, function (term) {
return <TermComponent
deleteTerm={thiz.props.deleteTerm}
updateTerm={thiz.props.updateTerm}
Expand Down

0 comments on commit 2e3032a

Please sign in to comment.