-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1078 from rainlanguage/Port-vault-queries
Port vault queries and components
- Loading branch information
Showing
34 changed files
with
884 additions
and
1,389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
packages/ui-components/src/__tests__/VaultBalanceChangesTable.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { render, screen, waitFor } from '@testing-library/svelte'; | ||
import { test, vi } from 'vitest'; | ||
import { expect } from '../lib/test/matchers'; | ||
import { QueryClient } from '@tanstack/svelte-query'; | ||
import VaultBalanceChangesTable from '../lib/components/tables/VaultBalanceChangesTable.svelte'; | ||
import type { VaultBalanceChange } from '@rainlanguage/orderbook/js_api'; | ||
import { formatTimestampSecondsAsLocal } from '../lib/utils/time'; | ||
|
||
vi.mock('@rainlanguage/orderbook/js_api', () => ({ | ||
getVaultBalanceChanges: vi.fn() | ||
})); | ||
|
||
test('renders the vault list table with correct data', async () => { | ||
const queryClient = new QueryClient(); | ||
|
||
const mockVaultBalanceChanges: VaultBalanceChange[] = [ | ||
{ | ||
__typename: 'Withdrawal', | ||
amount: '1000', | ||
oldVaultBalance: '5000', | ||
newVaultBalance: '4000', | ||
vault: { | ||
id: 'vault1', | ||
vault_id: 'vault-id1', | ||
token: { | ||
id: 'token1', | ||
address: '0xTokenAddress1', | ||
name: 'Token1', | ||
symbol: 'TKN1', | ||
decimals: '18' | ||
} | ||
}, | ||
timestamp: '1625247600', | ||
transaction: { | ||
id: 'tx1', | ||
from: '0xUser1', | ||
timestamp: '0', | ||
blockNumber: '0' | ||
}, | ||
orderbook: { | ||
id: '0x00' | ||
} | ||
} | ||
// ... other mock data | ||
] as unknown as VaultBalanceChange[]; | ||
|
||
// Mock the getVaultBalanceChanges function | ||
const { getVaultBalanceChanges } = await import('@rainlanguage/orderbook/js_api'); | ||
vi.mocked(getVaultBalanceChanges).mockResolvedValue(mockVaultBalanceChanges); | ||
|
||
render(VaultBalanceChangesTable, { | ||
props: { | ||
id: '100', | ||
subgraphUrl: 'https://example.com' | ||
}, | ||
context: new Map([['$$_queryClient', queryClient]]) | ||
}); | ||
|
||
await waitFor(() => { | ||
const rows = screen.getAllByTestId('bodyRow'); | ||
expect(rows).toHaveLength(1); | ||
}); | ||
}); | ||
|
||
test('it shows the correct data in the table', async () => { | ||
const queryClient = new QueryClient(); | ||
|
||
const mockVaultBalanceChanges: VaultBalanceChange[] = [ | ||
{ | ||
__typename: 'Withdrawal', | ||
amount: '1000', | ||
oldVaultBalance: '5000', | ||
newVaultBalance: '4000', | ||
vault: { | ||
id: 'vault1', | ||
vault_id: 'vault-id1', | ||
token: { | ||
id: 'token1', | ||
address: '0xTokenAddress1', | ||
name: 'Token1', | ||
symbol: 'TKN1', | ||
decimals: '4' | ||
} | ||
}, | ||
timestamp: '1625247600', | ||
transaction: { | ||
id: 'tx1', | ||
from: '0xUser1', | ||
timestamp: '0', | ||
blockNumber: '0' | ||
}, | ||
orderbook: { | ||
id: '0x00' | ||
} | ||
} | ||
] as unknown as VaultBalanceChange[]; | ||
|
||
// Mock the getVaultBalanceChanges function | ||
const { getVaultBalanceChanges } = await import('@rainlanguage/orderbook/js_api'); | ||
vi.mocked(getVaultBalanceChanges).mockResolvedValue(mockVaultBalanceChanges); | ||
|
||
render(VaultBalanceChangesTable, { | ||
props: { | ||
id: '100', | ||
subgraphUrl: 'https://example.com' | ||
}, | ||
context: new Map([['$$_queryClient', queryClient]]) | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId('vaultBalanceChangesTableDate')).toHaveTextContent( | ||
formatTimestampSecondsAsLocal(BigInt('1625247600')) | ||
); | ||
expect(screen.getByTestId('vaultBalanceChangesTableFrom')).toHaveTextContent('0xUse...User1'); | ||
expect(screen.getByTestId('vaultBalanceChangesTableTx')).toHaveTextContent('tx1'); | ||
expect(screen.getByTestId('vaultBalanceChangesTableBalanceChange')).toHaveTextContent( | ||
'0.1 TKN1' | ||
); | ||
expect(screen.getByTestId('vaultBalanceChangesTableBalance')).toHaveTextContent('0.4 TKN1'); | ||
expect(screen.getByTestId('vaultBalanceChangesTableType')).toHaveTextContent('Withdrawal'); | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
packages/ui-components/src/__tests__/VaultBalanceChart.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { render } from '@testing-library/svelte'; | ||
import { expect, test, vi } from 'vitest'; | ||
import { QueryClient } from '@tanstack/svelte-query'; | ||
import VaultBalanceChart from '../lib/components/charts/VaultBalanceChart.svelte'; | ||
import type { Vault } from '@rainlanguage/orderbook/js_api'; | ||
import { getVaultBalanceChanges } from '@rainlanguage/orderbook/js_api'; | ||
import { writable } from 'svelte/store'; | ||
|
||
vi.mock('@rainlanguage/orderbook/js_api', () => ({ | ||
getVaultBalanceChanges: vi.fn() | ||
})); | ||
|
||
vi.mock('../lib/components/charts/TanstackLightweightChartLine.svelte', async () => { | ||
const MockLightweightChart = (await import('../lib/__mocks__/MockComponent.svelte')).default; | ||
return { default: MockLightweightChart }; | ||
}); | ||
|
||
const mockVault: Vault = { | ||
id: 'vault1', | ||
vaultId: 'vault1', | ||
token: { | ||
id: 'token1', | ||
address: '0xTokenAddress1', | ||
name: 'Token1', | ||
symbol: 'TKN1', | ||
decimals: '18' | ||
}, | ||
owner: '0xOwnerAddress', | ||
ordersAsInput: [], | ||
ordersAsOutput: [], | ||
balanceChanges: [], | ||
balance: '1000000000000000000', | ||
orderbook: { | ||
id: '0x00' | ||
} | ||
}; | ||
|
||
test('calls getVaultBalanceChanges with correct arguments', async () => { | ||
const queryClient = new QueryClient(); | ||
|
||
render(VaultBalanceChart, { | ||
props: { | ||
vault: mockVault, | ||
subgraphUrl: 'https://example.com', | ||
lightweightChartsTheme: writable({}) | ||
}, | ||
context: new Map([['$$_queryClient', queryClient]]) | ||
}); | ||
|
||
expect(getVaultBalanceChanges).toHaveBeenCalledWith('https://example.com', 'vault1', { | ||
page: 1, | ||
pageSize: 1000 | ||
}); | ||
}); |
Oops, something went wrong.