Skip to content

Commit

Permalink
XC-240: Add unit tests for pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
lpahlavi committed Dec 10, 2024
1 parent 1d4b2d4 commit 6730df5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
5 changes: 4 additions & 1 deletion rs/ethereum/cketh/minter/src/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
75 changes: 74 additions & 1 deletion rs/ethereum/cketh/minter/src/dashboard/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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})"),
Expand Down
6 changes: 3 additions & 3 deletions rs/ethereum/cketh/minter/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ <h3 id="minted-events">Minted events</h3>
<td class="numeric">{{ event.mint_block_index }}</td>
</tr>
{% endfor %}
{% if table.has_more_than_one_page() %}}{{ table.pagination }}{% endif %}
{% if table.has_more_than_one_page() %}}{{ table.pagination|safe }}{% endif %}
</tbody>
</table>
{% endif %}
Expand Down Expand Up @@ -389,7 +389,7 @@ <h3 id="finalized-transactions">Finalized Transactions ckETH → ETH and ckERC20
<td>{{ tx.status }}</td>
</tr>
{% endfor %}
{% if table.has_more_than_one_page() %}}{{ table.pagination }}{% endif %}
{% if table.has_more_than_one_page() %}}{{ table.pagination|safe }}{% endif %}
</tbody>
</table>
{% endif %}
Expand Down Expand Up @@ -431,7 +431,7 @@ <h3 id="reimbursed-transactions">Reimbursed Transactions</h3>
</tr>
{% endmatch %}
{% endfor %}
{% if table.has_more_than_one_page() %}}{{ table.pagination }}{% endif %}
{% if table.has_more_than_one_page() %}}{{ table.pagination|safe }}{% endif %}
</tbody>
</table>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion rs/ethereum/cketh/minter/templates/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<td colspan='{{ table_width }}' style='text-align: right;'>
<b>Pages: </b>
{% for page in pages %}
{% if page.index != current_page_index %}
{% if page.index == current_page_index %}
{{ page.index }}&nbsp;
{% else %}
<a href='?{{ page_offset_query_param }}={{ page.offset }}#{{ table_id }}'>{{ page.index }}</a>&nbsp;
Expand Down

0 comments on commit 6730df5

Please sign in to comment.