Skip to content

Commit 34a871b

Browse files
committed
Removed mageMenu widget dependency
1 parent ee59325 commit 34a871b

File tree

2 files changed

+12
-78
lines changed

2 files changed

+12
-78
lines changed

app/code/Magento/Catalog/view/frontend/web/js/product/breadcrumbs.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,6 @@ define([
1919
menuContainer: '[data-action="navigation"] > ul'
2020
},
2121

22-
/** @inheritdoc */
23-
_init: function () {
24-
var menu;
25-
26-
// render breadcrumbs after navigation menu is loaded.
27-
menu = $(this.options.menuContainer).data('mageMenu');
28-
29-
if (typeof menu === 'undefined') {
30-
this._on($(this.options.menuContainer), {
31-
'menucreate': this._super
32-
});
33-
} else {
34-
this._super();
35-
}
36-
},
37-
3822
/** @inheritdoc */
3923
_render: function () {
4024
this._appendCatalogCrumbs();
@@ -87,18 +71,10 @@ define([
8771
* @private
8872
*/
8973
_getCategoryCrumb: function (menuItem) {
90-
var categoryId,
91-
categoryName,
92-
categoryUrl;
93-
94-
categoryId = /(\d+)/i.exec(menuItem.attr('id'))[0];
95-
categoryName = menuItem.text();
96-
categoryUrl = menuItem.attr('href');
97-
9874
return {
99-
'name': 'category' + categoryId,
100-
'label': categoryName,
101-
'link': categoryUrl,
75+
'name': 'category',
76+
'label': menuItem.text(),
77+
'link': menuItem.attr('href'),
10278
'title': ''
10379
};
10480
},

dev/tests/js/jasmine/tests/app/code/Magento/Catalog/frontend/js/product/breadcrumbs.test.js

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define([
2020
},
2121
defaultContext = require.s.contexts._,
2222
menuSelector = '[data-action="navigation"] > ul',
23-
menuItem = $('<li class="level0"><a href="http://localhost.com/cat1.html" id="ui-id-3">Cat1</a></li>')[0],
23+
menuItem = $('<li class="level0"><a href="http://localhost.com/cat1.html">Cat1</a></li>')[0],
2424

2525
/**
2626
* Create context object.
@@ -107,14 +107,14 @@ define([
107107
});
108108

109109
it('Check _getCategoryCrumb call', function () {
110-
var item = $('<a href="http://localhost.com/cat1.html" id="ui-id-3">Cat1</a>');
110+
var item = $('<a href="http://localhost.com/cat1.html">Cat1</a>');
111111

112112
expect(widget).toBeDefined();
113113
expect(widget).toEqual(jasmine.any(Function));
114114
expect(widget.prototype._getCategoryCrumb).toBeDefined();
115115
expect(widget.prototype._getCategoryCrumb(item)).toEqual(jasmine.objectContaining(
116116
{
117-
'name': 'category3',
117+
'name': 'category',
118118
'label': 'Cat1',
119119
'link': 'http://localhost.com/cat1.html'
120120
}
@@ -223,7 +223,7 @@ define([
223223
expect(result.length).toBe(1);
224224
expect(result[0]).toEqual(jasmine.objectContaining(
225225
{
226-
'name': 'category3',
226+
'name': 'category',
227227
'label': 'Cat1',
228228
'link': 'http://localhost.com/cat1.html'
229229
}
@@ -234,10 +234,10 @@ define([
234234
var result,
235235
menuItems = $(
236236
'<li class="level0 nav-1">' +
237-
'<a href="http://localhost.com/cat1.html" id="ui-id-3">cat1</a>' +
237+
'<a href="http://localhost.com/cat1.html">cat1</a>' +
238238
'<ul>' +
239239
'<li class="level1 nav-1-1">' +
240-
'<a href="http://localhost.com/cat1/cat21.html" id="ui-id-9">cat21</a>' +
240+
'<a href="http://localhost.com/cat1/cat21.html">cat21</a>' +
241241
'</li>' +
242242
'</ul>' +
243243
'</li>'
@@ -253,59 +253,17 @@ define([
253253

254254
context = createContext(widget.prototype);
255255
getParentMenuHandler = widget.prototype._getParentMenuItem.bind(context);
256-
result = getParentMenuHandler($('#ui-id-9'));
256+
result = getParentMenuHandler($('[href="http://localhost.com/cat1/cat21.html"]'));
257257

258258
expect(result).toBeDefined();
259259
expect(result.length).toBe(1);
260260
expect(result[0].tagName.toLowerCase()).toEqual('a');
261-
expect(result.attr('id')).toEqual('ui-id-3');
261+
expect(result.attr('href')).toEqual('http://localhost.com/cat1.html');
262262

263-
result = getParentMenuHandler($('#ui-id-3'));
263+
result = getParentMenuHandler($('[href="http://localhost.com/cat1.html"]'));
264264

265265
expect(result).toBeNull();
266266
});
267-
268-
it('Check _init event binding', function () {
269-
var context,
270-
initMethod;
271-
272-
expect(parentWidget).toBeDefined();
273-
expect(parentWidget).toEqual(jasmine.any(Function));
274-
275-
context = createContext(widget.prototype);
276-
initMethod = widget.prototype._init.bind(context);
277-
278-
spyOn(parentWidget.prototype, '_init');
279-
spyOn(widget.prototype, '_on').and.returnValue(widget);
280-
281-
initMethod();
282-
283-
expect(parentWidget.prototype._init).not.toHaveBeenCalled();
284-
expect(widget.prototype._on).toHaveBeenCalledWith(
285-
jasmine.objectContaining({
286-
selector: menuSelector
287-
}),
288-
{
289-
'menucreate': jasmine.any(Function)
290-
}
291-
);
292-
});
293-
294-
it('Check parent _init call', function () {
295-
var context,
296-
initMethod;
297-
298-
expect(parentWidget).toBeDefined();
299-
expect(parentWidget).toEqual(jasmine.any(Function));
300-
301-
context = createContext(widget.prototype);
302-
initMethod = widget.prototype._init.bind(context);
303-
spyOn(parentWidget.prototype, '_init');
304-
305-
jQuery(menuSelector).attr('data-mage-menu', '<li></li>');
306-
initMethod();
307-
expect(parentWidget.prototype._init).toHaveBeenCalled();
308-
});
309267
});
310268
});
311269
});

0 commit comments

Comments
 (0)