From 6730df5582c381fc584abada72aff666eae42b40 Mon Sep 17 00:00:00 2001 From: Louis Pahlavi Date: Tue, 10 Dec 2024 17:31:12 +0100 Subject: [PATCH] XC-240: Add unit tests for pagination --- rs/ethereum/cketh/minter/src/dashboard.rs | 5 +- .../cketh/minter/src/dashboard/tests.rs | 75 ++++++++++++++++++- .../cketh/minter/templates/dashboard.html | 6 +- .../cketh/minter/templates/pagination.html | 2 +- 4 files changed, 82 insertions(+), 6 deletions(-) diff --git a/rs/ethereum/cketh/minter/src/dashboard.rs b/rs/ethereum/cketh/minter/src/dashboard.rs index 2312578f3bbb..e90d29a6ae23 100644 --- a/rs/ethereum/cketh/minter/src/dashboard.rs +++ b/rs/ethereum/cketh/minter/src/dashboard.rs @@ -245,7 +245,10 @@ impl DashboardTablePagination { let pages = (0..num_items) .step_by(page_size) .enumerate() - .map(|(index, offset)| DashboardTablePage { index, offset }) + .map(|(index, offset)| DashboardTablePage { + index: index + 1, + offset, + }) .collect(); let current_page_index = current_offset / page_size; Self { diff --git a/rs/ethereum/cketh/minter/src/dashboard/tests.rs b/rs/ethereum/cketh/minter/src/dashboard/tests.rs index 2bb84730ae65..59db51175d99 100644 --- a/rs/ethereum/cketh/minter/src/dashboard/tests.rs +++ b/rs/ethereum/cketh/minter/src/dashboard/tests.rs @@ -17,7 +17,7 @@ use ic_cketh_minter::state::transactions::{ create_transaction, Erc20WithdrawalRequest, EthWithdrawalRequest, ReimbursementIndex, WithdrawalRequest, }; -use ic_cketh_minter::state::State; +use ic_cketh_minter::state::{MintedEvent, State}; use ic_cketh_minter::tx::{ Eip1559Signature, Eip1559TransactionRequest, GasFeeEstimate, SignedEip1559TransactionRequest, TransactionPrice, @@ -1001,6 +1001,71 @@ fn should_display_reimbursed_requests() { ); } +#[test] +fn should_display_minted_events_pagination() { + DashboardAssert::assert_that(initial_dashboard()).has_no_elements_matching("#minted-events"); + + let dashboard = { + let mut state = initial_state(); + (0..300).for_each(|index| { + state + .minted_events + .insert(event_source(index), minted_event(index)); + }); + DashboardTemplate::from_state(&state, DashboardPagingParameters::default()) + }; + + DashboardAssert::assert_that(dashboard) + .has_minted_events_last_row(&vec!["Pages:", "1", "2", "3"]); +} + +#[test] +fn should_not_display_minted_events_pagination() { + // todo() +} + +fn minted_event(index: u128) -> MintedEvent { + MintedEvent { + deposit_event: ReceivedEthEvent { + log_index: LogIndex::new(index), + ..received_eth_event() + } + .into(), + mint_block_index: LedgerMintIndex::new(1u64), + token_symbol: "ckETH".to_string(), + erc20_contract_address: None, + } +} + +fn event_source(index: u128) -> EventSource { + EventSource { + transaction_hash: "0x05c6ec45699c9a6a4b1a4ea2058b0cee852ea2f19b18fb8313c04bf8156efde4" + .parse() + .unwrap(), + log_index: LogIndex::new(index), + } +} + +#[test] +fn should_not_display_finalized_transactions_pagination() { + // todo() +} + +#[test] +fn should_display_finalized_transactions_pagination() { + // todo() +} + +#[test] +fn should_not_display_reimbursed_transactions_pagination() { + // todo() +} + +#[test] +fn should_display_reimbursed_transactions_pagination() { + // todo() +} + fn initial_dashboard() -> DashboardTemplate { DashboardTemplate::from_state(&initial_state(), DashboardPagingParameters::default()) } @@ -1483,6 +1548,14 @@ mod assertions { ) } + pub fn has_minted_events_last_row(&self, expected_value: &Vec<&str>) -> &Self { + self.has_table_row_string_value( + "#minted-events + table > tbody > tr:last-child", + expected_value, + "minted-events", + ) + } + pub fn has_rejected_deposits(&self, row_index: u8, expected_value: &Vec<&str>) -> &Self { self.has_table_row_string_value( &format!("#rejected-deposits + table > tbody > tr:nth-child({row_index})"), diff --git a/rs/ethereum/cketh/minter/templates/dashboard.html b/rs/ethereum/cketh/minter/templates/dashboard.html index cbafec33df37..0911bf6cae0d 100644 --- a/rs/ethereum/cketh/minter/templates/dashboard.html +++ b/rs/ethereum/cketh/minter/templates/dashboard.html @@ -281,7 +281,7 @@

Minted events

{{ event.mint_block_index }} {% endfor %} - {% if table.has_more_than_one_page() %}}{{ table.pagination }}{% endif %} + {% if table.has_more_than_one_page() %}}{{ table.pagination|safe }}{% endif %} {% endif %} @@ -389,7 +389,7 @@

Finalized Transactions ckETH → ETH and ckERC20 {{ tx.status }} {% endfor %} - {% if table.has_more_than_one_page() %}}{{ table.pagination }}{% endif %} + {% if table.has_more_than_one_page() %}}{{ table.pagination|safe }}{% endif %} {% endif %} @@ -431,7 +431,7 @@

Reimbursed Transactions

{% endmatch %} {% endfor %} - {% if table.has_more_than_one_page() %}}{{ table.pagination }}{% endif %} + {% if table.has_more_than_one_page() %}}{{ table.pagination|safe }}{% endif %} {% endif %} diff --git a/rs/ethereum/cketh/minter/templates/pagination.html b/rs/ethereum/cketh/minter/templates/pagination.html index b23a0a0b8b17..3f9fe543fc74 100644 --- a/rs/ethereum/cketh/minter/templates/pagination.html +++ b/rs/ethereum/cketh/minter/templates/pagination.html @@ -2,7 +2,7 @@ Pages: {% for page in pages %} - {% if page.index != current_page_index %} + {% if page.index == current_page_index %} {{ page.index }}  {% else %} {{ page.index }}