Write failing test for live reloading transactions on homepage

Co-authored-by: Stamates <stamates@hotmail.com>
pull/497/head
jimmay5469 6 years ago
parent ef36e8c8a5
commit 91fc54bc44
  1. 4
      apps/explorer_web/test/explorer_web/features/pages/home_page.ex
  2. 60
      apps/explorer_web/test/explorer_web/features/viewing_transactions_test.exs

@ -29,6 +29,10 @@ defmodule ExplorerWeb.HomePage do
css("[data-test='chain_transaction']", count: count) css("[data-test='chain_transaction']", count: count)
end end
def transaction(%Transaction{hash: transaction_hash}) do
css("[data-transaction-hash='#{transaction_hash}']")
end
def transaction_status(%Transaction{hash: transaction_hash}) do def transaction_status(%Transaction{hash: transaction_hash}) do
css("[data-transaction-hash='#{transaction_hash}'] [data-test='transaction_status']") css("[data-transaction-hash='#{transaction_hash}'] [data-test='transaction_status']")
end end

@ -14,9 +14,10 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
gas_used: 123_987 gas_used: 123_987
}) })
4 [oldest_transaction | _] =
|> insert_list(:transaction) 3
|> with_block() |> insert_list(:transaction)
|> with_block()
pending = insert(:transaction, block_hash: nil, gas: 5891, index: nil) pending = insert(:transaction, block_hash: nil, gas: 5891, index: nil)
pending_contract = insert(:transaction, to_address: nil, block_hash: nil, gas: 5891, index: nil) pending_contract = insert(:transaction, to_address: nil, block_hash: nil, gas: 5891, index: nil)
@ -24,7 +25,13 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
lincoln = insert(:address) lincoln = insert(:address)
taft = insert(:address) taft = insert(:address)
transaction = # From Lincoln to Taft.
txn_from_lincoln =
:transaction
|> insert(from_address: lincoln, to_address: taft)
|> with_block(block)
newest_transaction =
:transaction :transaction
|> insert( |> insert(
value: Wei.from(Decimal.new(5656), :ether), value: Wei.from(Decimal.new(5656), :ether),
@ -39,15 +46,9 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
) )
|> with_block(block, gas_used: Decimal.new(1_230_000_000_000_123_000), status: :ok) |> with_block(block, gas_used: Decimal.new(1_230_000_000_000_123_000), status: :ok)
insert(:log, address: lincoln, index: 0, transaction: transaction) insert(:log, address: lincoln, index: 0, transaction: newest_transaction)
# From Lincoln to Taft. internal = insert(:internal_transaction, index: 0, transaction: newest_transaction)
txn_from_lincoln =
:transaction
|> insert(from_address: lincoln, to_address: taft)
|> with_block(block)
internal = insert(:internal_transaction, index: 0, transaction: transaction)
{:ok, {:ok,
%{ %{
@ -56,7 +57,8 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
internal: internal, internal: internal,
lincoln: lincoln, lincoln: lincoln,
taft: taft, taft: taft,
transaction: transaction, first_shown_transaction: newest_transaction,
last_shown_transaction: oldest_transaction,
txn_from_lincoln: txn_from_lincoln txn_from_lincoln: txn_from_lincoln
}} }}
end end
@ -71,12 +73,30 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
end end
describe "viewing transaction lists" do describe "viewing transaction lists" do
test "transactions on the home page", %{session: session} do test "transactions on the homepage", %{session: session} do
session session
|> HomePage.visit_page() |> HomePage.visit_page()
|> assert_has(HomePage.transactions(count: 5)) |> assert_has(HomePage.transactions(count: 5))
end end
test "viewing new transactions via live update on the homepage", %{session: session, last_shown_transaction: last_shown_transaction} do
session
|> HomePage.visit_page()
|> assert_has(HomePage.transactions(count: 5))
transaction =
:transaction
|> insert()
|> with_block()
Notifier.handle_event({:chain_event, :transactions, [transaction.hash]})
session
|> assert_has(HomePage.transactions(count: 5))
|> assert_has(HomePage.transaction(transaction))
|> refute_has(HomePage.transaction(last_shown_transaction))
end
test "contract creation is shown for to_address on home page", %{session: session} do test "contract creation is shown for to_address on home page", %{session: session} do
transaction = transaction =
:transaction :transaction
@ -90,7 +110,7 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> assert_has(HomePage.contract_creation(internal_transaction)) |> assert_has(HomePage.contract_creation(internal_transaction))
end end
test "viewing the default transactions tab", %{session: session, transaction: transaction, pending: pending} do test "viewing the default transactions tab", %{session: session, first_shown_transaction: transaction, pending: pending} do
session session
|> TransactionListPage.visit_page() |> TransactionListPage.visit_page()
|> assert_has(TransactionListPage.transaction(transaction)) |> assert_has(TransactionListPage.transaction(transaction))
@ -122,20 +142,20 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
end end
describe "viewing a transaction page" do describe "viewing a transaction page" do
test "can navigate to transaction show from list page", %{session: session, transaction: transaction} do test "can navigate to transaction show from list page", %{session: session, first_shown_transaction: transaction} do
session session
|> TransactionListPage.visit_page() |> TransactionListPage.visit_page()
|> TransactionListPage.click_transaction(transaction) |> TransactionListPage.click_transaction(transaction)
|> assert_has(TransactionPage.detail_hash(transaction)) |> assert_has(TransactionPage.detail_hash(transaction))
end end
test "can see a transaction's details", %{session: session, transaction: transaction} do test "can see a transaction's details", %{session: session, first_shown_transaction: transaction} do
session session
|> TransactionPage.visit_page(transaction) |> TransactionPage.visit_page(transaction)
|> assert_has(TransactionPage.detail_hash(transaction)) |> assert_has(TransactionPage.detail_hash(transaction))
end end
test "can view a transaction's logs", %{session: session, transaction: transaction} do test "can view a transaction's logs", %{session: session, first_shown_transaction: transaction} do
session session
|> TransactionPage.visit_page(transaction) |> TransactionPage.visit_page(transaction)
|> TransactionPage.click_logs() |> TransactionPage.click_logs()
@ -145,7 +165,7 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
test "can visit an address from the transaction logs page", %{ test "can visit an address from the transaction logs page", %{
lincoln: lincoln, lincoln: lincoln,
session: session, session: session,
transaction: transaction first_shown_transaction: transaction
} do } do
session session
|> TransactionLogsPage.visit_page(transaction) |> TransactionLogsPage.visit_page(transaction)
@ -153,7 +173,7 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> assert_has(AddressPage.detail_hash(lincoln)) |> assert_has(AddressPage.detail_hash(lincoln))
end end
test "block confirmations via live update", %{session: session, transaction: transaction} do test "block confirmations via live update", %{session: session, first_shown_transaction: transaction} do
blocks = [insert(:block, number: transaction.block_number + 10)] blocks = [insert(:block, number: transaction.block_number + 10)]
TransactionPage.visit_page(session, transaction) TransactionPage.visit_page(session, transaction)

Loading…
Cancel
Save