Include links only for supported services

pull/163/head
Tim Mecklem 7 years ago committed by jimmay5469
parent 2aab375928
commit 435284c01f
  1. 7
      apps/explorer_web/config/config.exs
  2. 20
      apps/explorer_web/lib/explorer_web/social_media.ex
  3. 21
      apps/explorer_web/test/explorer_web/features/social_media_links_test.exs
  4. 25
      apps/explorer_web/test/explorer_web/social_media_test.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.Gettext, locales: ~w(en), default_locale: "en"
config :explorer_web, ExplorerWeb.SocialMedia, config :explorer_web, ExplorerWeb.SocialMedia,
facebook: "https://www.facebook.com/PoaNetwork", twitter: "PoaNetwork",
instagram: "https://www.instagram.com/PoaNetwork", telegram: "oraclesnetwork",
twitter: "https://www.twitter.com/PoaNetwork" facebook: "PoaNetwork",
instagram: "PoaNetwork"
config :ex_cldr, config :ex_cldr,
default_locale: "en", default_locale: "en",

@ -3,7 +3,25 @@ defmodule ExplorerWeb.SocialMedia do
This module provides social media links 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 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
end end

@ -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

@ -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
Loading…
Cancel
Save