diff --git a/apps/block_scout_web/test/block_scout_web/features/pages/block_page.ex b/apps/block_scout_web/test/block_scout_web/features/pages/block_page.ex index 2da3c3637e..8d4b14157b 100644 --- a/apps/block_scout_web/test/block_scout_web/features/pages/block_page.ex +++ b/apps/block_scout_web/test/block_scout_web/features/pages/block_page.ex @@ -1,10 +1,8 @@ defmodule BlockScoutWeb.BlockPage do @moduledoc false - use Phoenix.ConnTest use Wallaby.DSL - import BlockScoutWeb.Router.Helpers import Wallaby.Query, only: [css: 1, css: 2] alias Explorer.Chain.{Block, InternalTransaction, Transaction} @@ -41,8 +39,11 @@ defmodule BlockScoutWeb.BlockPage do css("[data-test='uncle_link'][data-uncle-hash='#{hash}']") end - def visit_page(session, %Block{} = block) do - path = block_path(build_conn(), :show, block) - visit(session, path) + def visit_page(session, %Block{number: block_number, consensus: true}) do + visit(session, "/blocks/#{block_number}") + end + + def visit_page(session, %Block{hash: hash}) do + visit(session, "/blocks/#{hash}") end end diff --git a/apps/block_scout_web/test/block_scout_web/features/viewing_blocks_test.exs b/apps/block_scout_web/test/block_scout_web/features/viewing_blocks_test.exs index c325e14fbd..4dff2a36ee 100644 --- a/apps/block_scout_web/test/block_scout_web/features/viewing_blocks_test.exs +++ b/apps/block_scout_web/test/block_scout_web/features/viewing_blocks_test.exs @@ -20,12 +20,6 @@ defmodule BlockScoutWeb.ViewingBlocksTest do {:ok, first_shown_block: newest_block, last_shown_block: oldest_block} end - test "viewing the blocks index page", %{first_shown_block: block, session: session} do - session - |> BlockListPage.visit_page() - |> assert_has(BlockListPage.block(block)) - end - describe "block details page" do test "show block detail page", %{session: session} do block = insert(:block, number: 42) @@ -36,35 +30,6 @@ defmodule BlockScoutWeb.ViewingBlocksTest do |> assert_has(BlockPage.page_type("Block Details")) end - test "inserts place holder blocks if out of order block received", %{session: session} do - BlockListPage.visit_page(session) - - block = insert(:block, number: 315) - Notifier.handle_event({:chain_event, :blocks, :realtime, [block]}) - - session - |> assert_has(BlockListPage.block(block)) - |> assert_has(BlockListPage.place_holder_blocks(3)) - end - - test "replaces place holder block if skipped block received", %{session: session} do - BlockListPage.visit_page(session) - - block = insert(:block, number: 315) - Notifier.handle_event({:chain_event, :blocks, :realtime, [block]}) - - session - |> assert_has(BlockListPage.block(block)) - |> assert_has(BlockListPage.place_holder_blocks(3)) - - skipped_block = insert(:block, number: 314) - Notifier.handle_event({:chain_event, :blocks, :realtime, [skipped_block]}) - - session - |> assert_has(BlockListPage.block(skipped_block)) - |> assert_has(BlockListPage.place_holder_blocks(2)) - end - test "block detail page has transactions", %{session: session} do block = insert(:block, number: 42) @@ -127,6 +92,15 @@ defmodule BlockScoutWeb.ViewingBlocksTest do |> assert_has(BlockPage.token_transfers(transaction, count: 3)) end + test "show reorg detail page", %{session: session} do + reorg = insert(:block, consensus: false) + + session + |> BlockPage.visit_page(reorg) + |> assert_has(BlockPage.detail_number(reorg)) + |> assert_has(BlockPage.page_type("Reorg Details")) + end + test "show uncle detail page", %{session: session} do uncle = insert(:block, consensus: false) insert(:block_second_degree_relation, uncle_hash: uncle.hash) @@ -150,14 +124,40 @@ defmodule BlockScoutWeb.ViewingBlocksTest do end end - describe "viewing reorg blocks list" do - test "lists uncle blocks", %{session: session} do - [reorg | _] = insert_list(10, :block, consensus: false) + describe "viewing blocks list" do + test "viewing the blocks index page", %{first_shown_block: block, session: session} do + session + |> BlockListPage.visit_page() + |> assert_has(BlockListPage.block(block)) + end + + test "inserts place holder blocks if out of order block received", %{session: session} do + BlockListPage.visit_page(session) + + block = insert(:block, number: 315) + Notifier.handle_event({:chain_event, :blocks, :realtime, [block]}) session - |> BlockListPage.visit_reorgs_page() - |> assert_has(BlockListPage.block(reorg)) - |> assert_has(BlockListPage.blocks(10)) + |> assert_has(BlockListPage.block(block)) + |> assert_has(BlockListPage.place_holder_blocks(3)) + end + + test "replaces place holder block if skipped block received", %{session: session} do + BlockListPage.visit_page(session) + + block = insert(:block, number: 315) + Notifier.handle_event({:chain_event, :blocks, :realtime, [block]}) + + session + |> assert_has(BlockListPage.block(block)) + |> assert_has(BlockListPage.place_holder_blocks(3)) + + skipped_block = insert(:block, number: 314) + Notifier.handle_event({:chain_event, :blocks, :realtime, [skipped_block]}) + + session + |> assert_has(BlockListPage.block(skipped_block)) + |> assert_has(BlockListPage.place_holder_blocks(2)) end end @@ -185,4 +185,15 @@ defmodule BlockScoutWeb.ViewingBlocksTest do |> assert_has(BlockListPage.blocks(10)) end end + + describe "viewing reorg blocks list" do + test "lists uncle blocks", %{session: session} do + [reorg | _] = insert_list(10, :block, consensus: false) + + session + |> BlockListPage.visit_reorgs_page() + |> assert_has(BlockListPage.block(reorg)) + |> assert_has(BlockListPage.blocks(10)) + end + end end