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)
end
def transaction(%Transaction{hash: transaction_hash}) do
css("[data-transaction-hash='#{transaction_hash}']")
end
def transaction_status(%Transaction{hash: transaction_hash}) do
css("[data-transaction-hash='#{transaction_hash}'] [data-test='transaction_status']")
end

@ -14,9 +14,10 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
gas_used: 123_987
})
4
|> insert_list(:transaction)
|> with_block()
[oldest_transaction | _] =
3
|> insert_list(:transaction)
|> with_block()
pending = insert(:transaction, 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)
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
|> insert(
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)
insert(:log, address: lincoln, index: 0, transaction: transaction)
insert(:log, address: lincoln, index: 0, transaction: newest_transaction)
# From Lincoln to Taft.
txn_from_lincoln =
:transaction
|> insert(from_address: lincoln, to_address: taft)
|> with_block(block)
internal = insert(:internal_transaction, index: 0, transaction: transaction)
internal = insert(:internal_transaction, index: 0, transaction: newest_transaction)
{:ok,
%{
@ -56,7 +57,8 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
internal: internal,
lincoln: lincoln,
taft: taft,
transaction: transaction,
first_shown_transaction: newest_transaction,
last_shown_transaction: oldest_transaction,
txn_from_lincoln: txn_from_lincoln
}}
end
@ -71,12 +73,30 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
end
describe "viewing transaction lists" do
test "transactions on the home page", %{session: session} do
test "transactions on the homepage", %{session: session} do
session
|> HomePage.visit_page()
|> assert_has(HomePage.transactions(count: 5))
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
transaction =
:transaction
@ -90,7 +110,7 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> assert_has(HomePage.contract_creation(internal_transaction))
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
|> TransactionListPage.visit_page()
|> assert_has(TransactionListPage.transaction(transaction))
@ -122,20 +142,20 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
end
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
|> TransactionListPage.visit_page()
|> TransactionListPage.click_transaction(transaction)
|> assert_has(TransactionPage.detail_hash(transaction))
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
|> TransactionPage.visit_page(transaction)
|> assert_has(TransactionPage.detail_hash(transaction))
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
|> TransactionPage.visit_page(transaction)
|> TransactionPage.click_logs()
@ -145,7 +165,7 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
test "can visit an address from the transaction logs page", %{
lincoln: lincoln,
session: session,
transaction: transaction
first_shown_transaction: transaction
} do
session
|> TransactionLogsPage.visit_page(transaction)
@ -153,7 +173,7 @@ defmodule ExplorerWeb.ViewingTransactionsTest do
|> assert_has(AddressPage.detail_hash(lincoln))
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)]
TransactionPage.visit_page(session, transaction)

Loading…
Cancel
Save