diff --git a/apps/explorer_web/config/config.exs b/apps/explorer_web/config/config.exs index 7099b19fc9..3ad584f5cf 100644 --- a/apps/explorer_web/config/config.exs +++ b/apps/explorer_web/config/config.exs @@ -20,9 +20,10 @@ config :explorer_web, ExplorerWeb.Endpoint, config :explorer_web, ExplorerWeb.Gettext, locales: ~w(en), default_locale: "en" config :explorer_web, ExplorerWeb.SocialMedia, - facebook: "https://www.facebook.com/PoaNetwork", - instagram: "https://www.instagram.com/PoaNetwork", - twitter: "https://www.twitter.com/PoaNetwork" + twitter: "PoaNetwork", + telegram: "oraclesnetwork", + facebook: "PoaNetwork", + instagram: "PoaNetwork" config :ex_cldr, default_locale: "en", diff --git a/apps/explorer_web/lib/explorer_web/social_media.ex b/apps/explorer_web/lib/explorer_web/social_media.ex index 49473bc799..86c36e955c 100644 --- a/apps/explorer_web/lib/explorer_web/social_media.ex +++ b/apps/explorer_web/lib/explorer_web/social_media.ex @@ -3,7 +3,25 @@ defmodule ExplorerWeb.SocialMedia do This module provides social media links """ + @services %{ + facebook: "https://www.facebook.com/", + instagram: "https://www.instagram.com/", + twitter: "https://www.twitter.com/", + telegram: "https://t.me/" + } + def links do - Application.get_env(:explorer_web, __MODULE__, []) + :explorer_web + |> Application.get_env(__MODULE__, []) + |> Enum.reverse() + |> filter_and_build_links() + end + + # Private functions + + defp filter_and_build_links(configured_services) do + for {name, account} <- configured_services, Map.has_key?(@services, name) do + {name, @services[name] <> account} + end end end diff --git a/apps/explorer_web/test/explorer_web/features/social_media_links_test.exs b/apps/explorer_web/test/explorer_web/features/social_media_links_test.exs deleted file mode 100644 index 385c0f9f1e..0000000000 --- a/apps/explorer_web/test/explorer_web/features/social_media_links_test.exs +++ /dev/null @@ -1,21 +0,0 @@ -defmodule ExplorerWeb.SocialMediaLinksTest do - use ExplorerWeb.FeatureCase - - import Wallaby.Query - - test "it shows twitter when twitter is configured", %{session: session} do - Application.put_env(:explorer_web, ExplorerWeb.SocialMedia, twitter: "https://twitter.com/twitter") - - session - |> visit("/") - |> assert_has(css("[data-test='twitter_link']")) - end - - test "it hides twitter when twitter is not configured", %{session: session} do - Application.put_env(:explorer_web, ExplorerWeb.SocialMedia, facebook: "https://facebook.com/") - - session - |> visit("/") - |> refute_has(css("[data-test='twitter_link']")) - end -end diff --git a/apps/explorer_web/test/explorer_web/social_media_test.exs b/apps/explorer_web/test/explorer_web/social_media_test.exs new file mode 100644 index 0000000000..be7b7bfa0b --- /dev/null +++ b/apps/explorer_web/test/explorer_web/social_media_test.exs @@ -0,0 +1,25 @@ +defmodule ExplorerWeb.SocialMediaTest do + use Explorer.DataCase + + alias ExplorerWeb.SocialMedia + + test "it filters out unsupported services" do + Application.put_env( + :explorer_web, + ExplorerWeb.SocialMedia, + twitter: "MyTwitterProfile", + myspace: "MyAwesomeProfile" + ) + + links = SocialMedia.links() + assert Keyword.has_key?(links, :twitter) + refute Keyword.has_key?(links, :myspace) + end + + test "it prepends the service url" do + Application.put_env(:explorer_web, ExplorerWeb.SocialMedia, twitter: "MyTwitterProfile") + + links = SocialMedia.links() + assert links[:twitter] == "https://www.twitter.com/MyTwitterProfile" + end +end