Skip to content

Commit fd033b6

Browse files
committed
AC-14607: Wishlist count not displayed on homepage/other pages except wishlist page in customer menu
Fix ESLint error
1 parent 975b91d commit fd033b6

File tree

1 file changed

+64
-59
lines changed

1 file changed

+64
-59
lines changed
Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright 2025 Adobe
3-
* All rights reserved.
3+
* All Rights Reserved.
44
*/
55

66
define([
@@ -20,10 +20,13 @@ define([
2020
get: jasmine.createSpy('get')
2121
};
2222

23+
// Helper function to set up subscribe callback
24+
function setupSubscribeCallback(callback) {
25+
subscribeCallback = callback;
26+
}
27+
2328
wishlistDataMock = {
24-
subscribe: jasmine.createSpy('subscribe').and.callFake(function (callback) {
25-
subscribeCallback = callback;
26-
})
29+
subscribe: jasmine.createSpy('subscribe').and.callFake(setupSubscribeCallback)
2730
};
2831

2932
customerDataMock.get.and.returnValue(wishlistDataMock);
@@ -39,34 +42,39 @@ define([
3942
return this;
4043
}
4144
};
42-
45+
4346
// Add the extend method that Magento components typically have
4447
WishlistComponent.extend = function (extensions) {
4548
var ExtendedComponent = function () {};
49+
4650
ExtendedComponent.prototype = Object.create(WishlistComponent.prototype);
47-
51+
4852
// Copy the extensions to the prototype
4953
for (var key in extensions) {
5054
if (extensions.hasOwnProperty(key)) {
5155
ExtendedComponent.prototype[key] = extensions[key];
5256
}
5357
}
54-
58+
5559
// Add the extend method to the new component
5660
ExtendedComponent.extend = WishlistComponent.extend;
57-
61+
5862
// Add _super method for each extended method
5963
for (var methodName in extensions) {
60-
if (extensions.hasOwnProperty(methodName) && typeof extensions[methodName] === 'function') {
61-
var originalMethod = WishlistComponent.prototype[methodName];
62-
if (originalMethod) {
63-
ExtendedComponent.prototype['_super'] = function () {
64-
return originalMethod.apply(this, arguments);
65-
};
66-
}
64+
if (!extensions.hasOwnProperty(methodName) || typeof extensions[methodName] !== 'function') {
65+
continue;
6766
}
67+
68+
var originalMethod = WishlistComponent.prototype[methodName];
69+
if (!originalMethod) {
70+
continue;
71+
}
72+
73+
ExtendedComponent.prototype['_super'] = function () {
74+
return originalMethod.apply(this, arguments);
75+
};
6876
}
69-
77+
7078
return ExtendedComponent;
7179
};
7280

@@ -78,50 +86,50 @@ define([
7886
it('should call _super() during initialization', function () {
7987
var instance = new mixin();
8088
spyOn(instance, '_super').and.callThrough();
81-
89+
8290
instance.initialize();
83-
91+
8492
expect(instance._super).toHaveBeenCalled();
8593
});
8694

8795
it('should reload wishlist customer data on initialization', function () {
8896
var instance = new mixin();
89-
97+
9098
instance.initialize();
91-
99+
92100
expect(customerData.reload).toHaveBeenCalledWith(['wishlist'], true);
93101
});
94102

95103
it('should get wishlist data from customer data', function () {
96104
var instance = new mixin();
97-
105+
98106
instance.initialize();
99-
107+
100108
expect(customerData.get).toHaveBeenCalledWith('wishlist');
101109
});
102110

103111
it('should return the instance after initialization', function () {
104-
var instance = new mixin();
105-
var result = instance.initialize();
106-
112+
var instance = new mixin(),
113+
result = instance.initialize();
114+
107115
expect(result).toBe(instance);
108116
});
109117
});
110118

111119
describe('Wishlist subscription', function () {
112120
it('should subscribe to wishlist data updates', function () {
113121
var instance = new mixin();
114-
122+
115123
instance.initialize();
116-
124+
117125
expect(wishlistDataMock.subscribe).toHaveBeenCalledWith(jasmine.any(Function));
118126
});
119127

120128
it('should handle undefined counter gracefully', function () {
121129
var instance = new mixin();
122-
130+
123131
instance.initialize();
124-
132+
125133
// Call with undefined counter
126134
expect(function () {
127135
subscribeCallback({ counter: undefined });
@@ -130,9 +138,9 @@ define([
130138

131139
it('should handle null counter gracefully', function () {
132140
var instance = new mixin();
133-
141+
134142
instance.initialize();
135-
143+
136144
// Call with null counter
137145
expect(function () {
138146
subscribeCallback({ counter: null });
@@ -141,9 +149,9 @@ define([
141149

142150
it('should handle missing counter property gracefully', function () {
143151
var instance = new mixin();
144-
152+
145153
instance.initialize();
146-
154+
147155
// Call with no counter property
148156
expect(function () {
149157
subscribeCallback({});
@@ -154,9 +162,9 @@ define([
154162
describe('Subscription callback behavior', function () {
155163
it('should handle counter updates when counters exist', function () {
156164
var instance = new mixin();
157-
165+
158166
instance.initialize();
159-
167+
160168
// Call with counter update
161169
expect(function () {
162170
subscribeCallback({ counter: 3 });
@@ -165,9 +173,9 @@ define([
165173

166174
it('should handle string counter values', function () {
167175
var instance = new mixin();
168-
176+
169177
instance.initialize();
170-
178+
171179
// Call with string counter
172180
expect(function () {
173181
subscribeCallback({ counter: '7' });
@@ -176,9 +184,9 @@ define([
176184

177185
it('should handle zero counter value', function () {
178186
var instance = new mixin();
179-
187+
180188
instance.initialize();
181-
189+
182190
// Call with zero counter
183191
expect(function () {
184192
subscribeCallback({ counter: 0 });
@@ -187,9 +195,9 @@ define([
187195

188196
it('should handle multiple counter updates', function () {
189197
var instance = new mixin();
190-
198+
191199
instance.initialize();
192-
200+
193201
// Multiple updates
194202
expect(function () {
195203
subscribeCallback({ counter: 1 });
@@ -200,9 +208,9 @@ define([
200208

201209
it('should handle rapid counter updates', function () {
202210
var instance = new mixin();
203-
211+
204212
instance.initialize();
205-
213+
206214
// Rapid updates
207215
expect(function () {
208216
for (var i = 0; i < 10; i++) {
@@ -215,61 +223,58 @@ define([
215223
describe('Mixin functionality', function () {
216224
it('should extend the WishlistComponent correctly', function () {
217225
var instance = new mixin();
218-
226+
219227
expect(instance).toBeDefined();
220228
expect(typeof instance.initialize).toBe('function');
221229
});
222230

223231
it('should maintain the original component structure', function () {
224232
var instance = new mixin();
225-
233+
226234
// The mixin should add functionality but not break the original
227235
expect(instance.initialize).toBeDefined();
228236
});
229237

230238
it('should handle initialization multiple times', function () {
231-
var instance = new mixin();
232-
233-
// First initialization
234-
var result1 = instance.initialize();
239+
var instance = new mixin(),
240+
result1 = instance.initialize(), // First initialization
241+
result2 = instance.initialize(); // Second initialization
242+
235243
expect(result1).toBe(instance);
236-
237-
// Second initialization
238-
var result2 = instance.initialize();
239244
expect(result2).toBe(instance);
240245
});
241246
});
242247

243248
describe('Error handling', function () {
244249
it('should throw error when customerData.get returns null', function () {
245250
customerDataMock.get.and.returnValue(null);
246-
251+
247252
var instance = new mixin();
248-
253+
249254
expect(function () {
250255
instance.initialize();
251256
}).toThrow();
252257
});
253258

254259
it('should throw error when customerData.get returns undefined', function () {
255260
customerDataMock.get.and.returnValue(undefined);
256-
261+
257262
var instance = new mixin();
258-
263+
259264
expect(function () {
260265
instance.initialize();
261266
}).toThrow();
262267
});
263268

264269
it('should throw error when wishlist data has no subscribe method', function () {
265270
customerDataMock.get.and.returnValue({});
266-
271+
267272
var instance = new mixin();
268-
273+
269274
expect(function () {
270275
instance.initialize();
271276
}).toThrow();
272277
});
273278
});
274279
});
275-
});
280+
});

0 commit comments

Comments
 (0)