-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FET-1707: Improve unit test coverage WIP
- Loading branch information
Stanislav Lysak
committed
Dec 2, 2024
1 parent
4d12ee9
commit 7f8740e
Showing
7 changed files
with
195 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<typeof useBreakpoint> = { | ||
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(<ConnectButton inHeader />) | ||
expect(screen.getByTestId('connect-button')).toBeInTheDocument() | ||
}) | ||
it('should render button in body', () => { | ||
render(<ConnectButton inHeader={false} />) | ||
expect(screen.getByTestId('body-connect-button')).toBeInTheDocument() | ||
}) | ||
it('should render button in tabbar', () => { | ||
render(<ConnectButton isTabBar />) | ||
expect(screen.getByTestId('tabbar-connect-button')).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { render, screen } from '@app/test-utils' | ||
|
||
import { describe, expect, it } from 'vitest' | ||
|
||
import { SocialIcon } from './SocialIcon' | ||
|
||
describe('SocialIcon', () => { | ||
it('should render icon', () => { | ||
render(<SocialIcon social="github" href="https://github.com" />) | ||
expect(screen.getByTestId('social-icon-github')).toBeInTheDocument() | ||
expect(screen.getByTestId('social-icon-github')).toHaveAttribute('href', 'https://github.com') | ||
}) | ||
it('should render colored icon', () => { | ||
const { container } = render(<SocialIcon social="discourse" href="https://discourse.com" />) | ||
const svgs = container.querySelectorAll('svg') | ||
expect(Array.from(svgs).length).toBe(2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* eslint-disable no-promise-executor-return */ | ||
import { mockFunction, render, screen } from '@app/test-utils' | ||
|
||
import mockRouter from 'next-router-mock' | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
||
import { useAccountSafely } from '@app/hooks/account/useAccountSafely' | ||
import { useBreakpoint } from '@app/utils/BreakpointProvider' | ||
|
||
import { TabBar } from './TabBar' | ||
|
||
vi.mock('next/router', async () => await vi.importActual('next-router-mock')) | ||
vi.mock('wagmi', async () => { | ||
const actual = await vi.importActual('wagmi') | ||
return { | ||
...actual, | ||
} | ||
}) | ||
vi.mock('@app/transaction-flow/transaction') | ||
vi.mock('@app/hooks/transactions/TransactionStoreContext') | ||
vi.mock('@app/utils/BreakpointProvider') | ||
vi.mock('@app/hooks/account/useAccountSafely') | ||
vi.mock('@app/hooks/ensjs/public/usePrimaryName', () => ({ | ||
usePrimaryName: ({ address }: { address: unknown }) => mockUsePrimary({ address }), | ||
})) | ||
|
||
const mockUseAccountSafely = mockFunction(useAccountSafely) | ||
const mockUseBreakpoint = mockFunction(useBreakpoint) | ||
const mockUsePrimary = vi.fn().mockImplementation(({}) => { | ||
return { | ||
data: { beautifiedName: 'test.eth', name: 'test.eth' }, | ||
isLoading: false, | ||
} | ||
}) | ||
|
||
const baseBreakpoints: ReturnType<typeof useBreakpoint> = { | ||
xs: true, | ||
sm: true, | ||
md: true, | ||
lg: false, | ||
xl: false, | ||
} | ||
|
||
describe('TabBar', () => { | ||
beforeEach(() => { | ||
mockUseBreakpoint.mockReturnValue(baseBreakpoints) | ||
}) | ||
|
||
it('should render connect button if no address is present', () => { | ||
mockUseAccountSafely.mockReturnValue({}) | ||
render(<TabBar />) | ||
expect(screen.queryByTestId('tabbar-connect-button')).toBeInTheDocument() | ||
}) | ||
|
||
it('should not render connect button if no address is present', () => { | ||
mockUseAccountSafely.mockReturnValue({ address: '0x1234' }) | ||
mockRouter.setCurrentUrl('/?from=from') | ||
render(<TabBar />) | ||
expect(screen.queryByTestId('tabbar-connect-button')).not.toBeInTheDocument() | ||
}) | ||
|
||
it('should render back button if has from query', () => { | ||
mockRouter.setCurrentUrl('/?from=from') | ||
render(<TabBar />) | ||
expect(screen.queryByTestId('tabbar-back')).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters