Skip to content

Commit e35e190

Browse files
ENGCOM-1539: Removed mageMenu widget dependency from breadcrumbs component #15178
2 parents c7336a4 + 68e8a50 commit e35e190

File tree

2 files changed

+12
-80
lines changed

2 files changed

+12
-80
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 & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ define([
1313

1414
var injector = new Squire(),
1515
widget,
16-
parentWidget,
1716
menuContainer,
1817
mocks = {
1918
'Magento_Theme/js/model/breadcrumb-list': jasmine.createSpyObj(['push'])
2019
},
2120
defaultContext = require.s.contexts._,
2221
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],
22+
menuItem = $('<li class="level0"><a href="http://localhost.com/cat1.html">Cat1</a></li>')[0],
2423

2524
/**
2625
* Create context object.
@@ -44,7 +43,6 @@ define([
4443
'Magento_Theme/js/view/breadcrumbs'
4544
], function (mixin, breadcrumb) {
4645
widget = mixin(breadcrumb);
47-
parentWidget = breadcrumb;
4846
done();
4947
}
5048
);
@@ -107,14 +105,14 @@ define([
107105
});
108106

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

112110
expect(widget).toBeDefined();
113111
expect(widget).toEqual(jasmine.any(Function));
114112
expect(widget.prototype._getCategoryCrumb).toBeDefined();
115113
expect(widget.prototype._getCategoryCrumb(item)).toEqual(jasmine.objectContaining(
116114
{
117-
'name': 'category3',
115+
'name': 'category',
118116
'label': 'Cat1',
119117
'link': 'http://localhost.com/cat1.html'
120118
}
@@ -223,7 +221,7 @@ define([
223221
expect(result.length).toBe(1);
224222
expect(result[0]).toEqual(jasmine.objectContaining(
225223
{
226-
'name': 'category3',
224+
'name': 'category',
227225
'label': 'Cat1',
228226
'link': 'http://localhost.com/cat1.html'
229227
}
@@ -234,10 +232,10 @@ define([
234232
var result,
235233
menuItems = $(
236234
'<li class="level0 nav-1">' +
237-
'<a href="http://localhost.com/cat1.html" id="ui-id-3">cat1</a>' +
235+
'<a href="http://localhost.com/cat1.html">cat1</a>' +
238236
'<ul>' +
239237
'<li class="level1 nav-1-1">' +
240-
'<a href="http://localhost.com/cat1/cat21.html" id="ui-id-9">cat21</a>' +
238+
'<a href="http://localhost.com/cat1/cat21.html">cat21</a>' +
241239
'</li>' +
242240
'</ul>' +
243241
'</li>'
@@ -253,59 +251,17 @@ define([
253251

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

258256
expect(result).toBeDefined();
259257
expect(result.length).toBe(1);
260258
expect(result[0].tagName.toLowerCase()).toEqual('a');
261-
expect(result.attr('id')).toEqual('ui-id-3');
259+
expect(result.attr('href')).toEqual('http://localhost.com/cat1.html');
262260

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

265263
expect(result).toBeNull();
266264
});
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-
});
309265
});
310266
});
311267
});

0 commit comments

Comments
 (0)