diff --git a/packages/ui-components/src/lib/components/debug/EvalResultsTable.svelte b/packages/ui-components/src/lib/components/debug/EvalResultsTable.svelte new file mode 100644 index 000000000..db7d6c71d --- /dev/null +++ b/packages/ui-components/src/lib/components/debug/EvalResultsTable.svelte @@ -0,0 +1,32 @@ + + + + + Stack item + Value + Hex + + + {#each table.rows[0] as value, i} + + {table.column_names[i]} + {isHex(value) ? formatEther(hexToBigInt(value)) : ''} + {value} + + {/each} + +
diff --git a/packages/ui-components/src/lib/components/debug/EvalResultsTable.test.ts b/packages/ui-components/src/lib/components/debug/EvalResultsTable.test.ts new file mode 100644 index 000000000..4e11ddcc0 --- /dev/null +++ b/packages/ui-components/src/lib/components/debug/EvalResultsTable.test.ts @@ -0,0 +1,39 @@ +import { render, screen, waitFor } from '@testing-library/svelte'; +import { test, expect } from 'vitest'; +import EvalResultsTable from './EvalResultsTable.svelte'; +import { formatEther, hexToBigInt, isHex } from 'viem'; + +test('renders table with the correct data', async () => { + const table = { + column_names: ['Column1', 'Column2', 'Column3'], + rows: [ + ['0x01', '0x02', '0x03'], + ['0x0a', '0x0b', '0x0c'], + ['0x1f', '0x2e', '0x3d'], + ['0xaa', '0xbb', '0xcc'], + ['0xff', '0xee', '0xdd'] + ] + }; + + render(EvalResultsTable, { table }); + + // Check if the table headers are rendered correctly + expect(screen.getByText('Stack item')).toBeInTheDocument(); + expect(screen.getByText('Value')).toBeInTheDocument(); + expect(screen.getByText('Hex')).toBeInTheDocument(); + + // Check if the table rows are rendered correctly + await waitFor(() => { + table.column_names.forEach((columnName, index) => { + expect(screen.getByText(columnName)).toBeInTheDocument(); + expect(screen.getByText(table.rows[0][index])).toBeInTheDocument(); + + // Verify if the formatted value is correct + const value = table.rows[0][index]; + if (value) { + const formattedValue = isHex(value) ? formatEther(hexToBigInt(value)) : ''; + expect(screen.getByText(formattedValue)).toBeInTheDocument(); + } + }); + }); +}); diff --git a/packages/ui-components/src/lib/index.ts b/packages/ui-components/src/lib/index.ts index b0a3d948d..a48dafbec 100644 --- a/packages/ui-components/src/lib/index.ts +++ b/packages/ui-components/src/lib/index.ts @@ -47,6 +47,7 @@ export { default as IconTelegram } from './components/IconTelegram.svelte'; export { default as IconWalletConnect } from './components/IconWalletConnect.svelte'; export { default as IconWarning } from './components/IconWarning.svelte'; export { default as InputToken } from './components/input/InputToken.svelte'; +export { default as EvalResultsTable } from './components/debug/EvalResultsTable.svelte'; //Types export type { AppStoresInterface } from './types/appStores.ts'; diff --git a/tauri-app/src/lib/components/debug/EvalResultsTable.svelte b/tauri-app/src/lib/components/debug/EvalResultsTable.svelte deleted file mode 100644 index 9ff14b89c..000000000 --- a/tauri-app/src/lib/components/debug/EvalResultsTable.svelte +++ /dev/null @@ -1,33 +0,0 @@ - - - - - Stack item - Value - Hex - - - {#each table.rows[0] as value, i} - - {table.column_names[i]} - {isHex(value) ? formatEther(hexToBigInt(value)) : ''} - {value} - - {/each} - -
diff --git a/tauri-app/src/lib/components/debug/EvalResultsTable.test.ts b/tauri-app/src/lib/components/debug/EvalResultsTable.test.ts deleted file mode 100644 index eca0319b1..000000000 --- a/tauri-app/src/lib/components/debug/EvalResultsTable.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { render, screen, waitFor } from '@testing-library/svelte'; -import { test } from 'vitest'; -import { expect } from '$lib/test/matchers'; -import EvalResultsTable from './EvalResultsTable.svelte'; -import type { RainEvalResultsTable } from '$lib/typeshare/config'; -import { formatEther, hexToBigInt, isHex } from 'viem'; - -test('renders table with the correct data', async () => { - const table: RainEvalResultsTable = { - column_names: ['Column1', 'Column2', 'Column3'], - rows: [ - ['0x01', '0x02', '0x03'], - ['0x0a', '0x0b', '0x0c'], - ['0x1f', '0x2e', '0x3d'], - ['0xaa', '0xbb', '0xcc'], - ['0xff', '0xee', '0xdd'], - ], - }; - - render(EvalResultsTable, { table }); - - // Check if the table headers are rendered correctly - expect(screen.getByText('Stack item')).toBeInTheDocument(); - expect(screen.getByText('Value')).toBeInTheDocument(); - expect(screen.getByText('Hex')).toBeInTheDocument(); - - // Check if the table rows are rendered correctly - await waitFor(() => { - table.column_names.forEach((columnName, index) => { - expect(screen.getByText(columnName)).toBeInTheDocument(); - expect(screen.getByText(table.rows[0][index])).toBeInTheDocument(); - - // Verify if the formatted value is correct - const value = table.rows[0][index]; - if (value) { - const formattedValue = isHex(value) ? formatEther(hexToBigInt(value)) : ''; - expect(screen.getByText(formattedValue)).toBeInTheDocument(); - } - }); - }); -}); diff --git a/tauri-app/src/lib/components/modal/ModalQuoteDebug.svelte b/tauri-app/src/lib/components/modal/ModalQuoteDebug.svelte index 48fe86cb8..d87b0c3fb 100644 --- a/tauri-app/src/lib/components/modal/ModalQuoteDebug.svelte +++ b/tauri-app/src/lib/components/modal/ModalQuoteDebug.svelte @@ -5,8 +5,7 @@ import { createQuery } from '@tanstack/svelte-query'; import { Alert, Modal } from 'flowbite-svelte'; import { type Hex } from 'viem'; - import { Refresh } from '@rainlanguage/ui-components'; - import EvalResultsTable from '../debug/EvalResultsTable.svelte'; + import { Refresh, EvalResultsTable } from '@rainlanguage/ui-components'; import { fade } from 'svelte/transition'; export let open: boolean; diff --git a/tauri-app/src/lib/components/modal/ModalTradeDebug.svelte b/tauri-app/src/lib/components/modal/ModalTradeDebug.svelte index 53c81fa1a..3729b6ba8 100644 --- a/tauri-app/src/lib/components/modal/ModalTradeDebug.svelte +++ b/tauri-app/src/lib/components/modal/ModalTradeDebug.svelte @@ -3,7 +3,7 @@ import { tradeDebug } from '$lib/queries/tradeDebug'; import { createQuery } from '@tanstack/svelte-query'; import { Alert, Modal, Spinner } from 'flowbite-svelte'; - import EvalResultsTable from '../debug/EvalResultsTable.svelte'; + import { EvalResultsTable } from '@rainlanguage/ui-components'; export let open: boolean; export let txHash: string;