-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract search logic from nfts part2 (#2424)
- Loading branch information
Showing
8 changed files
with
104 additions
and
67 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
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,26 @@ | ||
import {YoroiNft} from '../yoroi-wallets' | ||
import {nft} from '../yoroi-wallets/mocks' | ||
import {filterNfts} from './filterNfts' | ||
|
||
describe('filterNfts', () => { | ||
const cryptoWolf = {...nft, id: '0', fingerprint: 'fakefingerprint1', name: 'CryptoWolf #1234'} | ||
const boredMonkey = {...nft, id: '1', fingerprint: 'fakefingerprint2', name: 'Bored Monkey #4567'} | ||
const appleBlocks = {...nft, id: '2', fingerprint: 'fakefingerprint3', name: 'Apple Blocks #7890'} | ||
|
||
const nfts: YoroiNft[] = [cryptoWolf, boredMonkey, appleBlocks] | ||
|
||
it('filters NFTs correctly with case-insensitive search term', () => { | ||
const filteredNfts = filterNfts('APple bLOcks', nfts) | ||
expect(filteredNfts).toEqual([appleBlocks]) | ||
}) | ||
|
||
it('returns empty array when nft array is empty', () => { | ||
const filteredNfts = filterNfts('Bored Monkey #4567', []) | ||
expect(filteredNfts).toEqual([]) | ||
}) | ||
|
||
it('returns all NFTs when search term is empty', () => { | ||
const filteredNfts = filterNfts('', nfts) | ||
expect(filteredNfts).toEqual(nfts) | ||
}) | ||
}) |
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,8 @@ | ||
import {YoroiNft} from '../yoroi-wallets' | ||
|
||
export const filterNfts = (searchTerm: string, nfts: YoroiNft[]): YoroiNft[] => { | ||
const searchTermLowerCase = searchTerm.toLowerCase() | ||
const filteredNfts = | ||
searchTermLowerCase.length > 0 ? nfts.filter((nft) => nft.name.toLowerCase().includes(searchTermLowerCase)) : nfts | ||
return filteredNfts | ||
} |
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