@tapcart/mobile-components 0.8.10 → 0.8.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ui/image.js +1 -1
- package/dist/lib/cart.util.js +1 -1
- package/dist/lib/cart.util.test.js +73 -0
- package/dist/styles.css +15 -0
- package/package.json +1 -1
|
@@ -66,7 +66,7 @@ function ImagePreload({ imgAttributes }) {
|
|
|
66
66
|
*/
|
|
67
67
|
export const Image = React.forwardRef((_a, ref) => {
|
|
68
68
|
var _b, _c;
|
|
69
|
-
var { alt, aspectRatio, crop = "center", data, decoding = "async", height = "auto", loader = shopifyLoader, loading = "
|
|
69
|
+
var { alt, aspectRatio, crop = "center", data, decoding = "async", height = "auto", loader = shopifyLoader, loading = "eager", sizes, src, imageWrapperStyles, imageRadius, srcSetOptions = {
|
|
70
70
|
intervals: 15,
|
|
71
71
|
startingWidth: 100,
|
|
72
72
|
incrementSize: 100,
|
package/dist/lib/cart.util.js
CHANGED
|
@@ -145,7 +145,7 @@ const getTotalDiscountedPrice = (totalCompareAtPrice, discountsTotalAmount, sale
|
|
|
145
145
|
(giftCardsTotalAmount === undefined || isNaN(giftCardsTotalAmount)
|
|
146
146
|
? 0
|
|
147
147
|
: giftCardsTotalAmount);
|
|
148
|
-
return isNaN(total) ? 0 : total;
|
|
148
|
+
return isNaN(total) ? 0 : Math.max(0, total);
|
|
149
149
|
};
|
|
150
150
|
const getTotalSavedAmount = (cart) => {
|
|
151
151
|
const salesAmount = getSalesAmount(cart);
|
|
@@ -147,5 +147,78 @@ describe("cart-provider.util", () => {
|
|
|
147
147
|
// 100 (compare) - 10 (discount) - 20 (sale) - 5 (gift card) = 65
|
|
148
148
|
expect(result.totalDiscountedPrice).toBe(125);
|
|
149
149
|
});
|
|
150
|
+
it("should never return negative or NaN values for totalDiscountedPrice", () => {
|
|
151
|
+
// Test case 1: Normal case with valid data
|
|
152
|
+
const normalCart = Object.assign(Object.assign({}, baseCartData), { items: [
|
|
153
|
+
{
|
|
154
|
+
id: "line1",
|
|
155
|
+
quantity: 1,
|
|
156
|
+
productId: "prod1",
|
|
157
|
+
variantId: "var1",
|
|
158
|
+
productDetails: {},
|
|
159
|
+
variantDetails: {
|
|
160
|
+
compareAtPrice: { amount: "100.00", currencyCode: "USD" },
|
|
161
|
+
price: { amount: "80.00", currencyCode: "USD" },
|
|
162
|
+
},
|
|
163
|
+
discounts: [],
|
|
164
|
+
cost: { totalAmount: { amount: "80.00", currencyCode: "USD" } },
|
|
165
|
+
},
|
|
166
|
+
] });
|
|
167
|
+
let result = getCalculatedCartData(normalCart);
|
|
168
|
+
expect(result.totalDiscountedPrice).not.toBeLessThan(0);
|
|
169
|
+
expect(isNaN(result.totalDiscountedPrice)).toBe(false);
|
|
170
|
+
// Test case 2: Edge case with extreme discounts that exceed item price
|
|
171
|
+
const extremeDiscountCart = Object.assign(Object.assign({}, baseCartData), { items: [
|
|
172
|
+
{
|
|
173
|
+
id: "line1",
|
|
174
|
+
quantity: 1,
|
|
175
|
+
productId: "prod1",
|
|
176
|
+
variantId: "var1",
|
|
177
|
+
productDetails: {},
|
|
178
|
+
variantDetails: {
|
|
179
|
+
compareAtPrice: { amount: "50.00", currencyCode: "USD" },
|
|
180
|
+
price: { amount: "20.00", currencyCode: "USD" },
|
|
181
|
+
},
|
|
182
|
+
discounts: [
|
|
183
|
+
{
|
|
184
|
+
amount: 100,
|
|
185
|
+
type: "LINE_ITEM",
|
|
186
|
+
code: "HUGE_DISCOUNT",
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
cost: { totalAmount: { amount: "20.00", currencyCode: "USD" } },
|
|
190
|
+
},
|
|
191
|
+
], discountAllocations: [
|
|
192
|
+
{
|
|
193
|
+
targetType: DiscountApplicationTargetType.LineItem,
|
|
194
|
+
discountedAmount: { amount: "100.00", currencyCode: "USD" },
|
|
195
|
+
code: "HUGE_DISCOUNT",
|
|
196
|
+
},
|
|
197
|
+
] });
|
|
198
|
+
result = getCalculatedCartData(extremeDiscountCart);
|
|
199
|
+
expect(result.totalDiscountedPrice).not.toBeLessThan(0);
|
|
200
|
+
expect(isNaN(result.totalDiscountedPrice)).toBe(false);
|
|
201
|
+
// Test case 3: Edge case with missing price data
|
|
202
|
+
const missingDataCart = Object.assign(Object.assign({}, baseCartData), { items: [
|
|
203
|
+
{
|
|
204
|
+
id: "line1",
|
|
205
|
+
quantity: 1,
|
|
206
|
+
productId: "prod1",
|
|
207
|
+
variantId: "var1",
|
|
208
|
+
productDetails: {},
|
|
209
|
+
variantDetails: {
|
|
210
|
+
compareAtPrice: { amount: "", currencyCode: "USD" },
|
|
211
|
+
price: { amount: null, currencyCode: "USD" }, // Null amount
|
|
212
|
+
},
|
|
213
|
+
discounts: [],
|
|
214
|
+
cost: {
|
|
215
|
+
totalAmount: { amount: undefined, currencyCode: "USD" },
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
] });
|
|
219
|
+
result = getCalculatedCartData(missingDataCart);
|
|
220
|
+
expect(result.totalDiscountedPrice).not.toBeLessThan(0);
|
|
221
|
+
expect(isNaN(result.totalDiscountedPrice)).toBe(false);
|
|
222
|
+
});
|
|
150
223
|
});
|
|
151
224
|
});
|
package/dist/styles.css
CHANGED
|
@@ -980,6 +980,9 @@ video {
|
|
|
980
980
|
.h-2\.5 {
|
|
981
981
|
height: 0.625rem;
|
|
982
982
|
}
|
|
983
|
+
.h-20 {
|
|
984
|
+
height: 5rem;
|
|
985
|
+
}
|
|
983
986
|
.h-24 {
|
|
984
987
|
height: 6rem;
|
|
985
988
|
}
|
|
@@ -1013,6 +1016,9 @@ video {
|
|
|
1013
1016
|
.h-\[1px\] {
|
|
1014
1017
|
height: 1px;
|
|
1015
1018
|
}
|
|
1019
|
+
.h-\[20vh\] {
|
|
1020
|
+
height: 20vh;
|
|
1021
|
+
}
|
|
1016
1022
|
.h-\[22px\] {
|
|
1017
1023
|
height: 22px;
|
|
1018
1024
|
}
|
|
@@ -1118,6 +1124,9 @@ video {
|
|
|
1118
1124
|
.w-\[40px\] {
|
|
1119
1125
|
width: 40px;
|
|
1120
1126
|
}
|
|
1127
|
+
.w-\[54px\] {
|
|
1128
|
+
width: 54px;
|
|
1129
|
+
}
|
|
1121
1130
|
.w-auto {
|
|
1122
1131
|
width: auto;
|
|
1123
1132
|
}
|
|
@@ -1390,6 +1399,9 @@ video {
|
|
|
1390
1399
|
.gap-2 {
|
|
1391
1400
|
gap: 0.5rem;
|
|
1392
1401
|
}
|
|
1402
|
+
.gap-2\.5 {
|
|
1403
|
+
gap: 0.625rem;
|
|
1404
|
+
}
|
|
1393
1405
|
.gap-4 {
|
|
1394
1406
|
gap: 1rem;
|
|
1395
1407
|
}
|
|
@@ -1810,6 +1822,9 @@ video {
|
|
|
1810
1822
|
.pl-2 {
|
|
1811
1823
|
padding-left: 0.5rem;
|
|
1812
1824
|
}
|
|
1825
|
+
.pl-3 {
|
|
1826
|
+
padding-left: 0.75rem;
|
|
1827
|
+
}
|
|
1813
1828
|
.pl-4 {
|
|
1814
1829
|
padding-left: 1rem;
|
|
1815
1830
|
}
|