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 = {}
9 name = OsmCommunityIndex.resolve_name(community, community_locale_yaml)
10 assert_equal("Community Name", name)
13 def test_resource_name_fallback
14 # If there is a name for the chapter, prefer that to the community name
15 community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "name" => "Chapter Name" } })
16 community_locale_yaml = {}
18 name = OsmCommunityIndex.resolve_name(community, community_locale_yaml)
19 assert_equal("Chapter Name", name)
22 def test_i18n_explicit_name
23 # If there is an explicitly translated name for the chapter, use that
24 community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "name" => "Chapter Name" } })
25 community_locale_yaml = { "foo-chapter" => { "name" => "Translated Chapter Name" } }
27 name = OsmCommunityIndex.resolve_name(community, community_locale_yaml)
28 assert_equal("Translated Chapter Name", name)
31 def test_i18n_fallback_name
32 # If there's no explicitly translated name for the chapter, use the default name and interpolate the community name if required.
33 community = Community.new({ "id" => "foo-chapter", "type" => "osm-lc", "strings" => { "community" => "Community Name", "communityID" => "communityname" } })
34 community_locale_yaml = { "_communities" => { "communityname" => "Translated Community" }, "_defaults" => { "osm-lc" => { "name" => "{community} Chapter" } } }
36 name = OsmCommunityIndex.resolve_name(community, community_locale_yaml)
37 assert_equal("Translated Community Chapter", name)