]> git.openstreetmap.org Git - rails.git/blob - test/lib/osm_community_index_test.rb
Merge remote-tracking branch 'upstream/pull/5246'
[rails.git] / test / lib / osm_community_index_test.rb
1 require "test_helper"
2
3 class CountryTest < ActiveSupport::TestCase
4   def test_community_name_fallback
5     # If there is no translations and no name for the chapter, use the community name
6     community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name" } })
7     community_locale_yaml = {}
8     community_en_yaml = {}
9
10     name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
11     assert_equal("Community Name", name)
12   end
13
14   def test_resource_name_fallback
15     # If there is a name for the chapter, prefer that to the community name
16     community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "name" => "Chapter Name" } })
17     community_locale_yaml = {}
18     community_en_yaml = {}
19
20     name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
21     assert_equal("Chapter Name", name)
22   end
23
24   def test_i18n_explicit_name
25     # If there is an explicitly translated name for the chapter, use that
26     community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "name" => "Chapter Name" } })
27     community_locale_yaml = { "foo-chapter" => { "name" => "Translated Chapter Name" } }
28     community_en_yaml = {}
29
30     name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
31     assert_equal("Translated Chapter Name", name)
32   end
33
34   def test_i18n_fallback_name
35     # If there's no explicitly translated name for the chapter, use the default name and interpolate the community name if required.
36     community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "communityID" => "communityname" } })
37     community_locale_yaml = { "_communities" => { "communityname" => "Translated Community" }, "_defaults" => { "osm-lc" => { "name" => "{community} Chapter" } } }
38     community_en_yaml = {}
39
40     name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
41     assert_equal("Translated Community Chapter", name)
42   end
43
44   def test_i18n_invalid_replacement_token
45     # Ignore invalid replacement tokens in OCI data provided. This might happen if translators were mistakenly translating the predefined token ids.
46     community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "communityID" => "communityname" } })
47     community_locale_yaml = { "_communities" => { "communityname" => "Translated Community" }, "_defaults" => { "osm-lc" => { "name" => "{comminauté} Chapter" } } }
48     community_en_yaml = {}
49
50     name = OsmCommunityIndex.resolve_name(community, community_locale_yaml, community_en_yaml)
51     assert_equal("Community Name", name)
52   end
53 end