Convert remaining address page tests to page module calls

Decouple design concerns from test concerns by changing test selectors
to use `data-test` attribute selection instead of overloading css
classes for both purposes.

Co-authored-by: jimmay5469 <jimmay5469@gmail.com>
Co-authored-by: stamates <stamates@hotmail.com>
pull/156/head
Tim Mecklem 7 years ago
parent 5f7f9c48d0
commit d27dec7615
  1. 11
      apps/explorer/test/support/factories/chain/transaction_factory.ex
  2. 2
      apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex
  3. 13
      apps/explorer_web/lib/explorer_web/templates/address_internal_transaction/index.html.eex
  4. 16
      apps/explorer_web/lib/explorer_web/templates/address_transaction/index.html.eex
  5. 137
      apps/explorer_web/test/explorer_web/features/address_page_test.exs
  6. 13
      apps/explorer_web/test/explorer_web/features/pages/address_page.ex

@ -23,14 +23,19 @@ defmodule Explorer.Chain.TransactionFactory do
} }
end end
def list_with_block(transactions, block \\ nil) do
Enum.map(transactions, fn transaction -> with_block(transaction, block) end)
end
def with_block(transaction, block \\ nil) do def with_block(transaction, block \\ nil) do
block = block || insert(:block) block = block || insert(:block)
insert(:block_transaction, %{block_id: block.id, transaction_id: transaction.id}) insert(:block_transaction, block_id: block.id, transaction_id: transaction.id)
transaction transaction
end end
def list_with_block(transactions, block \\ nil) do def with_receipt(transaction) do
Enum.map(transactions, fn transaction -> with_block(transaction, block) end) insert(:receipt, transaction_id: transaction.id)
transaction
end end
end end
end end

@ -7,7 +7,7 @@
<dl> <dl>
<div class="address__item"> <div class="address__item">
<dt class="address__item-key"><%= gettext "Balance" %></dt> <dt class="address__item-key"><%= gettext "Balance" %></dt>
<dd class="address__item-value address__balance" title="<%= @address.hash %>"> <dd class="address__item-value address__balance" title="<%= @address.hash %>" data-test="address_balance">
<%= balance(@address) %> <%= gettext "Ether" %> <%= balance(@address) %> <%= gettext "Ether" %>
</dd> </dd>
</div> </div>

@ -27,30 +27,33 @@
<div class="dropdown-menu dropdown-menu-right filter" aria-labelledby="dropdownMenu2"> <div class="dropdown-menu dropdown-menu-right filter" aria-labelledby="dropdownMenu2">
<%= link( <%= link(
gettext("All"), gettext("All"),
to: address_internal_transaction_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"]),
class: "address__link address__link--active dropdown-item", class: "address__link address__link--active dropdown-item",
to: address_internal_transaction_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"]) "data-test": "filter_option"
) %> ) %>
<%= link( <%= link(
gettext("To"), gettext("To"),
class: "address__link address__link--active dropdown-item",
to: address_internal_transaction_path( to: address_internal_transaction_path(
@conn, @conn,
:index, :index,
@conn.assigns.locale, @conn.assigns.locale,
@conn.params["address_id"], @conn.params["address_id"],
filter: "to" filter: "to"
) ),
class: "address__link address__link--active dropdown-item",
"data-test": "filter_option"
) %> ) %>
<%= link( <%= link(
gettext("From"), gettext("From"),
class: "address__link address__link--active dropdown-item",
to: address_internal_transaction_path( to: address_internal_transaction_path(
@conn, @conn,
:index, :index,
@conn.assigns.locale, @conn.assigns.locale,
@conn.params["address_id"], @conn.params["address_id"],
filter: "from" filter: "from"
) ),
class: "address__link address__link--active dropdown-item",
"data-test": "filter_option"
) %> ) %>
</div> </div>
</div> </div>

@ -27,30 +27,33 @@
<div class="dropdown-menu dropdown-menu-right filter" aria-labelledby="dropdownMenu2"> <div class="dropdown-menu dropdown-menu-right filter" aria-labelledby="dropdownMenu2">
<%= link( <%= link(
gettext("All"), gettext("All"),
to: address_transaction_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"]),
class: "address__link address__link--active dropdown-item", class: "address__link address__link--active dropdown-item",
to: address_transaction_path(@conn, :index, @conn.assigns.locale, @conn.params["address_id"]) "data-test": "filter_option"
) %> ) %>
<%= link( <%= link(
gettext("To"), gettext("To"),
class: "address__link address__link--active dropdown-item",
to: address_transaction_path( to: address_transaction_path(
@conn, @conn,
:index, :index,
@conn.assigns.locale, @conn.assigns.locale,
@conn.params["address_id"], @conn.params["address_id"],
filter: "to" filter: "to"
) ),
class: "address__link address__link--active dropdown-item",
"data-test": "filter_option"
) %> ) %>
<%= link( <%= link(
gettext("From"), gettext("From"),
class: "address__link address__link--active dropdown-item",
to: address_transaction_path( to: address_transaction_path(
@conn, @conn,
:index, :index,
@conn.assigns.locale, @conn.assigns.locale,
@conn.params["address_id"], @conn.params["address_id"],
filter: "from" filter: "from"
) ),
class: "address__link address__link--active dropdown-item",
"data-test": "filter_option"
) %> ) %>
</div> </div>
</div> </div>
@ -80,8 +83,9 @@
<div class="transactions__hash"> <div class="transactions__hash">
<%= link( <%= link(
transaction.hash, transaction.hash,
to: transaction_path(@conn, :show, @conn.assigns.locale, transaction.hash),
class: "transactions__link transactions__link--truncated transactions__link--long-hash", class: "transactions__link transactions__link--truncated transactions__link--long-hash",
to: transaction_path(@conn, :show, @conn.assigns.locale, transaction.hash) "data-test": "transaction_hash"
) %> ) %>
</div> </div>
</td> </td>

@ -1,109 +1,90 @@
defmodule ExplorerWeb.AddressPageTest do defmodule ExplorerWeb.AddressPageTest do
use ExplorerWeb.FeatureCase, async: true use ExplorerWeb.FeatureCase, async: true
import Wallaby.Query, only: [css: 2]
alias Explorer.Chain.{Credit, Debit}
alias ExplorerWeb.AddressPage alias ExplorerWeb.AddressPage
setup do setup do
block = block = insert(:block)
insert(:block, %{
number: 555, lincoln = insert(:address)
timestamp: Timex.now() |> Timex.shift(hours: -2), taft = insert(:address)
gas_used: 123_987
}) from_taft =
:transaction
for _ <- 0..3, do: insert(:transaction) |> with_block(block) |> insert(from_address_id: taft.id, to_address_id: lincoln.id)
insert(:transaction, hash: "0xC001", gas: 5891) |> with_block |> with_block(block)
|> with_receipt()
lincoln = insert(:address, hash: "0xlincoln")
taft = insert(:address, hash: "0xhowardtaft") from_lincoln =
:transaction
transaction = |> insert(from_address_id: lincoln.id, to_address_id: taft.id)
insert( |> with_block(block)
:transaction, |> with_receipt()
hash: "0xSk8",
value: Explorer.Chain.Wei.from(Decimal.new(5656), :ether), {:ok,
gas: Decimal.new(1_230_000_000_000_123_123), %{
gas_price: Decimal.new(7_890_000_000_898_912_300_045), transactions: %{from_lincoln: from_lincoln, from_taft: from_taft},
input: "0x00012", addresses: %{lincoln: lincoln, taft: taft}
nonce: 99045, }}
inserted_at: Timex.parse!("1970-01-01T00:00:18-00:00", "{ISO:Extended}"),
updated_at: Timex.parse!("1980-01-01T00:00:18-00:00", "{ISO:Extended}"),
from_address_id: taft.id,
to_address_id: lincoln.id
)
insert(:block_transaction, block: block, transaction: transaction)
receipt = insert(:receipt, transaction: transaction, status: 1)
insert(:log, address_id: lincoln.id, receipt: receipt)
# From Lincoln to Taft.
txn_from_lincoln =
insert(
:transaction,
hash: "0xrazerscooter",
from_address_id: lincoln.id,
to_address_id: taft.id
)
insert(:block_transaction, block: block, transaction: txn_from_lincoln)
insert(:receipt, transaction: txn_from_lincoln)
Credit.refresh()
Debit.refresh()
{:ok, %{address: lincoln, transaction: transaction}}
end end
test "viewing address overview information", %{session: session} do test "viewing address overview information", %{session: session} do
insert(:address, hash: "0xthinmints", balance: 500) address = insert(:address, balance: 500)
session session
|> visit("/en/addresses/0xthinmints") |> AddressPage.visit_page(address)
|> assert_has(css(".address__balance", text: "0.000,000,000,000,000,500 POA")) |> assert_text(AddressPage.balance(), "0.000,000,000,000,000,500 POA")
end end
describe "viewing transactions" do describe "viewing transactions" do
test "sees all addresses transactions by default", %{address: address, session: session} do test "sees all addresses transactions by default", %{
addresses: addresses,
session: session,
transactions: transactions
} do
session session
|> AddressPage.visit_page(address.hash) |> AddressPage.visit_page(addresses.lincoln)
|> assert_has(AddressPage.transaction("0xSk8")) |> assert_has(AddressPage.transaction(transactions.from_taft))
|> assert_has(AddressPage.transaction("0xrazerscooter")) |> assert_has(AddressPage.transaction(transactions.from_lincoln))
end end
test "can filter to only see transactions to an address", %{address: address, session: session} do test "can filter to only see transactions from an address", %{
addresses: addresses,
session: session,
transactions: transactions
} do
session session
|> visit("/en/addresses/#{address.hash}") |> AddressPage.visit_page(addresses.lincoln)
|> click(css("[data-test='filter_dropdown']", text: "Filter: All")) |> AddressPage.apply_filter("From")
|> click(css(".address__link", text: "To")) |> assert_has(AddressPage.transaction(transactions.from_lincoln))
|> assert_has(css(".transactions__link--long-hash", text: "0xSk8")) |> refute_has(AddressPage.transaction(transactions.from_taft))
|> refute_has(css(".transactions__link--long-hash", text: "0xrazerscooter"))
end end
test "can filter to only see transactions from an address", %{address: address, session: session} do test "can filter to only see transactions to an address", %{
addresses: addresses,
session: session,
transactions: transactions
} do
session session
|> visit("/en/addresses/#{address.hash}") |> AddressPage.visit_page(addresses.lincoln)
|> click(css("[data-test='filter_dropdown']", text: "Filter: All")) |> AddressPage.apply_filter("To")
|> click(css(".address__link", text: "From")) |> refute_has(AddressPage.transaction(transactions.from_lincoln))
|> assert_has(css(".transactions__link--long-hash", text: "0xrazerscooter")) |> assert_has(AddressPage.transaction(transactions.from_taft))
|> refute_has(css(".transactions__link--long-hash", text: "0xSk8"))
end end
end end
describe "viewing internal transactions" do describe "viewing internal transactions" do
setup %{address: address, transaction: transaction} do setup %{addresses: addresses, transactions: transactions} do
insert(:internal_transaction, transaction_id: transaction.id, to_address_id: address.id) address_id = addresses.lincoln.id
insert(:internal_transaction, transaction_id: transaction.id, from_address_id: address.id) transaction_id = transactions.from_lincoln.id
insert(:internal_transaction, transaction_id: transaction_id, to_address_id: address_id, index: 0)
insert(:internal_transaction, transaction_id: transaction_id, from_address_id: address_id, index: 1)
:ok :ok
end end
test "can see internal transactions for an address", %{address: address, session: session} do test "can see internal transactions for an address", %{addresses: addresses, session: session} do
session session
|> AddressPage.visit_page(address.hash) |> AddressPage.visit_page(addresses.lincoln)
|> AddressPage.click_internal_transactions() |> AddressPage.click_internal_transactions()
|> assert_has(AddressPage.internal_transactions(count: 2)) |> assert_has(AddressPage.internal_transactions(count: 2))
end end
@ -118,7 +99,7 @@ defmodule ExplorerWeb.AddressPageTest do
test "can filter to only see internal transactions to an address", %{addresses: addresses, session: session} do test "can filter to only see internal transactions to an address", %{addresses: addresses, session: session} do
session session
|> AddressPage.visit_page(address.hash) |> AddressPage.visit_page(addresses.lincoln)
|> AddressPage.click_internal_transactions() |> AddressPage.click_internal_transactions()
|> AddressPage.apply_filter("To") |> AddressPage.apply_filter("To")
|> assert_has(AddressPage.internal_transactions(count: 1)) |> assert_has(AddressPage.internal_transactions(count: 1))

@ -3,6 +3,9 @@ defmodule ExplorerWeb.AddressPage do
use Wallaby.DSL use Wallaby.DSL
import Wallaby.Query, only: [css: 1, css: 2] import Wallaby.Query, only: [css: 1, css: 2]
alias Explorer.Chain.{Address, Transaction}
def visit_page(session, %Address{hash: address_hash}), do: visit_page(session, address_hash)
def visit_page(session, address_hash) do def visit_page(session, address_hash) do
visit(session, "/en/addresses/#{address_hash}") visit(session, "/en/addresses/#{address_hash}")
@ -13,7 +16,9 @@ defmodule ExplorerWeb.AddressPage do
click(session, css(@internal_transactions_link_selector)) click(session, css(@internal_transactions_link_selector))
end end
@transaction_selector ".transactions__link--long-hash" @transaction_selector "[data-test='transaction_hash']"
def transaction(%Transaction{hash: transaction_hash}), do: transaction(transaction_hash)
def transaction(transaction_hash) do def transaction(transaction_hash) do
css(@transaction_selector, text: transaction_hash) css(@transaction_selector, text: transaction_hash)
end end
@ -26,6 +31,10 @@ defmodule ExplorerWeb.AddressPage do
def apply_filter(session, direction) do def apply_filter(session, direction) do
session session
|> click(css("[data-test='filter_dropdown']", text: "Filter: All")) |> click(css("[data-test='filter_dropdown']", text: "Filter: All"))
|> click(css(".address__link", text: direction)) |> click(css("[data-test='filter_option']", text: direction))
end
def balance do
css("[data-test='address_balance']")
end end
end end

Loading…
Cancel
Save