From 9c56c21d0293dc237f4ae2ff92684ad19e1b9f7b Mon Sep 17 00:00:00 2001 From: storywithoutend Date: Wed, 20 Nov 2024 13:40:02 +0800 Subject: [PATCH] add tests and clean up folder structure --- .../pages/profile/[name]/Profile.tsx | 2 +- .../hooks/pages/profile/useRenew}/useRenew.ts | 0 src/utils/string.test.ts | 28 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) rename { src/hooks/pages/profile => src/hooks/pages/profile/useRenew}/useRenew.ts (100%) create mode 100644 src/utils/string.test.ts diff --git a/src/components/pages/profile/[name]/Profile.tsx b/src/components/pages/profile/[name]/Profile.tsx index ac9940a62..a34786aa3 100644 --- a/src/components/pages/profile/[name]/Profile.tsx +++ b/src/components/pages/profile/[name]/Profile.tsx @@ -1,4 +1,3 @@ -import { useRenew } from '@root/ src/hooks/pages/profile/useRenew' import Head from 'next/head' import { useEffect, useMemo } from 'react' import { Trans, useTranslation } from 'react-i18next' @@ -12,6 +11,7 @@ import BaseLink from '@app/components/@atoms/BaseLink' import { Outlink } from '@app/components/Outlink' import { useAbilities } from '@app/hooks/abilities/useAbilities' import { useChainName } from '@app/hooks/chain/useChainName' +import { useRenew } from '@app/hooks/pages/profile/useRenew/useRenew' import { useNameDetails } from '@app/hooks/useNameDetails' import { useProtectedRoute } from '@app/hooks/useProtectedRoute' import { useQueryParameterState } from '@app/hooks/useQueryParameterState' diff --git a/ src/hooks/pages/profile/useRenew.ts b/src/hooks/pages/profile/useRenew/useRenew.ts similarity index 100% rename from src/hooks/pages/profile/useRenew.ts rename to src/hooks/pages/profile/useRenew/useRenew.ts diff --git a/src/utils/string.test.ts b/src/utils/string.test.ts new file mode 100644 index 000000000..7c079b315 --- /dev/null +++ b/src/utils/string.test.ts @@ -0,0 +1,28 @@ +import { it, describe, expect } from "vitest"; +import { parseNumericString } from "./string"; + +describe('parseNumericString', () => { + it('should return an integer', () => { + expect(parseNumericString('123')).toBe(123) + }) + + it('should return an integer for a decimal', () => { + expect(parseNumericString('123.123')).toBe(123) + }) + + it('should return null for a string', () => { + expect(parseNumericString('abc')).toBe(null) + }) + + it('should return null for an empty string', () => { + expect(parseNumericString('')).toBe(null) + }) + + it('should return null for a negative number', () => { + expect(parseNumericString('-123')).toBe(null) + }) + + it('should return null for a negative number', () => { + expect(parseNumericString('1a23')).toBe(null) + }) +}) \ No newline at end of file