@tapcart/mobile-components 0.11.6 → 0.11.8

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.
Files changed (41) hide show
  1. package/dist/components/hooks/use-infinite-wishlist.d.ts.map +1 -1
  2. package/dist/components/hooks/use-infinite-wishlist.js +15 -2
  3. package/dist/components/ui/badge.d.ts +7 -1
  4. package/dist/components/ui/badge.d.ts.map +1 -1
  5. package/dist/components/ui/badge.js +10 -3
  6. package/dist/components/ui/carousel.d.ts.map +1 -1
  7. package/dist/components/ui/carousel.js +49 -7
  8. package/dist/components/ui/image.d.ts.map +1 -1
  9. package/dist/components/ui/image.js +2 -1
  10. package/dist/components/ui/product-card.d.ts +6 -0
  11. package/dist/components/ui/product-card.d.ts.map +1 -1
  12. package/dist/components/ui/product-card.js +3 -3
  13. package/dist/components/ui/text.d.ts +5 -1
  14. package/dist/components/ui/text.d.ts.map +1 -1
  15. package/dist/components/ui/text.js +8 -2
  16. package/dist/lib/price.d.ts.map +1 -1
  17. package/dist/lib/utils/html.d.ts +16 -0
  18. package/dist/lib/utils/html.d.ts.map +1 -0
  19. package/dist/lib/utils/html.js +56 -0
  20. package/dist/lib/utils.d.ts +6 -0
  21. package/dist/lib/utils.d.ts.map +1 -1
  22. package/dist/styles.css +7 -6
  23. package/dist/tests/utils/html.test.d.ts +2 -0
  24. package/dist/tests/utils/html.test.d.ts.map +1 -0
  25. package/dist/tests/utils/html.test.js +104 -0
  26. package/package.json +1 -1
  27. package/dist/lib/isVersion20.util.d.ts +0 -2
  28. package/dist/lib/isVersion20.util.d.ts.map +0 -1
  29. package/dist/lib/isVersion20.util.js +0 -7
  30. package/dist/lib/utils.wishlist.test.d.ts +0 -2
  31. package/dist/lib/utils.wishlist.test.d.ts.map +0 -1
  32. package/dist/lib/utils.wishlist.test.js +0 -108
  33. package/dist/tests/addItemToWishlist/addItemToWishlist.wishlistId.test.d.ts +0 -2
  34. package/dist/tests/addItemToWishlist/addItemToWishlist.wishlistId.test.d.ts.map +0 -1
  35. package/dist/tests/addItemToWishlist/addItemToWishlist.wishlistId.test.js +0 -50
  36. package/dist/tests/removeItemFromWishlist/removeItemFromWishlist.test.d.ts +0 -2
  37. package/dist/tests/removeItemFromWishlist/removeItemFromWishlist.test.d.ts.map +0 -1
  38. package/dist/tests/removeItemFromWishlist/removeItemFromWishlist.test.js +0 -268
  39. package/dist/tests/removeItemFromWishlists/removeItemFromWishlist.test.d.ts +0 -2
  40. package/dist/tests/removeItemFromWishlists/removeItemFromWishlist.test.d.ts.map +0 -1
  41. package/dist/tests/removeItemFromWishlists/removeItemFromWishlist.test.js +0 -268
@@ -1,268 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { removeItemFromWishlist } from "../../lib/utils";
11
- describe("removeItemFromWishlist", () => {
12
- let mockTapcart;
13
- let consoleErrorSpy;
14
- let consoleLogSpy;
15
- beforeEach(() => {
16
- // Reset mocks before each test
17
- jest.clearAllMocks();
18
- // Spy on console methods
19
- consoleErrorSpy = jest.spyOn(console, "error").mockImplementation();
20
- consoleLogSpy = jest.spyOn(console, "log").mockImplementation();
21
- // Default mock Tapcart instance
22
- mockTapcart = {
23
- action: jest.fn(),
24
- variables: {
25
- customer: { id: "customer-123" },
26
- wishlists: [
27
- {
28
- id: "wishlist-1",
29
- items: [
30
- {
31
- productId: "gid://shopify/Product/123",
32
- variantId: "gid://shopify/ProductVariant/456",
33
- },
34
- ],
35
- },
36
- ],
37
- },
38
- };
39
- });
40
- afterEach(() => {
41
- consoleErrorSpy.mockRestore();
42
- consoleLogSpy.mockRestore();
43
- });
44
- describe("validation and error handling", () => {
45
- it("should return false when Tapcart instance is missing", () => __awaiter(void 0, void 0, void 0, function* () {
46
- const result = yield removeItemFromWishlist({
47
- Tapcart: null,
48
- productId: "gid://shopify/Product/123",
49
- selectedVariantId: "gid://shopify/ProductVariant/456",
50
- });
51
- expect(result).toBe(false);
52
- expect(consoleErrorSpy).toHaveBeenCalledWith("Tapcart instance is missing");
53
- }));
54
- it("should handle errors gracefully and return false", () => __awaiter(void 0, void 0, void 0, function* () {
55
- // Mock Tapcart.action to throw an error
56
- mockTapcart.action = jest.fn().mockImplementation(() => {
57
- throw new Error("Test error");
58
- });
59
- const result = yield removeItemFromWishlist({
60
- Tapcart: mockTapcart,
61
- productId: "gid://shopify/Product/123",
62
- selectedVariantId: "gid://shopify/ProductVariant/456",
63
- });
64
- expect(result).toBe(false);
65
- expect(consoleErrorSpy).toHaveBeenCalledWith("Failed to remove from wishlist", expect.any(Error));
66
- }));
67
- });
68
- describe("variant ID handling", () => {
69
- it("should return false when variant ID is missing from both wishlist entry and selectedVariantId", () => __awaiter(void 0, void 0, void 0, function* () {
70
- // Mock Tapcart with no variant ID in wishlist entry
71
- mockTapcart.variables.wishlists[0].items[0].variantId = null;
72
- const result = yield removeItemFromWishlist({
73
- Tapcart: mockTapcart,
74
- productId: "gid://shopify/Product/123",
75
- selectedVariantId: null,
76
- });
77
- expect(result).toBe(false);
78
- expect(consoleErrorSpy).toHaveBeenCalledWith("Missing variant id for wishlist removal");
79
- expect(mockTapcart.action).not.toHaveBeenCalled();
80
- }));
81
- it("should use variant ID from wishlist entry when available", () => __awaiter(void 0, void 0, void 0, function* () {
82
- // Mock Tapcart.action to return a success result
83
- mockTapcart.action = jest.fn().mockResolvedValue(true);
84
- const result = yield removeItemFromWishlist({
85
- Tapcart: mockTapcart,
86
- productId: "gid://shopify/Product/123",
87
- selectedVariantId: null,
88
- });
89
- expect(result).toBe(true);
90
- expect(mockTapcart.action).toHaveBeenCalledWith("wishlist/item/remove", {
91
- productId: "gid://shopify/Product/123",
92
- variantId: "456",
93
- wishlistId: "wishlist-1",
94
- });
95
- }));
96
- it("should use selectedVariantId when wishlist entry has no variant ID", () => __awaiter(void 0, void 0, void 0, function* () {
97
- // Mock Tapcart with no variant ID in wishlist entry
98
- mockTapcart.variables.wishlists[0].items[0].variantId = null;
99
- // Mock Tapcart.action to return a success result
100
- mockTapcart.action = jest.fn().mockResolvedValue(true);
101
- const result = yield removeItemFromWishlist({
102
- Tapcart: mockTapcart,
103
- productId: "gid://shopify/Product/123",
104
- selectedVariantId: "gid://shopify/ProductVariant/789",
105
- });
106
- expect(result).toBe(true);
107
- expect(mockTapcart.action).toHaveBeenCalledWith("wishlist/item/remove", {
108
- productId: "gid://shopify/Product/123",
109
- variantId: "789",
110
- wishlistId: "wishlist-1",
111
- });
112
- }));
113
- it("should prioritize wishlist entry variant ID over selectedVariantId", () => __awaiter(void 0, void 0, void 0, function* () {
114
- // Mock Tapcart.action to return a success result
115
- mockTapcart.action = jest.fn().mockResolvedValue(true);
116
- const result = yield removeItemFromWishlist({
117
- Tapcart: mockTapcart,
118
- productId: "gid://shopify/Product/123",
119
- selectedVariantId: "gid://shopify/ProductVariant/789",
120
- });
121
- expect(result).toBe(true);
122
- expect(mockTapcart.action).toHaveBeenCalledWith("wishlist/item/remove", {
123
- productId: "gid://shopify/Product/123",
124
- variantId: "456",
125
- wishlistId: "wishlist-1",
126
- });
127
- }));
128
- });
129
- describe("wishlist ID handling", () => {
130
- it("should return false when wishlist ID is missing", () => __awaiter(void 0, void 0, void 0, function* () {
131
- // Mock Tapcart with no wishlist ID
132
- mockTapcart.variables.wishlists = [];
133
- const result = yield removeItemFromWishlist({
134
- Tapcart: mockTapcart,
135
- productId: "gid://shopify/Product/123",
136
- selectedVariantId: "gid://shopify/ProductVariant/456",
137
- });
138
- expect(result).toBe(false);
139
- expect(consoleErrorSpy).toHaveBeenCalledWith("Missing wishlist id for wishlist removal");
140
- expect(mockTapcart.action).not.toHaveBeenCalled();
141
- }));
142
- it("should use wishlist ID from wishlist entry when available", () => __awaiter(void 0, void 0, void 0, function* () {
143
- // Mock Tapcart.action to return a success result
144
- mockTapcart.action = jest.fn().mockResolvedValue(true);
145
- const result = yield removeItemFromWishlist({
146
- Tapcart: mockTapcart,
147
- productId: "gid://shopify/Product/123",
148
- selectedVariantId: "gid://shopify/ProductVariant/456",
149
- });
150
- expect(result).toBe(true);
151
- expect(mockTapcart.action).toHaveBeenCalledWith("wishlist/item/remove", {
152
- productId: "gid://shopify/Product/123",
153
- variantId: "456",
154
- wishlistId: "wishlist-1", // From wishlist entry
155
- });
156
- }));
157
- });
158
- describe("GID handling", () => {
159
- it("should extract IDs from GID format", () => __awaiter(void 0, void 0, void 0, function* () {
160
- // Mock Tapcart with GID format
161
- mockTapcart.variables.wishlists[0].items[0].productId = "gid://shopify/Product/123?param=value";
162
- mockTapcart.variables.wishlists[0].items[0].variantId = "gid://shopify/ProductVariant/456?param=value";
163
- // Mock Tapcart.action to return a success result
164
- mockTapcart.action = jest.fn().mockResolvedValue(true);
165
- const result = yield removeItemFromWishlist({
166
- Tapcart: mockTapcart,
167
- productId: "gid://shopify/Product/123?param=value",
168
- selectedVariantId: "gid://shopify/ProductVariant/789?param=value",
169
- });
170
- expect(result).toBe(true);
171
- expect(mockTapcart.action).toHaveBeenCalledWith("wishlist/item/remove", {
172
- productId: "gid://shopify/Product/123?param=value",
173
- variantId: "456",
174
- wishlistId: "wishlist-1",
175
- });
176
- }));
177
- it("should handle plain IDs without GID format", () => __awaiter(void 0, void 0, void 0, function* () {
178
- // Mock Tapcart with plain IDs
179
- mockTapcart.variables.wishlists[0].items[0].productId = "123";
180
- mockTapcart.variables.wishlists[0].items[0].variantId = "456";
181
- // Mock Tapcart.action to return a success result
182
- mockTapcart.action = jest.fn().mockResolvedValue(true);
183
- const result = yield removeItemFromWishlist({
184
- Tapcart: mockTapcart,
185
- productId: "123",
186
- selectedVariantId: "789",
187
- });
188
- expect(result).toBe(true);
189
- expect(mockTapcart.action).toHaveBeenCalledWith("wishlist/item/remove", {
190
- productId: "123",
191
- variantId: "456",
192
- wishlistId: "wishlist-1",
193
- });
194
- }));
195
- it("should use the provided wishlistId when supplied", () => __awaiter(void 0, void 0, void 0, function* () {
196
- mockTapcart.variables.wishlists = [];
197
- mockTapcart.action = jest.fn().mockResolvedValue(true);
198
- const result = yield removeItemFromWishlist({
199
- Tapcart: mockTapcart,
200
- productId: "gid://shopify/Product/123",
201
- selectedVariantId: "gid://shopify/ProductVariant/456",
202
- wishlistId: "gid://shopify/Wishlist/789",
203
- });
204
- expect(result).toBe(true);
205
- expect(mockTapcart.action).toHaveBeenCalledWith("wishlist/item/remove", {
206
- productId: "gid://shopify/Product/123",
207
- variantId: "456",
208
- wishlistId: "789",
209
- });
210
- }));
211
- });
212
- describe("edge cases", () => {
213
- it("should handle undefined wishlists array", () => __awaiter(void 0, void 0, void 0, function* () {
214
- mockTapcart.variables.wishlists = undefined;
215
- const result = yield removeItemFromWishlist({
216
- Tapcart: mockTapcart,
217
- productId: "gid://shopify/Product/123",
218
- selectedVariantId: "gid://shopify/ProductVariant/456",
219
- });
220
- expect(result).toBe(false);
221
- expect(consoleErrorSpy).toHaveBeenCalledWith("Missing wishlist id for wishlist removal");
222
- expect(mockTapcart.action).not.toHaveBeenCalled();
223
- }));
224
- it("should handle empty wishlists array", () => __awaiter(void 0, void 0, void 0, function* () {
225
- mockTapcart.variables.wishlists = [];
226
- const result = yield removeItemFromWishlist({
227
- Tapcart: mockTapcart,
228
- productId: "gid://shopify/Product/123",
229
- selectedVariantId: "gid://shopify/ProductVariant/456",
230
- });
231
- expect(result).toBe(false);
232
- expect(consoleErrorSpy).toHaveBeenCalledWith("Missing wishlist id for wishlist removal");
233
- expect(mockTapcart.action).not.toHaveBeenCalled();
234
- }));
235
- it("should handle wishlist entry with undefined variantId", () => __awaiter(void 0, void 0, void 0, function* () {
236
- mockTapcart.variables.wishlists[0].items[0].variantId = undefined;
237
- // Mock Tapcart.action to return a success result
238
- mockTapcart.action = jest.fn().mockResolvedValue(true);
239
- const result = yield removeItemFromWishlist({
240
- Tapcart: mockTapcart,
241
- productId: "gid://shopify/Product/123",
242
- selectedVariantId: "gid://shopify/ProductVariant/789",
243
- });
244
- expect(result).toBe(true);
245
- expect(mockTapcart.action).toHaveBeenCalledWith("wishlist/item/remove", {
246
- productId: "gid://shopify/Product/123",
247
- variantId: "789",
248
- wishlistId: "wishlist-1",
249
- });
250
- }));
251
- it("should handle wishlist entry with null variantId", () => __awaiter(void 0, void 0, void 0, function* () {
252
- mockTapcart.variables.wishlists[0].items[0].variantId = null;
253
- // Mock Tapcart.action to return a success result
254
- mockTapcart.action = jest.fn().mockResolvedValue(true);
255
- const result = yield removeItemFromWishlist({
256
- Tapcart: mockTapcart,
257
- productId: "gid://shopify/Product/123",
258
- selectedVariantId: "gid://shopify/ProductVariant/789",
259
- });
260
- expect(result).toBe(true);
261
- expect(mockTapcart.action).toHaveBeenCalledWith("wishlist/item/remove", {
262
- productId: "gid://shopify/Product/123",
263
- variantId: "789",
264
- wishlistId: "wishlist-1",
265
- });
266
- }));
267
- });
268
- });