Skip to content

Commit

Permalink
Merge branch 'main' into feat(frontend)/use-component-to-group-of-dat…
Browse files Browse the repository at this point in the history
…es-in-AllTransactionsList
  • Loading branch information
AntonioVentilii committed Nov 15, 2024
2 parents 64ceea6 + 809e5dc commit 25dbf6c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { ethTransactionsStore } from '$eth/stores/eth-transactions.store';
import type { EthTransactionUi } from '$eth/types/eth-transaction';
import IcTransactionModal from '$icp/components/transactions/IcTransactionModal.svelte';
import { btcStatusesStore } from '$icp/stores/btc.store';
import { icTransactionsStore } from '$icp/stores/ic-transactions.store';
import type { IcTransactionUi } from '$icp/types/ic-transaction';
import { ckEthMinterInfoStore } from '$icp-eth/stores/cketh.store';
import TransactionsDateGroup from '$lib/components/transactions/TransactionsDateGroup.svelte';
Expand All @@ -28,15 +30,14 @@
import { mapAllTransactionsUi, sortTransactions } from '$lib/utils/transactions.utils';
let transactions: AllTransactionsUi;
// TODO: add icTransactions and btcStatuses
$: transactions = mapAllTransactionsUi({
tokens: $enabledTokens,
$btcTransactions: $btcTransactionsStore,
$ethTransactions: $ethTransactionsStore,
$ckEthMinterInfo: $ckEthMinterInfoStore,
$ethAddress: $ethAddress,
$icTransactions: {},
$btcStatuses: {}
$icTransactions: $icTransactionsStore,
$btcStatuses: $btcStatusesStore
});
let sortedTransactions: AllTransactionsUi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import * as networkEnv from '$env/networks.env';
import { ETHEREUM_NETWORK_ID, SEPOLIA_NETWORK_ID } from '$env/networks.env';
import * as ethEnv from '$env/networks.eth.env';
import { BTC_MAINNET_TOKEN_ID } from '$env/tokens.btc.env';
import { ETHEREUM_TOKEN_ID } from '$env/tokens.env';
import { ETHEREUM_TOKEN_ID, ICP_TOKEN_ID } from '$env/tokens.env';
import { ethTransactionsStore } from '$eth/stores/eth-transactions.store';
import { icTransactionsStore } from '$icp/stores/ic-transactions.store';
import AllTransactionsList from '$lib/components/transactions/AllTransactionsList.svelte';
import * as transactionsUtils from '$lib/utils/transactions.utils';
import { createMockBtcTransactionsUi } from '$tests/mocks/btc.mock';
import { createMockEthTransactions } from '$tests/mocks/eth-transactions.mock';
import en from '$tests/mocks/i18n.mock';
import { createMockIcTransactionsUi } from '$tests/mocks/ic-transactions.mock';
import { render } from '@testing-library/svelte';

describe('AllTransactionsList', () => {
Expand All @@ -35,27 +37,12 @@ describe('AllTransactionsList', () => {
describe('when the transactions list is not empty', () => {
const btcTransactionsNumber = 5;
const ethTransactionsNumber = 3;
const icTransactionsNumber = 7;

const todayTimestamp = new Date().getTime();
const yesterdayTimestamp = todayTimestamp - 24 * 60 * 60 * 1000;

btcTransactionsStore.append({
tokenId: BTC_MAINNET_TOKEN_ID,
transactions: createMockBtcTransactionsUi(btcTransactionsNumber).map((transaction) => ({
data: { ...transaction, timestamp: BigInt(todayTimestamp) },
certified: false
}))
});

ethTransactionsStore.add({
tokenId: ETHEREUM_TOKEN_ID,
transactions: createMockEthTransactions(ethTransactionsNumber).map((transaction) => ({
...transaction,
timestamp: yesterdayTimestamp
}))
});

beforeEach(() => {
beforeAll(() => {
vi.resetAllMocks();

vi.spyOn(btcEnv, 'BTC_MAINNET_ENABLED', 'get').mockImplementation(() => true);
Expand All @@ -65,6 +52,30 @@ describe('AllTransactionsList', () => {
ETHEREUM_NETWORK_ID,
SEPOLIA_NETWORK_ID
]);

btcTransactionsStore.append({
tokenId: BTC_MAINNET_TOKEN_ID,
transactions: createMockBtcTransactionsUi(btcTransactionsNumber).map((transaction) => ({
data: { ...transaction, timestamp: BigInt(todayTimestamp) },
certified: false
}))
});

ethTransactionsStore.add({
tokenId: ETHEREUM_TOKEN_ID,
transactions: createMockEthTransactions(ethTransactionsNumber).map((transaction) => ({
...transaction,
timestamp: yesterdayTimestamp
}))
});

icTransactionsStore.append({
tokenId: ICP_TOKEN_ID,
transactions: createMockIcTransactionsUi(icTransactionsNumber).map((transaction) => ({
data: { ...transaction, timestamp: BigInt(todayTimestamp) },
certified: false
}))
});
});

it('should not render the placeholder', () => {
Expand Down Expand Up @@ -93,7 +104,9 @@ describe('AllTransactionsList', () => {
(el) => el.parentElement?.parentElement === container
);

expect(transactionComponents).toHaveLength(btcTransactionsNumber + ethTransactionsNumber);
expect(transactionComponents).toHaveLength(
btcTransactionsNumber + ethTransactionsNumber + icTransactionsNumber
);
});
});
});
3 changes: 2 additions & 1 deletion src/frontend/src/tests/mocks/ic-transactions.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const createMockIcTransactionsUi = (n: number): IcTransactionUi[] =>
Array.from({ length: n }, () => ({
id: crypto.randomUUID(),
type: 'send',
status: 'executed'
status: 'executed',
value: BigInt(1)
}));

0 comments on commit 25dbf6c

Please sign in to comment.