From 6030d799898f157e2275a4881609559cb001fdbf Mon Sep 17 00:00:00 2001 From: nino Date: Mon, 30 Dec 2024 15:53:26 +0400 Subject: [PATCH 1/4] Move EvalResultsTable.svelte into components ui --- .../src/lib/components/debug/EvalResultsTable.svelte | 3 +-- packages/ui-components/src/lib/index.ts | 1 + tauri-app/src/lib/components/modal/ModalQuoteDebug.svelte | 3 +-- tauri-app/src/lib/components/modal/ModalTradeDebug.svelte | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) rename {tauri-app => packages/ui-components}/src/lib/components/debug/EvalResultsTable.svelte (89%) diff --git a/tauri-app/src/lib/components/debug/EvalResultsTable.svelte b/packages/ui-components/src/lib/components/debug/EvalResultsTable.svelte similarity index 89% rename from tauri-app/src/lib/components/debug/EvalResultsTable.svelte rename to packages/ui-components/src/lib/components/debug/EvalResultsTable.svelte index 9ff14b89c..1aac9f025 100644 --- a/tauri-app/src/lib/components/debug/EvalResultsTable.svelte +++ b/packages/ui-components/src/lib/components/debug/EvalResultsTable.svelte @@ -1,5 +1,4 @@ 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/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; From ba29304df3b0f8f7c7ad57a2ef88b5f5b9e8f06e Mon Sep 17 00:00:00 2001 From: nino Date: Mon, 30 Dec 2024 15:54:16 +0400 Subject: [PATCH 2/4] Fmt --- .../components/debug/EvalResultsTable.svelte | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/ui-components/src/lib/components/debug/EvalResultsTable.svelte b/packages/ui-components/src/lib/components/debug/EvalResultsTable.svelte index 1aac9f025..db7d6c71d 100644 --- a/packages/ui-components/src/lib/components/debug/EvalResultsTable.svelte +++ b/packages/ui-components/src/lib/components/debug/EvalResultsTable.svelte @@ -1,32 +1,32 @@
- - Stack item - Value - Hex - - - {#each table.rows[0] as value, i} - - {table.column_names[i]} - {isHex(value) ? formatEther(hexToBigInt(value)) : ''} - {value} - - {/each} - + + Stack item + Value + Hex + + + {#each table.rows[0] as value, i} + + {table.column_names[i]} + {isHex(value) ? formatEther(hexToBigInt(value)) : ''} + {value} + + {/each} +
From 88cfc0289d36f138545439f915e3956a4fe11934 Mon Sep 17 00:00:00 2001 From: nino Date: Mon, 30 Dec 2024 18:36:43 +0400 Subject: [PATCH 3/4] Move test --- .../components/debug/EvalResultsTable.test.ts | 40 ++++++++++++++++++ .../components/debug/EvalResultsTable.test.ts | 41 ------------------- 2 files changed, 40 insertions(+), 41 deletions(-) create mode 100644 packages/ui-components/src/lib/components/debug/EvalResultsTable.test.ts delete mode 100644 tauri-app/src/lib/components/debug/EvalResultsTable.test.ts 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..1fd6874b2 --- /dev/null +++ b/packages/ui-components/src/lib/components/debug/EvalResultsTable.test.ts @@ -0,0 +1,40 @@ +import { render, screen, waitFor } from '@testing-library/svelte'; +import { test } from 'vitest'; +import { expect } from 'tauri-app/src/lib/test/matchers.ts'; +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/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(); - } - }); - }); -}); From 0ca189a4330d3edfbca157aec7ab33e2e06b01df Mon Sep 17 00:00:00 2001 From: nino Date: Tue, 31 Dec 2024 11:12:51 +0400 Subject: [PATCH 4/4] Remove tauri-app expect from test and use vitest expect instead --- .../src/lib/components/debug/EvalResultsTable.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/ui-components/src/lib/components/debug/EvalResultsTable.test.ts b/packages/ui-components/src/lib/components/debug/EvalResultsTable.test.ts index 1fd6874b2..4e11ddcc0 100644 --- a/packages/ui-components/src/lib/components/debug/EvalResultsTable.test.ts +++ b/packages/ui-components/src/lib/components/debug/EvalResultsTable.test.ts @@ -1,6 +1,5 @@ import { render, screen, waitFor } from '@testing-library/svelte'; -import { test } from 'vitest'; -import { expect } from 'tauri-app/src/lib/test/matchers.ts'; +import { test, expect } from 'vitest'; import EvalResultsTable from './EvalResultsTable.svelte'; import { formatEther, hexToBigInt, isHex } from 'viem';