• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

decentraland / marketplace / 6468133945

10 Oct 2023 10:36AM UTC coverage: 40.778% (+0.7%) from 40.103%
6468133945

Pull #2030

github

juanmahidalgo
test: add Test for SearchBarDropdown
Pull Request #2030: Feat: new search bar component

2260 of 6951 branches covered (0.0%)

Branch coverage included in aggregate %.

215 of 215 new or added lines in 20 files covered. (100.0%)

4280 of 9087 relevant lines covered (47.1%)

18.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

19.81
/webapp/src/utils/filters.tsx
1
import {
2
  GenderFilterOption,
3
  Network,
4
  NFTCategory,
5
  WearableGender
6
} from '@dcl/schemas'
7
import classNames from 'classnames'
8
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
9
import { Mana } from '../components/Mana'
10
import { LANDFilters } from '../components/Vendor/decentraland/types'
11

12
export enum AssetStatusFilter {
13
  ON_SALE = 'on_sale',
14
  ONLY_MINTING = 'only_minting',
15
  ONLY_LISTING = 'only_listing',
16
  NOT_FOR_SALE = 'not_for_sale'
17
}
18

19
export const AVAILABLE_FOR_MALE = 'AVAILABLE_FOR_MALE'
73✔
20
export const AVAILABLE_FOR_FEMALE = 'AVAILABLE_FOR_FEMALE'
73✔
21

22
export function getPriceLabel(
23
  minPrice?: string,
24
  maxPrice?: string,
25
  network: Network = Network.ETHEREUM
×
26
) {
27
  const priceFormatter = Intl.NumberFormat('en', { notation: 'compact' })
1✔
28
  const manaTranslator = () => (
1✔
29
    <Mana
×
30
      className={classNames('mana-label-icon', {
31
        'mana-label-range': minPrice && maxPrice
×
32
      })}
33
      network={network}
34
    />
35
  )
36

37
  if (!minPrice && !maxPrice) {
1!
38
    return t('nft_filters.price.all_items')
1✔
39
  }
40

41
  if (minPrice && !maxPrice) {
×
42
    return t('nft_filters.price.more_than_price', {
×
43
      price: priceFormatter.format(Number(minPrice)),
44
      mana: manaTranslator
45
    })
46
  }
47

48
  if (maxPrice && !minPrice) {
×
49
    return t('nft_filters.price.less_than_price', {
×
50
      price: priceFormatter.format(Number(maxPrice)),
51
      mana: manaTranslator
52
    })
53
  }
54

55
  return t('nft_filters.price.price_between', {
×
56
    minPrice: priceFormatter.format(Number(minPrice)),
57
    maxPrice: priceFormatter.format(Number(maxPrice)),
58
    mana: manaTranslator
59
  })
60
}
61

62
export function getEstateSizeLabel(min?: string, max?: string) {
63
  const priceFormatter = Intl.NumberFormat('en', { notation: 'compact' })
1✔
64

65
  if (!min && !max) {
1!
66
    return t('nft_filters.estate_size.all_sizes')
1✔
67
  }
68

69
  if (min && !max) {
×
70
    return t('nft_filters.estate_size.more_than_size', {
×
71
      size: priceFormatter.format(Number(min))
72
    })
73
  }
74

75
  if (max && !min) {
×
76
    return t('nft_filters.estate_size.less_than_size', {
×
77
      size: priceFormatter.format(Number(max))
78
    })
79
  }
80

81
  return t('nft_filters.estate_size.size_between', {
×
82
    min: priceFormatter.format(Number(min)),
83
    max: priceFormatter.format(Number(max))
84
  })
85
}
86

87
export function getNetwork(network?: Network, category?: NFTCategory) {
88
  if (network) {
5!
89
    return network
×
90
  }
91

92
  if (
5!
93
    category &&
5!
94
    [NFTCategory.WEARABLE, NFTCategory.EMOTE].includes(category)
95
  ) {
96
    return Network.MATIC
×
97
  }
98

99
  return Network.ETHEREUM
5✔
100
}
101

102
export function getBodyShapeValue(
103
  bodyShapes: (WearableGender | GenderFilterOption)[] | undefined
104
): string | undefined {
105
  if (bodyShapes?.length === 0) {
×
106
    return undefined
×
107
  }
108

109
  const hasUnisex = bodyShapes?.includes(GenderFilterOption.UNISEX)
×
110
  const hasMale = bodyShapes?.includes(GenderFilterOption.MALE)
×
111
  const hasFemale = bodyShapes?.includes(GenderFilterOption.FEMALE)
×
112

113
  if (hasUnisex && hasFemale) {
×
114
    return AVAILABLE_FOR_FEMALE
×
115
  }
116

117
  if (hasUnisex && hasMale) {
×
118
    return AVAILABLE_FOR_MALE
×
119
  }
120

121
  return undefined
×
122
}
123

124
export function getGenderFilterLabel(
125
  bodyShapes: (WearableGender | GenderFilterOption)[] | undefined
126
): string {
127
  const bodyShape = getBodyShapeValue(bodyShapes)
×
128

129
  if (!bodyShape) {
×
130
    return 'nft_filters.body_shapes.all_items'
×
131
  }
132

133
  const labels: Record<string, string> = {
×
134
    [AVAILABLE_FOR_FEMALE]: 'nft_filters.body_shapes.available_for_female',
135
    [AVAILABLE_FOR_MALE]: 'nft_filters.body_shapes.available_for_male'
136
  }
137

138
  return labels[bodyShape]
×
139
}
140

141
export function getLandLabel({
142
  landStatus,
143
  onlyOnRent = false,
×
144
  onlyOnSale = false
×
145
}: {
146
  landStatus?: LANDFilters
147
  onlyOnRent?: boolean
148
  onlyOnSale?: boolean
149
}) {
150
  if (landStatus === LANDFilters.ONLY_FOR_RENT || onlyOnRent) {
×
151
    return t('nft_land_filters.only_for_rent')
×
152
  }
153

154
  if (landStatus === LANDFilters.ONLY_FOR_SALE || onlyOnSale) {
×
155
    return t('nft_land_filters.only_for_sale')
×
156
  }
157

158
  if (landStatus === LANDFilters.ALL_LAND || !landStatus) {
×
159
    return t('nft_land_filters.all_land')
×
160
  }
161
  return undefined
×
162
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc