From 7f8740eb513d90ecab2f31de93dbdd513f986784 Mon Sep 17 00:00:00 2001 From: Stanislav Lysak Date: Mon, 2 Dec 2024 12:03:20 +0200 Subject: [PATCH] FET-1707: Improve unit test coverage WIP --- .../@molecules/Hamburger/MainMenu.tsx | 32 ++------ src/components/ConnectButton.test.tsx | 38 ++++++++++ src/components/ConnectButton.tsx | 14 +--- src/components/SocialIcon.test.tsx | 18 +++++ src/components/SocialIcon.tsx | 73 +++++++++++++++---- src/components/TabBar.test.tsx | 67 +++++++++++++++++ src/components/TabBar.tsx | 7 +- 7 files changed, 195 insertions(+), 54 deletions(-) create mode 100644 src/components/ConnectButton.test.tsx create mode 100644 src/components/SocialIcon.test.tsx create mode 100644 src/components/TabBar.test.tsx diff --git a/src/components/@molecules/Hamburger/MainMenu.tsx b/src/components/@molecules/Hamburger/MainMenu.tsx index 06ee8e264..731ae44a5 100644 --- a/src/components/@molecules/Hamburger/MainMenu.tsx +++ b/src/components/@molecules/Hamburger/MainMenu.tsx @@ -12,14 +12,6 @@ import { WalletSVG, } from '@ensdomains/thorin' -import SocialDiscord from '@app/assets/social/SocialDiscord.svg' -import SocialDiscourse from '@app/assets/social/SocialDiscourse.svg' -import SocialDiscourseColour from '@app/assets/social/SocialDiscourseColour.svg' -import SocialGithub from '@app/assets/social/SocialGithub.svg' -import SocialMirror from '@app/assets/social/SocialMirror.svg' -import SocialMirrorColour from '@app/assets/social/SocialMirrorColour.svg' -import SocialX from '@app/assets/social/SocialX.svg' -import SocialYoutube from '@app/assets/social/SocialYoutube.svg' import BaseLink from '@app/components/@atoms/BaseLink' import { SocialIcon } from '@app/components/SocialIcon' import { useChainName } from '@app/hooks/chain/useChainName' @@ -295,24 +287,12 @@ const MainMenu = ({ setCurrentView }: { setCurrentView: (view: 'main' | 'languag ))} - - - - - - + + + + + + diff --git a/src/components/ConnectButton.test.tsx b/src/components/ConnectButton.test.tsx new file mode 100644 index 000000000..7c3415724 --- /dev/null +++ b/src/components/ConnectButton.test.tsx @@ -0,0 +1,38 @@ +import { mockFunction, render, screen } from '@app/test-utils' + +import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { useBreakpoint } from '@app/utils/BreakpointProvider' + +import { ConnectButton } from './ConnectButton' + +vi.mock('@app/utils/BreakpointProvider') + +const baseBreakpoints: ReturnType = { + xs: true, + sm: true, + md: true, + lg: false, + xl: false, +} + +const mockUseBreakpoint = mockFunction(useBreakpoint) + +describe('ConnectButton', () => { + beforeEach(() => { + mockUseBreakpoint.mockReturnValue(baseBreakpoints) + }) + + it('should render button in header', () => { + render() + expect(screen.getByTestId('connect-button')).toBeInTheDocument() + }) + it('should render button in body', () => { + render() + expect(screen.getByTestId('body-connect-button')).toBeInTheDocument() + }) + it('should render button in tabbar', () => { + render() + expect(screen.getByTestId('tabbar-connect-button')).toBeInTheDocument() + }) +}) diff --git a/src/components/ConnectButton.tsx b/src/components/ConnectButton.tsx index 921891df9..ce69c60a6 100644 --- a/src/components/ConnectButton.tsx +++ b/src/components/ConnectButton.tsx @@ -96,16 +96,6 @@ type Props = { inHeader?: boolean } -const calculateTestId = (isTabBar: boolean | undefined, inHeader: boolean | undefined) => { - if (isTabBar) { - return 'tabbar-connect-button' - } - if (!inHeader) { - return 'body-connect-button' - } - return 'connect-button' -} - export const ConnectButton = ({ isTabBar, large, inHeader }: Props) => { const { t } = useTranslation('common') const breakpoints = useBreakpoint() @@ -114,7 +104,9 @@ export const ConnectButton = ({ isTabBar, large, inHeader }: Props) => { return (