diff --git a/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 b/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 index bc5d8c0b07..f0ebb00151 100644 --- a/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 +++ b/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 @@ -218,7 +218,7 @@ export default ComboBox.extend(TagsMixin, { context.set("termMatchErrorMessage", json.forbidden_message); if (context.get("siteSettings.tags_sort_alphabetically")) { - results = results.sort((a, b) => a.id > b.id); + results = results.sort((a, b) => a.text.localeCompare(b.text)); } results = results.filter(r => !context.get("selection").includes(r.id)); diff --git a/test/javascripts/components/mini-tag-chooser-test.js.es6 b/test/javascripts/components/mini-tag-chooser-test.js.es6 index ae52da4c70..27918e20b2 100644 --- a/test/javascripts/components/mini-tag-chooser-test.js.es6 +++ b/test/javascripts/components/mini-tag-chooser-test.js.es6 @@ -14,6 +14,7 @@ componentTest("default", { beforeEach() { this.siteSettings.max_tag_length = 24; this.siteSettings.force_lowercase_tags = true; + this.siteSettings.tags_sort_alphabetically = true; this.site.set("can_create_tag", true); this.set("tags", ["jeff", "neil", "arpit"]); @@ -35,11 +36,10 @@ componentTest("default", { } return response({ - results: [{ text: "bianca", count: 3 }, { text: "régis", count: 5 }] + results: [{ text: "penar", count: 3 }, { text: "bianca", count: 3 }, { text: "régis", count: 5 }] }); }); }, - skip: true, async test(assert) { await this.subject.expand(); @@ -51,6 +51,12 @@ componentTest("default", { assert.equal( this.subject.rowByIndex(1).name(), + "penar", + "it has the correct tag at the correct position after alphabetical sorting" + ); + + assert.equal( + this.subject.rowByIndex(2).name(), "régis", "it has the correct tag" );