From 7726693dfb8fe9dc32a7aed8c901e2c0d2901866 Mon Sep 17 00:00:00 2001 From: Romit Choudhary Date: Tue, 7 Sep 2021 11:16:01 +0200 Subject: [PATCH] Fixes #2528 - Manage -> Calendars -> Edit: "Subscribe to public holidays in" sorted wrong --- .../controllers/_ui_element/ical_feed.coffee | 6 +++-- .../javascripts/app/lib/app_post/utils.coffee | 5 ++++- spec/system/manage/calendars_spec.rb | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_ui_element/ical_feed.coffee b/app/assets/javascripts/app/controllers/_ui_element/ical_feed.coffee index f54ee7e1b..45ae04d2e 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/ical_feed.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/ical_feed.coffee @@ -2,8 +2,10 @@ class App.UiElement.ical_feed extends App.UiElement.ApplicationUiElement @render: (attribute, params) -> - icalFeeds = App.Config.get('ical_feeds') || {} - icalFeedsSorted = App.Utils.sortByValue(icalFeeds) + icalFeeds = App.Config.get('ical_feeds') || {} + icalFeedsTranslated = _.mapObject icalFeeds, (value, key) -> App.i18n.translateContent(value) + icalFeedsSorted = App.Utils.sortByValue(icalFeedsTranslated) + item = $( App.view('generic/ical_feed')( attribute: attribute, icalFeeds: icalFeedsSorted ) ) updateCheckList = -> diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 617df5219..cbc0585d2 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -1008,7 +1008,10 @@ class App.Utils valueTmp = value.toString().toLowerCase() byNames.push valueTmp byNamesWithValue[valueTmp] = [i, value] - byNames = byNames.sort() + + # sort() by default doesn't compare non-ascii characters such as ['é', 'a', 'ú', 'c'] + # hence using localecompare in sorting for translated strings + byNames = byNames.sort((a, b) -> a.localeCompare(b)) # do a reverse, if needed if order == 'DESC' diff --git a/spec/system/manage/calendars_spec.rb b/spec/system/manage/calendars_spec.rb index 7d5b77760..eaa7812de 100644 --- a/spec/system/manage/calendars_spec.rb +++ b/spec/system/manage/calendars_spec.rb @@ -46,4 +46,26 @@ RSpec.describe 'Manage > Calendars', type: :system do end end end + + # https://github.com/zammad/zammad/issues/2528 + context 'ical feed - subscribe to public holidays in another country' do + it 'shows countries dropdown in sorted order' do + allow(Calendar).to receive(:ical_feeds).and_return({ + 'https://argentinien.de': 'Argentinien', + 'https://australien.de': 'Australien', + 'https://osterreich.de': 'Österreich', + 'https://weibrussland.de': 'Weißrussland', + 'https://kanada.de': 'Kanada', + 'https://chile.de': 'Chile', + }) + + visit '/#manage/calendars' + + click '.js-new' + + in_modal disappears: false do + expect(all('.ical_feed select option').map(&:text)).to eq ['-', 'Argentinien', 'Australien', 'Chile', 'Kanada', 'Österreich', 'Weißrussland'] + end + end + end end