forked from decentraland/marketplace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add favorites counter to cards and detail (decentraland#1495)
* feat: Create Favorites Counter component * fix: Avoid changes in the size of the bubbles on hover * refactor: Use css modules * feat: Add favorites counter to the item detail page and to the asset cards * refactor: Apply PR feedback * test: Add skipped tests (waiting for render with providers) to the components that changed * test: Add tests for the title component and the new favorites counter inside * test: Ass tests for the favorite counter in the item detail
- Loading branch information
1 parent
8c6d79e
commit 31fc96f
Showing
14 changed files
with
232 additions
and
14 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
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,100 @@ | ||
import { BodyShape, ChainId, Network, NFTCategory, Rarity } from '@dcl/schemas' | ||
import { Asset } from '../../modules/asset/types' | ||
import { renderWithProviders } from '../../utils/test' | ||
import AssetCard from './AssetCard' | ||
import { Props as AssetCardProps } from './AssetCard.types' | ||
|
||
const FAVORITES_COUNTER_TEST_ID = 'favorites-counter' | ||
|
||
function renderAssetCard(props: Partial<AssetCardProps> = {}) { | ||
return renderWithProviders( | ||
<AssetCard | ||
asset={{} as Asset} | ||
price={null} | ||
isClaimingBackLandTransactionPending={false} | ||
showRentalChip={false} | ||
rental={null} | ||
isFavoritesEnabled={false} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
describe('AssetCard', () => { | ||
let asset: Asset | ||
|
||
beforeEach(() => { | ||
asset = { | ||
id: 'assetId', | ||
name: 'assetName', | ||
thumbnail: 'assetThumbnail', | ||
url: 'assetUrl', | ||
category: NFTCategory.WEARABLE, | ||
contractAddress: '0xContractAddress', | ||
itemId: '', | ||
rarity: Rarity.UNIQUE, | ||
price: '5000000000000000', | ||
available: 0, | ||
isOnSale: false, | ||
creator: '0xCreator', | ||
beneficiary: null, | ||
createdAt: 0, | ||
updatedAt: 0, | ||
reviewedAt: 0, | ||
soldAt: 0, | ||
data: { | ||
wearable: { | ||
rarity: Rarity.UNIQUE, | ||
bodyShapes: [BodyShape.MALE] | ||
} as Asset['data']['wearable'] | ||
}, | ||
network: Network.MATIC, | ||
chainId: ChainId.MATIC_MUMBAI, | ||
firstListedAt: null | ||
} | ||
}) | ||
|
||
it('should render the Asset Card', () => { | ||
renderAssetCard({ asset }) | ||
}) | ||
|
||
describe('when the favorites feature flag is not enabled', () => { | ||
it('should not render the favorites counter', () => { | ||
const { queryByTestId } = renderAssetCard({ | ||
asset, | ||
isFavoritesEnabled: false | ||
}) | ||
expect(queryByTestId(FAVORITES_COUNTER_TEST_ID)).toBeNull() | ||
}) | ||
}) | ||
|
||
describe('when the favorites feature flag is enabled', () => { | ||
describe('when the asset is an nft', () => { | ||
beforeEach(() => { | ||
asset = { ...asset, tokenId: 'tokenId' } as Asset | ||
}) | ||
|
||
it('should not render the favorites counter', () => { | ||
const { queryByTestId } = renderAssetCard({ | ||
asset, | ||
isFavoritesEnabled: true | ||
}) | ||
expect(queryByTestId(FAVORITES_COUNTER_TEST_ID)).toBeNull() | ||
}) | ||
}) | ||
|
||
describe('when the asset is an item', () => { | ||
beforeEach(() => { | ||
asset = { ...asset, itemId: 'itemId' } as Asset | ||
}) | ||
|
||
it('should render the favorites counter', () => { | ||
const { getByTestId } = renderAssetCard({ | ||
asset, | ||
isFavoritesEnabled: true | ||
}) | ||
expect(getByTestId(FAVORITES_COUNTER_TEST_ID)).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
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,11 @@ | ||
import { connect } from 'react-redux' | ||
import { getIsFavoritesEnabled } from '../../../modules/features/selectors' | ||
import { RootState } from '../../../modules/reducer' | ||
import { MapStateProps } from './Title.types' | ||
import Title from './Title' | ||
|
||
const mapState = (state: RootState): MapStateProps => ({ | ||
isFavoritesEnabled: getIsFavoritesEnabled(state) | ||
}) | ||
|
||
export default connect(mapState)(Title) |
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,58 @@ | ||
import { Asset } from '../../../modules/asset/types' | ||
import { getAssetName } from '../../../modules/asset/utils' | ||
import { renderWithProviders } from '../../../utils/test' | ||
import Title from './Title' | ||
|
||
const FAVORITES_COUNTER_TEST_ID = 'favorites-counter' | ||
|
||
describe('Title', () => { | ||
let asset: Asset | ||
|
||
beforeEach(() => { | ||
asset = { name: 'Asset Name' } as Asset | ||
}) | ||
|
||
it('should render the Asset Name', () => { | ||
const { getByText } = renderWithProviders( | ||
<Title asset={asset} isFavoritesEnabled /> | ||
) | ||
expect(getByText(getAssetName(asset))).toBeInTheDocument() | ||
}) | ||
|
||
describe('when the favorites feature flag is not enabled', () => { | ||
it('should not render the favorites counter', () => { | ||
const { queryByTestId } = renderWithProviders( | ||
<Title asset={asset} isFavoritesEnabled={false} /> | ||
) | ||
expect(queryByTestId(FAVORITES_COUNTER_TEST_ID)).toBeNull() | ||
}) | ||
}) | ||
|
||
describe('when the favorites feature flag is enabled', () => { | ||
describe('when the asset is an nft', () => { | ||
beforeEach(() => { | ||
asset = { ...asset, tokenId: 'tokenId' } as Asset | ||
}) | ||
|
||
it('should not render the favorites counter', () => { | ||
const { queryByTestId } = renderWithProviders( | ||
<Title asset={asset} isFavoritesEnabled /> | ||
) | ||
expect(queryByTestId(FAVORITES_COUNTER_TEST_ID)).toBeNull() | ||
}) | ||
}) | ||
|
||
describe('when the asset is an item', () => { | ||
beforeEach(() => { | ||
asset = { ...asset, itemId: 'itemId' } as Asset | ||
}) | ||
|
||
it('should render the favorites counter', () => { | ||
const { getByTestId } = renderWithProviders( | ||
<Title asset={asset} isFavoritesEnabled /> | ||
) | ||
expect(getByTestId(FAVORITES_COUNTER_TEST_ID)).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import React from 'react' | ||
import { getAssetName } from '../../../modules/asset/utils' | ||
import { getAssetName, isNFT } from '../../../modules/asset/utils' | ||
import { FavoritesCounter } from '../../FavoritesCounter' | ||
import { Props } from './Title.types' | ||
import styles from './Title.module.css' | ||
|
||
const Title = ({ asset }: Props) => { | ||
return <div className={styles.title}>{getAssetName(asset)}</div> | ||
const Title = ({ asset, isFavoritesEnabled }: Props) => { | ||
return ( | ||
<div className={styles.title}> | ||
<span className={styles.text}>{getAssetName(asset)}</span> | ||
{/* TODO: this may be moved after the new detail page for unified markets */} | ||
{isFavoritesEnabled && !isNFT(asset) ? ( | ||
<FavoritesCounter | ||
isCollapsed | ||
className={styles.favorites} | ||
item={asset} | ||
/> | ||
) : null} | ||
</div> | ||
) | ||
} | ||
|
||
export default React.memo(Title) |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import Title from './Title' | ||
import Title from './Title.container' | ||
|
||
export default Title |
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
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