Skip to content

Commit

Permalink
fix some failing unit tests (not all yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Dec 13, 2024
1 parent fcb70fb commit 45af67d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 18 additions & 7 deletions src/components/@molecules/ProfileEditor/Avatar/AvatarNFT.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import * as ReactQuery from '@tanstack/react-query'
import { beforeEach, describe, expect, it, Mock, vi } from 'vitest'
import { useAccount, useClient } from 'wagmi'

import * as ThorinComponents from '@ensdomains/thorin'

import * as UseInfiniteQuery from '@app/utils/query/useInfiniteQuery'

import { makeMockIntersectionObserver } from '../../../../../test/mock/makeMockIntersectionObserver'
import { AvatarNFT } from './AvatarNFT'
import React from 'react'

vi.mock('wagmi')
vi.mock('@app/hooks/chain/useCurrentBlockTimestamp', () => ({
Expand All @@ -20,6 +20,8 @@ vi.mock('@app/hooks/chain/useChainName', () => ({
useChainName: () => 'mainnet',
}))



const mockUseClient = mockFunction(useClient)
const mockUseAccount = mockFunction(useAccount)

Expand Down Expand Up @@ -194,6 +196,8 @@ describe('<AvatarNFT />', () => {
})
it('show load more data on page load trigger', async () => {
const useInfiniteQuerySpy = vi.spyOn(UseInfiniteQuery, 'useInfiniteQuery')


mockFetch
.mockImplementationOnce(() =>
Promise.resolve({
Expand All @@ -209,12 +213,16 @@ describe('<AvatarNFT />', () => {
pageKey: 'test456',
}),
)
vi.spyOn(ThorinComponents, 'ScrollBox').mockImplementationOnce(
({ children, onReachedBottom }) => {
vi.mock('@ensdomains/thorin', async (importActual) => ({
...(await importActual() as any),
ScrollBox: () => ({ children, onReachedBottom }: React.PropsWithChildren<{
onReachedBottom?: () => void;
}>) => {
onReachedBottom!()
return <div>{children}</div>
},
)
}))


render(<AvatarNFT {...props} />)
await waitFor(() => expect(mockFetch).toHaveBeenCalled())
Expand Down Expand Up @@ -246,12 +254,15 @@ describe('<AvatarNFT />', () => {
}),
)

vi.spyOn(ThorinComponents, 'ScrollBox').mockImplementationOnce(
({ children, onReachedBottom }) => {
vi.mock('@ensdomains/thorin', async (importActual) => ({
...(await importActual() as any),
ScrollBox: () => ({ children, onReachedBottom }: React.PropsWithChildren<{
onReachedBottom?: () => void;
}>) => {
onReachedBottom!()
return <div>{children}</div>
},
)
}))

render(<AvatarNFT {...props} />)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('AddProfileRecordView', () => {
render(<AddProfileRecordView control={result.current.control} />)
await userEvent.click(screen.getByTestId('profile-record-option-ipfs'))
expect(screen.getByTestId('profile-record-option-ipfs')).toHaveStyle(
'background-color: ButtonFace',
'background-color: rgb(238, 245, 255)',
)
expect(screen.getByTestId('profile-record-option-skynet')).toBeDisabled()
expect(screen.getByTestId('profile-record-option-swarm')).toBeDisabled()
Expand Down

0 comments on commit 45af67d

Please sign in to comment.