Skip to content

Commit

Permalink
add useChainSvgLogo, useNativeTokenSvgLogo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumXO committed Nov 17, 2023
1 parent 2894f69 commit f1d9ea2
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/components/Svg/Networks/components/Bnb-chain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ const Item: FC<PropsWithChildren<SvgProps>> = (props): ReactElement => (
</Svg>
);

Item.displayName = 'BNB Chain';

export default memo(Item);
2 changes: 2 additions & 0 deletions src/components/Svg/Networks/components/Fantom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ const Item: FC<PropsWithChildren<SvgProps>> = (props): ReactElement => (
</Svg>
);

Item.displayName = 'Fantom';

export default memo(Item);
20 changes: 20 additions & 0 deletions src/hooks/__tests__/useChainSvgLogo.test.tsx
Original file line number Diff line number Diff line change
@@ -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);
});
11 changes: 11 additions & 0 deletions src/hooks/__tests__/useNativeTokenSvgLogo.test.tsx
Original file line number Diff line number Diff line change
@@ -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);
});
2 changes: 1 addition & 1 deletion src/hooks/useChainSvgLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SvgProps } from "../components/Svg/types";

type UseNetworksSvgLogoReturnType = NamedExoticComponent<PropsWithChildren<SvgProps>>;

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;
Expand Down
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3105,6 +3105,14 @@
lodash "^4.17.15"
redent "^3.0.0"

"@testing-library/[email protected]":
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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit f1d9ea2

Please sign in to comment.