From f1d9ea2ed0db03c0849fe1c42173f9a9849a96cb Mon Sep 17 00:00:00 2001 From: Sikorskiy Dmitriy Date: Fri, 17 Nov 2023 17:50:43 +0200 Subject: [PATCH] add useChainSvgLogo, useNativeTokenSvgLogo tests --- package.json | 1 + .../Svg/Networks/components/Bnb-chain.tsx | 2 ++ .../Svg/Networks/components/Fantom.tsx | 2 ++ src/hooks/__tests__/useChainSvgLogo.test.tsx | 20 +++++++++++++++++++ .../__tests__/useNativeTokenSvgLogo.test.tsx | 11 ++++++++++ src/hooks/useChainSvgLogo.tsx | 2 +- yarn.lock | 15 ++++++++++++++ 7 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/hooks/__tests__/useChainSvgLogo.test.tsx create mode 100644 src/hooks/__tests__/useNativeTokenSvgLogo.test.tsx diff --git a/package.json b/package.json index 41fbcfd..4a5a075 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "@storybook/testing-library": "^0.0.14-next.2", "@testing-library/jest-dom": "^5.11.6", "@testing-library/react": "^12.1.3", + "@testing-library/react-hooks": "8.0.1", "@types/react": "^18.0.15", "@types/react-dom": "^18.0.6", "@types/react-router-dom": "^5.1.7", diff --git a/src/components/Svg/Networks/components/Bnb-chain.tsx b/src/components/Svg/Networks/components/Bnb-chain.tsx index 1c94476..45fbbe8 100644 --- a/src/components/Svg/Networks/components/Bnb-chain.tsx +++ b/src/components/Svg/Networks/components/Bnb-chain.tsx @@ -24,4 +24,6 @@ const Item: FC> = (props): ReactElement => ( ); +Item.displayName = 'BNB Chain'; + export default memo(Item); \ No newline at end of file diff --git a/src/components/Svg/Networks/components/Fantom.tsx b/src/components/Svg/Networks/components/Fantom.tsx index 9deb81d..0be6ab4 100644 --- a/src/components/Svg/Networks/components/Fantom.tsx +++ b/src/components/Svg/Networks/components/Fantom.tsx @@ -21,4 +21,6 @@ const Item: FC> = (props): ReactElement => ( ); +Item.displayName = 'Fantom'; + export default memo(Item); \ No newline at end of file diff --git a/src/hooks/__tests__/useChainSvgLogo.test.tsx b/src/hooks/__tests__/useChainSvgLogo.test.tsx new file mode 100644 index 0000000..dac5d99 --- /dev/null +++ b/src/hooks/__tests__/useChainSvgLogo.test.tsx @@ -0,0 +1,20 @@ +import useChainSvgLogo from "../useChainSvgLogo"; +import { renderHook } from "@testing-library/react-hooks"; +import { expect, it } from "vitest"; +import { ChainId } from "@real-wagmi/sdk"; +import { Fantom, BnbChain } from "../../components"; + +it("useChainSvgLogo()", () => { + const { result, rerender } = renderHook((chainId) => useChainSvgLogo(chainId), { + initialProps: ChainId.FANTOM, + }); + + const prevComponent = result.current; + + rerender(ChainId.BSC); + + const updatedComponent = result.current; + + expect(prevComponent).toBe(Fantom); + expect(updatedComponent).toBe(BnbChain); +}); \ No newline at end of file diff --git a/src/hooks/__tests__/useNativeTokenSvgLogo.test.tsx b/src/hooks/__tests__/useNativeTokenSvgLogo.test.tsx new file mode 100644 index 0000000..fc1eaec --- /dev/null +++ b/src/hooks/__tests__/useNativeTokenSvgLogo.test.tsx @@ -0,0 +1,11 @@ +import { renderHook } from "@testing-library/react-hooks"; +import useNativeTokenSvgLogo from "../useNativeTokenSvgLogo"; +import { ChainId } from "@real-wagmi/sdk"; +import Ftm from "../../components/Svg/Tokens/components/Ftm"; +import { it } from "vitest"; + +it("useNativeTokenSvgLogo()", () => { + const resultFantom = renderHook(() => useNativeTokenSvgLogo(ChainId.FANTOM)).result; + + expect(resultFantom.current).toBe(Ftm); +}); \ No newline at end of file diff --git a/src/hooks/useChainSvgLogo.tsx b/src/hooks/useChainSvgLogo.tsx index 5ac52e7..c0d0f87 100644 --- a/src/hooks/useChainSvgLogo.tsx +++ b/src/hooks/useChainSvgLogo.tsx @@ -5,7 +5,7 @@ import { SvgProps } from "../components/Svg/types"; type UseNetworksSvgLogoReturnType = NamedExoticComponent>; -export default function useNetworksSvgLogo(chainId: ChainId = ChainId.ZKSYNC): UseNetworksSvgLogoReturnType { +export default function useChainSvgLogo(chainId: ChainId = ChainId.ZKSYNC): UseNetworksSvgLogoReturnType { let layout: UseNetworksSvgLogoReturnType; switch (chainId) { case ChainId.FANTOM: layout = Fantom; break; diff --git a/yarn.lock b/yarn.lock index 61c139e..4cfd2ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3105,6 +3105,14 @@ lodash "^4.17.15" redent "^3.0.0" +"@testing-library/react-hooks@8.0.1": + version "8.0.1" + resolved "https://registry.yarnpkg.com/@testing-library/react-hooks/-/react-hooks-8.0.1.tgz#0924bbd5b55e0c0c0502d1754657ada66947ca12" + integrity sha512-Aqhl2IVmLt8IovEVarNDFuJDVWVvhnr9/GCU6UUnrYXwgDFF9h2L2o2P9KBni1AST5sT6riAyoukFLyjQUgD/g== + dependencies: + "@babel/runtime" "^7.12.5" + react-error-boundary "^3.1.0" + "@testing-library/react@^12.1.3": version "12.1.5" resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-12.1.5.tgz#bb248f72f02a5ac9d949dea07279095fa577963b" @@ -7525,6 +7533,13 @@ react-element-to-jsx-string@^15.0.0: is-plain-object "5.0.0" react-is "18.1.0" +react-error-boundary@^3.1.0: + version "3.1.4" + resolved "https://registry.yarnpkg.com/react-error-boundary/-/react-error-boundary-3.1.4.tgz#255db92b23197108757a888b01e5b729919abde0" + integrity sha512-uM9uPzZJTF6wRQORmSrvOIgt4lJ9MC1sNgEOj2XGsDTRE4kmpWxg7ENK9EWNKJRMAOY9z0MuF4yIfl6gp4sotA== + dependencies: + "@babel/runtime" "^7.12.5" + react-fast-compare@^3.0.1: version "3.2.2" resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz#929a97a532304ce9fee4bcae44234f1ce2c21d49"