From ba8d8a4f93c0f225b8c00c5866e5e17d1ed00b89 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Tue, 10 Dec 2019 12:36:49 -0500 Subject: [PATCH] FIX: alphabetical tag sorting in mini-tag-chooser --- .../select-kit/components/mini-tag-chooser.js.es6 | 2 +- .../components/mini-tag-chooser-test.js.es6 | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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 bc5d8c0b07d..f0ebb00151c 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 ae52da4c705..27918e20b26 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" );