diff --git a/src/components/AccountAddress.tsx b/src/components/AccountAddress.tsx index b7f49b35..6299c26f 100644 --- a/src/components/AccountAddress.tsx +++ b/src/components/AccountAddress.tsx @@ -3,6 +3,7 @@ import { useMemo } from "react"; import { Tooltip } from "@mui/material"; import { css } from "@emotion/react"; +import { Network } from "../model/network"; import { encodeAddress } from "../utils/formatAddress"; import { shortenHash } from "../utils/shortenHash"; @@ -24,9 +25,8 @@ const copyToClipboardStyle = css` `; export type AccountLinkProps = { - network: string; + network: Network; address: string; - prefix: number; icon?: boolean; link?: boolean; shorten?: boolean; @@ -37,21 +37,20 @@ export const AccountAddress = (props: AccountLinkProps) => { const { network, address, - prefix, icon = true, link = true, shorten, copyToClipboard } = props; - const encodedAddress = useMemo(() => encodeAddress(address, prefix), [address]); + const encodedAddress = useMemo(() => encodeAddress(address, network.prefix), [address]); const content = useMemo(() => { let content = {shorten ? shortenHash(encodedAddress) : encodedAddress}; if (link) { content = ( - + {content} ); @@ -83,7 +82,7 @@ export const AccountAddress = (props: AccountLinkProps) => { )} diff --git a/src/components/DataViewer.tsx b/src/components/DataViewer.tsx index c38a45d2..520e11f4 100644 --- a/src/components/DataViewer.tsx +++ b/src/components/DataViewer.tsx @@ -7,6 +7,7 @@ import { Close } from "@mui/icons-material"; import { config } from "../config"; import { DecodedArg } from "../model/decodedMetadata"; +import { Network } from "../model/network"; import { RuntimeSpec } from "../model/runtimeSpec"; import CopyToClipboardButton from "./CopyToClipboardButton"; @@ -203,7 +204,7 @@ const DataViewerModalHandle = (props: DataViewerModalHandleProps) => { }; export type DataViewerProps = { - network: string; + network: Network; data: any; metadata?: DecodedArg[]; runtimeSpec?: RuntimeSpec; diff --git a/src/components/DataViewerValueParsed.tsx b/src/components/DataViewerValueParsed.tsx index 50dbac91..1e40d076 100644 --- a/src/components/DataViewerValueParsed.tsx +++ b/src/components/DataViewerValueParsed.tsx @@ -7,6 +7,7 @@ import { noCase } from "../utils/string"; import { AccountAddress } from "./AccountAddress"; import { RuntimeSpec } from "../model/runtimeSpec"; +import { Network } from "../model/network"; // found in https://github.com/polkadot-js/apps/blob/59c2badf87c29fd8cb5b7dfcc045c3ce451a54bc/packages/react-params/src/Param/findComponent.ts#L51 const ADDRESS_TYPES = ["AccountId", "AccountId20", "AccountId32", "Address", "LookupSource", "MultiAddress"]; @@ -72,7 +73,7 @@ const valueStyle = css` `; type ValueOfKindProps = { - network: string; + network: Network; value: { __kind: string, value: any; @@ -111,7 +112,7 @@ const ValueOfKind = (props: ValueOfKindProps) => { }; type MaybeAccountLinkValueProps = { - network: string; + network: Network; value: any; valueMetadata: DecodedArg; runtimeSpec: RuntimeSpec; @@ -147,7 +148,6 @@ const AccountValue = (props: MaybeAccountLinkValueProps) => { @@ -155,7 +155,7 @@ const AccountValue = (props: MaybeAccountLinkValueProps) => { }; export type DataViewerValueParsedProps = { - network: string; + network: Network; value: any; metadata?: DecodedArg[]|DecodedArg; runtimeSpec?: RuntimeSpec; diff --git a/src/components/account/AccountBalancesTable.tsx b/src/components/account/AccountBalancesTable.tsx index 1c9880c4..f00a2ee8 100644 --- a/src/components/account/AccountBalancesTable.tsx +++ b/src/components/account/AccountBalancesTable.tsx @@ -144,8 +144,7 @@ export const AccountBalancesTable = (props: AccountBalanceOverview) => {
& { - network: string; + network: Network; account: Resource; } @@ -19,8 +19,6 @@ const AccountInfoTableAttribute = InfoTableAttribute; export const AccountInfoTable = (props: AccountInfoTableProps) => { const {network, account, ...tableProps} = props; - const networkData = useNetwork(network); - return ( { {...tableProps} > encodeAddress(data.address, data.runtimeSpec.metadata.ss58Prefix)} - copyToClipboard={(data) => encodeAddress(data.address, data.runtimeSpec.metadata.ss58Prefix)} + label={`${network.displayName} address`} + render={(data) => encodeAddress(data.address, network.prefix)} + copyToClipboard={(data) => encodeAddress(data.address, network.prefix)} hide={(data) => isEthereumAddress(data.address)} /> ; usdRates: Resource; }; @@ -37,7 +38,6 @@ function BalancesTable(props: BalancesTableProps) { } @@ -48,9 +48,9 @@ function BalancesTable(props: BalancesTableProps) { render={(balance, usdRates) => @@ -62,9 +62,9 @@ function BalancesTable(props: BalancesTableProps) { render={(balance, usdRates) => @@ -76,9 +76,9 @@ function BalancesTable(props: BalancesTableProps) { render={(balance, usdRates) => @@ -88,7 +88,7 @@ function BalancesTable(props: BalancesTableProps) { - + {balance.updatedAtBlock} } diff --git a/src/components/blocks/BlockInfoTable.tsx b/src/components/blocks/BlockInfoTable.tsx index d2224569..163b12ef 100644 --- a/src/components/blocks/BlockInfoTable.tsx +++ b/src/components/blocks/BlockInfoTable.tsx @@ -1,4 +1,5 @@ import { Block } from "../../model/block"; +import { Network } from "../../model/network"; import { Resource } from "../../model/resource"; import { encodeAddress } from "../../utils/formatAddress"; @@ -8,7 +9,7 @@ import { Link } from "../Link"; import { Time } from "../Time"; export type BlockInfoTableProps = { - network: string; + network: Network; block: Resource; } @@ -51,7 +52,7 @@ export const BlockInfoTable = (props: BlockInfoTableProps) => { - + {data.parentHash} } @@ -63,13 +64,12 @@ export const BlockInfoTable = (props: BlockInfoTableProps) => { } copyToClipboard={(data) => data.validator && encodeAddress( data.validator, - data.runtimeSpec.metadata.ss58Prefix + network.prefix ) } hide={(data) => !data.validator} diff --git a/src/components/blocks/BlocksTable.tsx b/src/components/blocks/BlocksTable.tsx index 55f227ef..b1ca1e52 100644 --- a/src/components/blocks/BlocksTable.tsx +++ b/src/components/blocks/BlocksTable.tsx @@ -1,4 +1,5 @@ import { Block } from "../../model/block"; +import { Network } from "../../model/network"; import { PaginatedResource } from "../../model/paginatedResource"; import { AccountAddress } from "../AccountAddress"; @@ -7,7 +8,7 @@ import { Link } from "../Link"; import { Time } from "../Time"; export type BlocksTableProps = { - network: string; + network: Network; blocks: PaginatedResource, showValidator: boolean, showTime?: boolean; @@ -36,7 +37,7 @@ function ExtrinsicsTable(props: BlocksTableProps) { - + {block.height} } @@ -56,7 +57,6 @@ function ExtrinsicsTable(props: BlocksTableProps) { diff --git a/src/components/calls/CallInfoTable.tsx b/src/components/calls/CallInfoTable.tsx index 85cb8acf..e01b53c5 100644 --- a/src/components/calls/CallInfoTable.tsx +++ b/src/components/calls/CallInfoTable.tsx @@ -4,6 +4,7 @@ import CrossIcon from "../../assets/cross-icon.png"; import CheckIcon from "../../assets/check-icon.png"; import { Call } from "../../model/call"; +import { Network } from "../../model/network"; import { Resource } from "../../model/resource"; import { encodeAddress } from "../../utils/formatAddress"; @@ -17,7 +18,7 @@ import { Link } from "../Link"; import { Time } from "../Time"; export type CallInfoTableProps = { - network: string; + network: Network; call: Resource; } @@ -49,7 +50,7 @@ export const CallInfoTable = (props: CallInfoTableProps) => { - + {data.blockHeight} } @@ -58,7 +59,7 @@ export const CallInfoTable = (props: CallInfoTableProps) => { - + {data.extrinsicId} } @@ -67,7 +68,7 @@ export const CallInfoTable = (props: CallInfoTableProps) => { data.parentId && - + {data.parentId} } @@ -80,11 +81,10 @@ export const CallInfoTable = (props: CallInfoTableProps) => { } copyToClipboard={(data) => data.caller && - encodeAddress(data.caller, data.runtimeSpec.metadata.ss58Prefix) + encodeAddress(data.caller, network.prefix) } hide={(data) => !data.caller} /> @@ -102,7 +102,7 @@ export const CallInfoTable = (props: CallInfoTableProps) => { label="Name" render={(data) => diff --git a/src/components/calls/CallsTable.tsx b/src/components/calls/CallsTable.tsx index 594ec69b..8ff2c626 100644 --- a/src/components/calls/CallsTable.tsx +++ b/src/components/calls/CallsTable.tsx @@ -1,12 +1,14 @@ import { Call } from "../../model/call"; +import { Network } from "../../model/network"; import { PaginatedResource } from "../../model/paginatedResource"; + import { AccountAddress } from "../AccountAddress"; import { ButtonLink } from "../ButtonLink"; import { ItemsTable, ItemsTableAttribute } from "../ItemsTable"; import { Link } from "../Link"; export type CallsTableProps = { - network: string; + network: Network; calls: PaginatedResource; showAccount?: boolean; }; @@ -29,7 +31,7 @@ export const CallsTable = (props: CallsTableProps) => { - + {call.id} } @@ -38,7 +40,7 @@ export const CallsTable = (props: CallsTableProps) => { label="Name" render={(call) => @@ -53,7 +55,6 @@ export const CallsTable = (props: CallsTableProps) => { @@ -63,7 +64,7 @@ export const CallsTable = (props: CallsTableProps) => { - + {call.extrinsicId} } diff --git a/src/components/events/EventInfoTable.tsx b/src/components/events/EventInfoTable.tsx index b23cbebe..b6e20e5b 100644 --- a/src/components/events/EventInfoTable.tsx +++ b/src/components/events/EventInfoTable.tsx @@ -1,4 +1,5 @@ import { Event } from "../../model/event"; +import { Network } from "../../model/network"; import { Resource } from "../../model/resource"; import { getEventMetadataByName } from "../../utils/queryMetadata"; @@ -9,7 +10,7 @@ import { Link } from "../Link"; import { Time } from "../Time"; export type EventInfoTableProps = { - network: string; + network: Network; event: Resource; } @@ -42,7 +43,7 @@ export const EventInfoTable = (props: EventInfoTableProps) => { label="Block" render={(data) => {data.blockHeight} @@ -53,7 +54,7 @@ export const EventInfoTable = (props: EventInfoTableProps) => { label="Extrinsic" render={(data) => data.extrinsicId && {data.extrinsicId} @@ -64,7 +65,7 @@ export const EventInfoTable = (props: EventInfoTableProps) => { label="Call" render={(data) => data.callId && {data.callId} @@ -75,7 +76,7 @@ export const EventInfoTable = (props: EventInfoTableProps) => { label="Name" render={(data) => diff --git a/src/components/events/EventsTable.tsx b/src/components/events/EventsTable.tsx index 8ad08fd5..80ce08a3 100644 --- a/src/components/events/EventsTable.tsx +++ b/src/components/events/EventsTable.tsx @@ -2,6 +2,7 @@ import { css } from "@emotion/react"; import { Event } from "../../model/event"; +import { Network } from "../../model/network"; import { PaginatedResource } from "../../model/paginatedResource"; import { getEventMetadataByName } from "../../utils/queryMetadata"; @@ -16,7 +17,7 @@ const parametersColCss = (showExtrinsic?: boolean) => css` `; export type EventsTableProps = { - network: string; + network: Network; events: PaginatedResource; showExtrinsic?: boolean; }; @@ -39,7 +40,7 @@ function EventsTable(props: EventsTableProps) { ( - + {event.id} )} @@ -48,7 +49,7 @@ function EventsTable(props: EventsTableProps) { label="Name" render={(event) => @@ -60,7 +61,7 @@ function EventsTable(props: EventsTableProps) { event.extrinsicId && ( - + {event.extrinsicId} )} diff --git a/src/components/extrinsics/ExtrinsicInfoTable.tsx b/src/components/extrinsics/ExtrinsicInfoTable.tsx index f241579b..5f0a2ee2 100644 --- a/src/components/extrinsics/ExtrinsicInfoTable.tsx +++ b/src/components/extrinsics/ExtrinsicInfoTable.tsx @@ -4,6 +4,7 @@ import CrossIcon from "../../assets/cross-icon.png"; import CheckIcon from "../../assets/check-icon.png"; import { Extrinsic } from "../../model/extrinsic"; +import { Network } from "../../model/network"; import { Resource } from "../../model/resource"; import { encodeAddress } from "../../utils/formatAddress"; @@ -17,7 +18,7 @@ import { Link } from "../Link"; import { Time } from "../Time"; export type ExtrinsicInfoTableProps = { - network: string; + network: Network; extrinsic: Resource; } @@ -54,7 +55,7 @@ export const ExtrinsicInfoTable = (props: ExtrinsicInfoTableProps) => { - + {data.blockHeight} } @@ -66,11 +67,10 @@ export const ExtrinsicInfoTable = (props: ExtrinsicInfoTableProps) => { } copyToClipboard={(data) => data.signer && - encodeAddress(data.signer, data.runtimeSpec.metadata.ss58Prefix) + encodeAddress(data.signer, network.prefix) } hide={(data) => !data.signer} /> @@ -88,7 +88,7 @@ export const ExtrinsicInfoTable = (props: ExtrinsicInfoTableProps) => { label="Name" render={(data) => diff --git a/src/components/extrinsics/ExtrinsicsTable.tsx b/src/components/extrinsics/ExtrinsicsTable.tsx index 86e31672..132c95b4 100644 --- a/src/components/extrinsics/ExtrinsicsTable.tsx +++ b/src/components/extrinsics/ExtrinsicsTable.tsx @@ -1,4 +1,5 @@ import { Extrinsic } from "../../model/extrinsic"; +import { Network } from "../../model/network"; import { PaginatedResource } from "../../model/paginatedResource"; import { AccountAddress } from "../AccountAddress"; @@ -8,7 +9,7 @@ import { Link } from "../Link"; import { Time } from "../Time"; export type ExtrinsicsTableProps = { - network: string; + network: Network; extrinsics: PaginatedResource, showAccount?: boolean; showTime?: boolean; @@ -62,7 +63,6 @@ function ExtrinsicsTable(props: ExtrinsicsTableProps) { diff --git a/src/components/network/NetworkStats.tsx b/src/components/network/NetworkStats.tsx index a7fc5e82..f9ea3e07 100644 --- a/src/components/network/NetworkStats.tsx +++ b/src/components/network/NetworkStats.tsx @@ -10,11 +10,11 @@ import StakingReward from "../../assets/staking-reward.svg"; import { Resource } from "../../model/resource"; import { Stats } from "../../model/stats"; -import { getNetwork } from "../../services/networksService"; import { ErrorMessage } from "../ErrorMessage"; import Loading from "../Loading"; import NotFound from "../NotFound"; +import { Network } from "../../model/network"; const statStyle = css` min-width: 100px; @@ -80,14 +80,12 @@ const StatItem = (props: StatItemProps) => { }; export type NetworkInfoTableProps = { + network: Network; stats: Resource; - networkName: string; } export const NetworkStats = (props: NetworkInfoTableProps) => { - const { stats, networkName } = props; - - const network = getNetwork(networkName); + const { stats, network } = props; if (stats.loading) { return ; diff --git a/src/components/transfers/TransfersTable.tsx b/src/components/transfers/TransfersTable.tsx index d17582ce..59caea3b 100644 --- a/src/components/transfers/TransfersTable.tsx +++ b/src/components/transfers/TransfersTable.tsx @@ -5,7 +5,7 @@ import CheckIcon from "../../assets/check-icon.png"; import { PaginatedResource } from "../../model/paginatedResource"; import { Transfer } from "../../model/transfer"; -import { getNetwork } from "../../services/networksService"; +import { Network } from "../../model/network"; import { AccountAddress } from "../AccountAddress"; import { Currency } from "../Currency"; @@ -14,7 +14,7 @@ import { Link } from "../Link"; import { Time } from "../Time"; export type TransfersTableProps = { - network: string; + network: Network; transfers: PaginatedResource, showTime?: boolean; }; @@ -43,7 +43,7 @@ function TransfersTable(props: TransfersTableProps) { transfer.extrinsic && - + {transfer.extrinsic.id} } @@ -54,7 +54,6 @@ function TransfersTable(props: TransfersTableProps) { @@ -66,7 +65,6 @@ function TransfersTable(props: TransfersTableProps) { @@ -77,7 +75,7 @@ function TransfersTable(props: TransfersTableProps) { render={(transfer) => diff --git a/src/screens/account.tsx b/src/screens/account.tsx index 60984088..a8032468 100644 --- a/src/screens/account.tsx +++ b/src/screens/account.tsx @@ -119,7 +119,7 @@ export const AccountPage = () => { { error={extrinsics.error} value="extrinsics" > - + {hasSupport(network.name, "explorer-squid") && { error={calls.error} value="calls" > - + } {hasSupport(network.name, "main-squid") && @@ -185,7 +185,7 @@ export const AccountPage = () => { error={transfers.error} value="transfers" > - + } diff --git a/src/screens/block.tsx b/src/screens/block.tsx index 3cb1779f..3138e0cd 100644 --- a/src/screens/block.tsx +++ b/src/screens/block.tsx @@ -46,7 +46,7 @@ export const BlockPage = () => { @@ -60,7 +60,7 @@ export const BlockPage = () => { error={extrinsics.error} value="extrinsics" > - + { error={calls.error} value="calls" > - + { error={events.error} value="events" > - + diff --git a/src/screens/call.tsx b/src/screens/call.tsx index ce4a5e2a..cb0fafeb 100644 --- a/src/screens/call.tsx +++ b/src/screens/call.tsx @@ -30,7 +30,7 @@ export const CallPage = () => { Call #{id} - + {call.data && @@ -42,7 +42,7 @@ export const CallPage = () => { error={events.error} value="events" > - + diff --git a/src/screens/event.tsx b/src/screens/event.tsx index 175c4e50..66c277c1 100644 --- a/src/screens/event.tsx +++ b/src/screens/event.tsx @@ -25,7 +25,7 @@ export const EventPage = () => { Event #{id} - + ); }; diff --git a/src/screens/extrinsic.tsx b/src/screens/extrinsic.tsx index 9d83889d..ced81bdc 100644 --- a/src/screens/extrinsic.tsx +++ b/src/screens/extrinsic.tsx @@ -35,7 +35,7 @@ export const ExtrinsicPage = () => { @@ -50,7 +50,7 @@ export const ExtrinsicPage = () => { value="events" > @@ -61,7 +61,7 @@ export const ExtrinsicPage = () => { error={calls.error} value="calls" > - + diff --git a/src/screens/network.tsx b/src/screens/network.tsx index 55855592..703fd422 100644 --- a/src/screens/network.tsx +++ b/src/screens/network.tsx @@ -59,17 +59,17 @@ export const NetworkPage = () => { return ( <> - + {network.displayName} {hasSupport(network.name, "stats-squid") && - + } {hasSupport(network.name, "stats-squid") && - + Token distribution @@ -82,7 +82,7 @@ export const NetworkPage = () => { - + { error={extrinsics.error} value="extrinsics" > - + { error={blocks.error} value="blocks" > - + @@ -112,7 +112,7 @@ export const NetworkPage = () => { error={transfers.error} value="transfers" > - + } {hasSupport(network.name, "stats-squid") && @@ -123,7 +123,7 @@ export const NetworkPage = () => { error={topHolders.error} value="top-holders" > - + } diff --git a/src/screens/search.tsx b/src/screens/search.tsx index 05c198e3..3edeb68b 100644 --- a/src/screens/search.tsx +++ b/src/screens/search.tsx @@ -147,7 +147,7 @@ export const SearchPage = () => { error={extrinsicsByName.error} value="extrinsics" > - + } {!eventsByName.notFound && @@ -158,7 +158,7 @@ export const SearchPage = () => { error={eventsByName.error} value="events" > - + } diff --git a/test/e2e/account.spec.ts b/test/e2e/account.spec.ts index 251f5649..95de201c 100644 --- a/test/e2e/account.spec.ts +++ b/test/e2e/account.spec.ts @@ -189,7 +189,9 @@ test.describe("Account detail page", () => { await page.getByTestId("extrinsics-tab").click(); await removeContent(page.locator("[data-test=extrinsics-table] tr td")); - await takeScreenshot("account-with-extrinsics"); + + const accountRelatedItems = page.getByTestId("account-related-items"); + await takeScreenshot("account-with-extrinsics", accountRelatedItems); }); test("shows account detail page with calls", async ({ page, takeScreenshot }) => { @@ -198,7 +200,9 @@ test.describe("Account detail page", () => { await page.getByTestId("calls-tab").click(); await removeContent(page.locator("[data-test=calls-table] tr td")); - await takeScreenshot("account-with-calls"); + + const accountRelatedItems = page.getByTestId("account-related-items"); + await takeScreenshot("account-with-calls", accountRelatedItems); }); test("shows account detail page with transfers", async ({ page, takeScreenshot }) => { @@ -207,7 +211,9 @@ test.describe("Account detail page", () => { await page.getByTestId("transfers-tab").click(); await removeContent(page.locator("[data-test=transfers-table] tr td")); - await takeScreenshot("account-with-transfers"); + + const accountRelatedItems = page.getByTestId("account-related-items"); + await takeScreenshot("account-with-transfers", accountRelatedItems); }); test("shows error message if account address is not valid", async ({ page, takeScreenshot }) => { @@ -261,7 +267,8 @@ test.describe("Account detail page", () => { await expect(errorMessage).toHaveText(/Unexpected error/); await expect(errorMessage).toHaveText(/Extrinsics error/); - await takeScreenshot("account-with-extrinsics-error"); + const accountRelatedItems = page.getByTestId("account-related-items"); + await takeScreenshot("account-with-extrinsics-error", accountRelatedItems); }); test("shows error message when calls items fetch fails", async ({ page, takeScreenshot }) => { @@ -287,7 +294,8 @@ test.describe("Account detail page", () => { await expect(errorMessage).toHaveText(/Unexpected error/); await expect(errorMessage).toHaveText(/Calls error/); - await takeScreenshot("account-with-calls-error"); + const accountRelatedItems = page.getByTestId("account-related-items"); + await takeScreenshot("account-with-calls-error", accountRelatedItems); }); test("shows error message when transfers items fetch fails", async ({ page, takeScreenshot }) => { @@ -313,6 +321,7 @@ test.describe("Account detail page", () => { await expect(errorMessage).toHaveText(/Unexpected error/); await expect(errorMessage).toHaveText(/Transfers error/); - await takeScreenshot("account-with-transfers-error"); + const accountRelatedItems = page.getByTestId("account-related-items"); + await takeScreenshot("account-with-transfers-error", accountRelatedItems); }); }); diff --git a/test/e2e/network.fixture.json b/test/e2e/network.fixture.json new file mode 100644 index 00000000..d93811c7 --- /dev/null +++ b/test/e2e/network.fixture.json @@ -0,0 +1,22 @@ +{ + "stats": { + "data": { + "currents": [ + { + "chainFinalizedBlocks": "17041967", + "nominationPoolsMembersAmount": 14111, + "nominationPoolsPoolsActiveTotalStake": "66052692450108600", + "chainSignedExtrinsics": "13401862", + "stakingTotalStake": "6578430208558741725", + "balancesTotalIssuance": "13496997352396268589", + "balancesTransfersAmount": "11156384", + "stakingActiveValidatorsAmount": 297, + "stakingValidatorsIdealAmount": 297, + "stakingInflationRatio": 7.373995331554838, + "stakingRewardsRatio": 15.129262196487339, + "nominationPoolsPoolsActiveAmount": 137 + } + ] + } + } +} diff --git a/test/e2e/chainDashboard.spec.ts b/test/e2e/network.spec.ts similarity index 65% rename from test/e2e/chainDashboard.spec.ts rename to test/e2e/network.spec.ts index 0922b0f6..02888e83 100644 --- a/test/e2e/chainDashboard.spec.ts +++ b/test/e2e/network.spec.ts @@ -3,21 +3,52 @@ import { navigate } from "../utils/navigate"; import { removeContent } from "../utils/removeContent"; import { test, expect } from "../utils/test"; +import fixtures from "./network.fixture.json"; -test.describe("Chain dashboard page", () => { +test.describe("Network page", () => { + + test.beforeEach(async ({ page }) => { + await page.route("**/*", (route, request) => { + + if (request.url().match("gs-stats-polkadot") && request.postDataJSON()?.query.match("currents")) { + return route.fulfill({ + status: 200, + body: JSON.stringify(fixtures.stats) + }); + } + + route.continue(); + }); + }); test("redirects to /:network", async ({ page, takeScreenshot }) => { - await navigate(page, "/kusama/latest-extrinsics", {waitUntil: "data-loaded"}); - await page.waitForURL(/\/kusama/); + await navigate(page, "/polkadot/latest-extrinsics", {waitUntil: "data-loaded"}); + await page.waitForURL(/\/polkadot/); + }); + + test("shows stats", async ({ page, takeScreenshot }) => { + await navigate(page, "/polkadot", {waitUntil: "data-loaded"}); + + const stats = page.getByTestId("network-stats"); + await takeScreenshot("network-stats", stats); + }); + + test("shows token distribution", async ({ page, takeScreenshot }) => { + await navigate(page, "/polkadot", {waitUntil: "data-loaded"}); + + const tokenDistribution = page.getByTestId("network-token-distribution"); + await takeScreenshot("network-stats", tokenDistribution); }); test("shows latest extrinsics tab", async ({ page, takeScreenshot }) => { await navigate(page, "/polkadot", {waitUntil: "data-loaded"}); await page.getByTestId("extrinsics-tab").click(); - + await removeContent(page.locator("[data-test=extrinsics-table] tr td")); - await takeScreenshot("chain-dashboard-latest-extrinsics"); + + const relatedItems = page.getByTestId("network-related-items"); + await takeScreenshot("network-latest-extrinsics", relatedItems); }); test("shows latest blocks tab", async ({ page, takeScreenshot }) => { @@ -26,7 +57,9 @@ test.describe("Chain dashboard page", () => { await page.getByTestId("blocks-tab").click(); await removeContent(page.locator("[data-test=blocks-table] tr td")); - await takeScreenshot("chain-dashboard-latest-blocks"); + + const relatedItems = page.getByTestId("network-related-items"); + await takeScreenshot("network-latest-blocks", relatedItems); }); test("shows latest transfers tab", async ({ page, takeScreenshot }) => { @@ -35,7 +68,9 @@ test.describe("Chain dashboard page", () => { await page.getByTestId("transfers-tab").click(); await removeContent(page.locator("[data-test=transfers-table] tr td")); - await takeScreenshot("chain-dashboard-latest-transfers"); + + const relatedItems = page.getByTestId("network-related-items"); + await takeScreenshot("network-latest-transfers", relatedItems); }); test("shows top holders tab", async ({ page, takeScreenshot }) => { @@ -44,7 +79,9 @@ test.describe("Chain dashboard page", () => { await page.getByTestId("top-holders-tab").click(); await removeContent(page.locator("[data-test=balances-table] tr td")); - await takeScreenshot("chain-dashboard-top-holders"); + + const relatedItems = page.getByTestId("network-related-items"); + await takeScreenshot("network-top-holders", relatedItems); }); test("show error message when extrinsics items fetch fails", async ({ page, takeScreenshot }) => { @@ -68,7 +105,8 @@ test.describe("Chain dashboard page", () => { await expect(errorMessage).toHaveText(/Unexpected error/); await expect(errorMessage).toHaveText(/Extrinsics error/); - await takeScreenshot("chain-dashboard-latest-extrinsics-error"); + const relatedItems = page.getByTestId("network-related-items"); + await takeScreenshot("network-latest-extrinsics-error", relatedItems); }); test("show error message when blocks items fetch fails", async ({ page, takeScreenshot }) => { @@ -88,13 +126,14 @@ test.describe("Chain dashboard page", () => { await navigate(page, "/polkadot", {waitUntil: "data-loaded"}); await page.getByTestId("blocks-tab").click(); - + const errorMessage = page.getByTestId("error"); await expect(errorMessage).toBeVisible(); await expect(errorMessage).toHaveText(/Unexpected error/); await expect(errorMessage).toHaveText(/Blocks error/); - await takeScreenshot("chain-dashboard-latest-blocks-error"); + const relatedItems = page.getByTestId("network-related-items"); + await takeScreenshot("network-latest-blocks-error", relatedItems); }); test("show error message when transfers items fetch fails", async ({ page, takeScreenshot }) => { @@ -114,13 +153,14 @@ test.describe("Chain dashboard page", () => { await navigate(page, "/polkadot", {waitUntil: "data-loaded"}); await page.getByTestId("transfers-tab").click(); - + const errorMessage = page.getByTestId("error"); await expect(errorMessage).toBeVisible(); await expect(errorMessage).toHaveText(/Unexpected error/); await expect(errorMessage).toHaveText(/Transfers error/); - await takeScreenshot("chain-dashboard-latest-transfers-error"); + const relatedItems = page.getByTestId("network-related-items"); + await takeScreenshot("network-latest-transfers-error", relatedItems); }); test("show error message when top holders items fetch fails", async ({ page, takeScreenshot }) => { @@ -140,13 +180,14 @@ test.describe("Chain dashboard page", () => { await navigate(page, "/polkadot", {waitUntil: "data-loaded"}); await page.getByTestId("top-holders-tab").click(); - + const errorMessage = page.getByTestId("error"); await expect(errorMessage).toBeVisible(); await expect(errorMessage).toHaveText(/Unexpected error/); await expect(errorMessage).toHaveText(/Top holders error/); - await takeScreenshot("chain-dashboard-top-holders-error"); + const relatedItems = page.getByTestId("network-related-items"); + await takeScreenshot("network-top-holders-error", relatedItems); }); });