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