]> git.openstreetmap.org Git - rails.git/blob - test/helpers/social_share_button_helper_test.rb
Merge branch 'pull/4985'
[rails.git] / test / helpers / social_share_button_helper_test.rb
1 require "test_helper"
2
3 class SocialShareButtonHelperTest < ActionView::TestCase
4   include SocialShareButtonHelper
5   include ApplicationHelper
6
7   def setup
8     @options = {
9       :allow_sites => %w[x facebook linkedin],
10       :title => "Test Title",
11       :url => "https://example.com",
12       :desc => "Test Description",
13       :via => "testuser"
14     }
15   end
16
17   def test_render_social_share_buttons_with_valid_sites
18     result = render_social_share_buttons(@options)
19     assert_includes result, "x"
20     assert_includes result, "facebook"
21     assert_includes result, "linkedin"
22   end
23
24   def test_render_social_share_buttons_with_invalid_site
25     @options[:allow_sites] << "invalid_site"
26     result = render_social_share_buttons(@options)
27     assert_not_includes result, "invalid_site"
28   end
29
30   def test_render_social_share_buttons_with_no_sites
31     @options[:allow_sites] = []
32     result = render_social_share_buttons(@options)
33     SocialShareButtonHelper::SOCIAL_SHARE_CONFIG.each_key do |site|
34       assert_includes result, site.to_s # Convert symbol to string
35     end
36   end
37
38   def test_filter_allowed_sites
39     valid_sites, invalid_sites = SocialShareButtonHelper.filter_allowed_sites(%w[x facebook invalid_site])
40     assert_equal %w[x facebook], valid_sites
41     assert_equal %w[invalid_site], invalid_sites
42   end
43
44   def test_icon_path
45     assert_equal "social_icons/x.svg", SocialShareButtonHelper.icon_path("x")
46     assert_equal "", SocialShareButtonHelper.icon_path("invalid_site")
47   end
48 end