Configurable social media links
pull/166/head
Jimmy Lauzau 7 years ago committed by GitHub
commit 7710814876
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      apps/explorer_web/config/config.exs
  2. 27
      apps/explorer_web/lib/explorer_web/social_media.ex
  3. 20
      apps/explorer_web/lib/explorer_web/templates/layout/app.html.eex
  4. 6
      apps/explorer_web/lib/explorer_web/views/layout_view.ex
  5. 4
      apps/explorer_web/test/explorer_web/features/contributor_browsing_test.exs
  6. 25
      apps/explorer_web/test/explorer_web/social_media_test.exs
  7. 1
      apps/explorer_web/test/support/feature_case.ex

@ -10,15 +10,21 @@ config :explorer_web,
namespace: ExplorerWeb, namespace: ExplorerWeb,
ecto_repos: [Explorer.Repo] ecto_repos: [Explorer.Repo]
# Configures gettext
config :explorer_web, ExplorerWeb.Gettext, locales: ~w(en), default_locale: "en"
# Configures the endpoint # Configures the endpoint
config :explorer_web, ExplorerWeb.Endpoint, config :explorer_web, ExplorerWeb.Endpoint,
url: [host: "localhost"], url: [host: "localhost"],
render_errors: [view: ExplorerWeb.ErrorView, accepts: ~w(html json)], render_errors: [view: ExplorerWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: ExplorerWeb.PubSub, adapter: Phoenix.PubSub.PG2] pubsub: [name: ExplorerWeb.PubSub, adapter: Phoenix.PubSub.PG2]
# Configures gettext
config :explorer_web, ExplorerWeb.Gettext, locales: ~w(en), default_locale: "en"
config :explorer_web, ExplorerWeb.SocialMedia,
twitter: "PoaNetwork",
telegram: "oraclesnetwork",
facebook: "PoaNetwork",
instagram: "PoaNetwork"
config :ex_cldr, config :ex_cldr,
default_locale: "en", default_locale: "en",
locales: ["en"], locales: ["en"],

@ -0,0 +1,27 @@
defmodule ExplorerWeb.SocialMedia do
@moduledoc """
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
: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

@ -43,7 +43,7 @@
<div id="content"> <div id="content">
<div class="content-header"> <div class="content-header">
<nav> <nav>
<button type="button" id="sidebarCollapse" class="navbar-btn" data-test="hamburger_menu_button"> <button type="button" id="sidebarCollapse" class="navbar-btn">
<span></span> <span></span>
<span></span> <span></span>
<span></span> <span></span>
@ -59,21 +59,13 @@
<% end %> <% end %>
</div> </div>
<div class="header__cell header__cell--links u-nudge-top" align="right"> <div class="header__cell header__cell--links u-nudge-top" align="right">
<a href="https://www.facebook.com/PoaNetwork/" target="_blank" class="header__link"> <%= for {service, link} <- configured_social_media_services() do %>
<%= link to: link, class: "header__link", target: "_blank", "data-test": "#{service}_link" do %>
<div class="social-media"> <div class="social-media">
<i class="fa fa-facebook-f"></i> <i class="fa fa-<%= service %>"></i>
</div> </div>
</a> <% end %>
<a href="https://www.instagram.com/PoaNetwork/" target="_blank" class="header__link"> <% end %>
<div class="social-media">
<i class="fa fa-instagram"></i>
</div>
</a>
<a href="https://www.twitter.com/PoaNetwork/" target="_blank" class="header__link">
<div class="social-media">
<i class="fa fa-twitter"></i>
</div>
</a>
</div> </div>
</div> </div>
</div> </div>

@ -1,3 +1,9 @@
defmodule ExplorerWeb.LayoutView do defmodule ExplorerWeb.LayoutView do
use ExplorerWeb, :view use ExplorerWeb, :view
alias ExplorerWeb.SocialMedia
def configured_social_media_services do
SocialMedia.links()
end
end end

@ -12,7 +12,6 @@ defmodule ExplorerWeb.UserListTest do
assert current_path(session) == "/en" assert current_path(session) == "/en"
session session
|> click(css("[data-test='hamburger_menu_button']"))
|> click(@logo) |> click(@logo)
|> assert_has(css("main", text: "Blocks")) |> assert_has(css("main", text: "Blocks"))
end end
@ -91,7 +90,6 @@ defmodule ExplorerWeb.UserListTest do
|> assert_has(css(".blocks__column--gas-used", count: 5, text: "10")) |> assert_has(css(".blocks__column--gas-used", count: 5, text: "10"))
session session
|> click(css("[data-test='hamburger_menu_button']"))
|> click(link("Blocks")) |> click(link("Blocks"))
|> assert_has(css(".blocks__column--height", text: "311")) |> assert_has(css(".blocks__column--height", text: "311"))
|> click(link("311")) |> click(link("311"))
@ -168,7 +166,7 @@ defmodule ExplorerWeb.UserListTest do
|> assert_has(css(".transactions__title", text: "Transactions")) |> assert_has(css(".transactions__title", text: "Transactions"))
|> assert_has(css(".transactions__column--hash", count: 5)) |> assert_has(css(".transactions__column--hash", count: 5))
|> assert_has(css(".transactions__column--value", count: 5)) |> assert_has(css(".transactions__column--value", count: 5))
|> assert_has(css(".transactions__column--age", count: 5, visible: false)) |> assert_has(css(".transactions__column--age", count: 5))
end end
test "can see pending transactions", %{session: session} do test "can see pending transactions", %{session: session} do

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

@ -24,6 +24,7 @@ defmodule ExplorerWeb.FeatureCase do
metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for(Explorer.Repo, self()) metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for(Explorer.Repo, self())
{:ok, session} = Wallaby.start_session(metadata: metadata) {:ok, session} = Wallaby.start_session(metadata: metadata)
session = Wallaby.Browser.resize_window(session, 1200, 800)
{:ok, session: session} {:ok, session: session}
end end
end end

Loading…
Cancel
Save