-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: tests for best buying option componend and listings and owners …
…table (#1499) * feat: tests for listings and owners table * feat: added best buy option tests * fix: pr comments * fix: test not passing
- Loading branch information
1 parent
aa7eb5f
commit f0519fa
Showing
8 changed files
with
709 additions
and
9 deletions.
There are no files selected for viewing
205 changes: 205 additions & 0 deletions
205
webapp/src/components/AssetPage/BestBuyingOption/BestBuyingOption.spec.tsx
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,205 @@ | ||
import { | ||
Bid, | ||
ChainId, | ||
Item, | ||
ListingStatus, | ||
Network, | ||
NFTCategory, | ||
Order, | ||
Rarity | ||
} from '@dcl/schemas' | ||
import { waitFor } from '@testing-library/react' | ||
import React, { RefObject } from 'react' | ||
import { t } from 'decentraland-dapps/dist/modules/translation/utils' | ||
|
||
import * as bidAPI from '../../../modules/vendor/decentraland/bid/api' | ||
import * as orderAPI from '../../../modules/vendor/decentraland/order/api' | ||
import { renderWithProviders } from '../../../utils/tests' | ||
import BestBuyingOption from './BestBuyingOption' | ||
import { formatWeiMANA } from '../../../lib/mana' | ||
|
||
jest.mock('../../../modules/vendor/decentraland/nft/api') | ||
jest.mock('../../../modules/vendor/decentraland/order/api') | ||
jest.mock('../../../modules/vendor/decentraland/bid/api') | ||
jest.mock('decentraland-dapps/dist/containers', () => { | ||
const module = jest.requireActual('decentraland-dapps/dist/containers') | ||
return { | ||
...module, | ||
Profile: () => <div></div> | ||
} | ||
}) | ||
|
||
describe('Best Buying Option', () => { | ||
let asset: Item = { | ||
contractAddress: '0xaddress', | ||
itemId: '1', | ||
id: '1', | ||
name: 'asset name', | ||
thumbnail: '', | ||
url: '', | ||
category: NFTCategory.WEARABLE, | ||
rarity: Rarity.UNIQUE, | ||
price: '10', | ||
available: 2, | ||
isOnSale: false, | ||
creator: '0xcreator', | ||
beneficiary: null, | ||
createdAt: 1671033414000, | ||
updatedAt: 1671033414000, | ||
reviewedAt: 1671033414000, | ||
soldAt: 1671033414000, | ||
data: { | ||
parcel: undefined, | ||
estate: undefined, | ||
wearable: undefined, | ||
ens: undefined, | ||
emote: undefined | ||
}, | ||
network: Network.MATIC, | ||
chainId: ChainId.ETHEREUM_GOERLI, | ||
firstListedAt: null | ||
} | ||
|
||
let orderResponse: Order = { | ||
id: '1', | ||
marketplaceAddress: '0xmarketplace', | ||
contractAddress: '0xaddress', | ||
tokenId: '1', | ||
owner: '0x92712b730b9a474f99a47bb8b1750190d5959a2b', | ||
buyer: null, | ||
price: '10', | ||
status: ListingStatus.OPEN, | ||
expiresAt: 1671033414000, | ||
createdAt: 1671033414000, | ||
updatedAt: 0, | ||
network: Network.MATIC, | ||
chainId: ChainId.ETHEREUM_GOERLI | ||
} | ||
|
||
let bid: Bid = { | ||
id: '1', | ||
bidAddress: '0xbid', | ||
bidder: 'bidder', | ||
seller: 'seller', | ||
price: '2', | ||
fingerprint: '', | ||
status: ListingStatus.OPEN, | ||
blockchainId: '1', | ||
blockNumber: '', | ||
expiresAt: 1671033414000, | ||
createdAt: 1671033414000, | ||
updatedAt: 0, | ||
contractAddress: '0xaddress', | ||
tokenId: '', | ||
network: Network.MATIC, | ||
chainId: ChainId.ETHEREUM_GOERLI | ||
} | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
describe('Mint option', () => { | ||
it('should render the mint option', async () => { | ||
const reference: RefObject<HTMLDivElement> = React.createRef() | ||
const { getByText } = renderWithProviders( | ||
<BestBuyingOption asset={asset} tableRef={reference} /> | ||
) | ||
|
||
expect( | ||
getByText(t('best_buying_option.minting.title')) | ||
).toBeInTheDocument() | ||
}) | ||
|
||
it('should render the mint price', async () => { | ||
const reference: RefObject<HTMLDivElement> = React.createRef() | ||
const { getByText } = renderWithProviders( | ||
<BestBuyingOption asset={asset} tableRef={reference} /> | ||
) | ||
|
||
const price = formatWeiMANA(asset.price) | ||
|
||
expect(getByText(price)).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe('Listing option', () => { | ||
beforeEach(() => { | ||
asset.available = 0 | ||
;(orderAPI.orderAPI.fetchOrders as jest.Mock).mockResolvedValueOnce({ | ||
data: [orderResponse], | ||
total: 1 | ||
}) | ||
;(bidAPI.bidAPI.fetchByNFT as jest.Mock).mockResolvedValueOnce({ | ||
data: [bid], | ||
total: 1 | ||
}) | ||
}) | ||
|
||
it('should render the listing option', async () => { | ||
const reference: RefObject<HTMLDivElement> = React.createRef() | ||
const { getByText, findByTestId } = renderWithProviders( | ||
<BestBuyingOption asset={asset} tableRef={reference} /> | ||
) | ||
|
||
const loader = await findByTestId('loader') | ||
|
||
await waitFor(() => { | ||
expect(loader).not.toBeInTheDocument() | ||
}) | ||
|
||
expect( | ||
getByText(t('best_buying_option.buy_listing.title')) | ||
).toBeInTheDocument() | ||
}) | ||
|
||
it('should render the listing price and de highest offer for that NFT', async () => { | ||
const reference: RefObject<HTMLDivElement> = React.createRef() | ||
const { getByText, findByTestId } = renderWithProviders( | ||
<BestBuyingOption asset={asset} tableRef={reference} /> | ||
) | ||
|
||
const loader = await findByTestId('loader') | ||
|
||
await waitFor(() => { | ||
expect(loader).not.toBeInTheDocument() | ||
}) | ||
|
||
const price = formatWeiMANA(orderResponse.price) | ||
|
||
const highestOffer = formatWeiMANA(bid.price) | ||
|
||
expect(getByText(price)).toBeInTheDocument() | ||
expect(getByText(highestOffer)).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
describe('No available options', () => { | ||
beforeEach(() => { | ||
asset.available = 0 | ||
;(orderAPI.orderAPI.fetchOrders as jest.Mock).mockResolvedValueOnce({ | ||
data: [], | ||
total: 0 | ||
}) | ||
;(bidAPI.bidAPI.fetchByNFT as jest.Mock).mockResolvedValueOnce({ | ||
data: [bid], | ||
total: 0 | ||
}) | ||
}) | ||
|
||
it('should render no options available', async () => { | ||
const reference: RefObject<HTMLDivElement> = React.createRef() | ||
const { getByText, findByTestId } = renderWithProviders( | ||
<BestBuyingOption asset={asset} tableRef={reference} /> | ||
) | ||
|
||
const loader = await findByTestId('loader') | ||
|
||
await waitFor(() => { | ||
expect(loader).not.toBeInTheDocument() | ||
}) | ||
|
||
expect(getByText(t('best_buying_option.empty.title'))).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
Oops, something went wrong.