From af1df66f10b434ca7e1e2381727ed14eb8e20218 Mon Sep 17 00:00:00 2001 From: nino Date: Fri, 27 Dec 2024 13:10:44 +0400 Subject: [PATCH] Move RaindexVersionValidator to components-ui --- .../components/RaindexVersionValidator.svelte | 21 +++++++++++++ .../RaindexVersionValidator.test.ts | 30 +++++++++++++++++++ packages/ui-components/src/lib/index.ts | 1 + .../components/RaindexVersionValidator.svelte | 21 ------------- .../RaindexVersionValidator.test.ts | 30 ------------------- 5 files changed, 52 insertions(+), 51 deletions(-) create mode 100644 packages/ui-components/src/lib/components/RaindexVersionValidator.svelte create mode 100644 packages/ui-components/src/lib/components/RaindexVersionValidator.test.ts delete mode 100644 tauri-app/src/lib/components/RaindexVersionValidator.svelte delete mode 100644 tauri-app/src/lib/components/RaindexVersionValidator.test.ts diff --git a/packages/ui-components/src/lib/components/RaindexVersionValidator.svelte b/packages/ui-components/src/lib/components/RaindexVersionValidator.svelte new file mode 100644 index 000000000..f13b6bccd --- /dev/null +++ b/packages/ui-components/src/lib/components/RaindexVersionValidator.svelte @@ -0,0 +1,21 @@ + + +{#if error && typeof error == 'string' && error.startsWith('Raindex version')} + + +
+ {error} + This order may not be compatible with this version of Raindex. Head to + Github to find a compatible release. +
+
+{/if} diff --git a/packages/ui-components/src/lib/components/RaindexVersionValidator.test.ts b/packages/ui-components/src/lib/components/RaindexVersionValidator.test.ts new file mode 100644 index 000000000..ac4c1df0e --- /dev/null +++ b/packages/ui-components/src/lib/components/RaindexVersionValidator.test.ts @@ -0,0 +1,30 @@ +import { describe, test, expect } from 'vitest'; +import { render } from '@testing-library/svelte'; +import RaindexVersionValidator from './RaindexVersionValidator.svelte'; + +describe('RaindexVersionValidator Component', () => { + test('should show error message if error is a string that starts with "Raindex version"', () => { + const error = 'Raindex version error'; + const comp = render(RaindexVersionValidator, { props: { error } }); + + const alert = comp.getByRole('alert'); + expect(alert).toContainHTML('Raindex version error'); + expect(alert).toHaveTextContent( + `This order may not be compatible with this version of Raindex. ` + ); + }); + + test('should not show error message if error is not a string', () => { + const error = 42; + const comp = render(RaindexVersionValidator, { props: { error } }); + + expect(() => comp.getByRole('alert')).toThrow(); + }); + + test('should not show error message if error does not start with "Raindex version"', () => { + const error = 'Some other error'; + const comp = render(RaindexVersionValidator, { props: { error } }); + + expect(() => comp.getByRole('alert')).toThrow(); + }); +}); diff --git a/packages/ui-components/src/lib/index.ts b/packages/ui-components/src/lib/index.ts index 88874ce51..323f8d24c 100644 --- a/packages/ui-components/src/lib/index.ts +++ b/packages/ui-components/src/lib/index.ts @@ -46,6 +46,7 @@ export { default as IconSuccess } from './components/IconSuccess.svelte'; 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 RaindexVersionValidator } from './components/RaindexVersionValidator.svelte'; //Types export type { AppStoresInterface } from './types/appStores.ts'; diff --git a/tauri-app/src/lib/components/RaindexVersionValidator.svelte b/tauri-app/src/lib/components/RaindexVersionValidator.svelte deleted file mode 100644 index 4bf54a01e..000000000 --- a/tauri-app/src/lib/components/RaindexVersionValidator.svelte +++ /dev/null @@ -1,21 +0,0 @@ - - -{#if error && typeof error == 'string' && error.startsWith('Raindex version')} - - -
- {error} - This order may not be compatible with this version of Raindex. Head to - Github to find a compatible release. -
-
-{/if} diff --git a/tauri-app/src/lib/components/RaindexVersionValidator.test.ts b/tauri-app/src/lib/components/RaindexVersionValidator.test.ts deleted file mode 100644 index ddccb0a0f..000000000 --- a/tauri-app/src/lib/components/RaindexVersionValidator.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { describe, test, expect } from 'vitest'; -import { render } from '@testing-library/svelte'; -import RaindexVersionValidator from './RaindexVersionValidator.svelte'; - -describe('RaindexVersionValidator Component', () => { - test('should show error message if error is a string that starts with "Raindex version"', () => { - const error = 'Raindex version error'; - const comp = render(RaindexVersionValidator, { props: { error } }); - - const alert = comp.getByRole('alert'); - expect(alert).toContainHTML('Raindex version error'); - expect(alert).toHaveTextContent( - `This order may not be compatible with this version of Raindex. `, - ); - }); - - test('should not show error message if error is not a string', () => { - const error = 42; - const comp = render(RaindexVersionValidator, { props: { error } }); - - expect(() => comp.getByRole('alert')).toThrow(); - }); - - test('should not show error message if error does not start with "Raindex version"', () => { - const error = 'Some other error'; - const comp = render(RaindexVersionValidator, { props: { error } }); - - expect(() => comp.getByRole('alert')).toThrow(); - }); -});