Skip to content

Commit

Permalink
Removed mageMenu widget dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
vovayatsyuk committed May 24, 2018
1 parent a24105d commit 7b1d1b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,6 @@ define([
menuContainer: '[data-action="navigation"] > ul'
},

/** @inheritdoc */
_init: function () {
var menu,
originalInit = this._super.bind(this);

// render breadcrumbs after navigation menu is loaded.
menu = $(this.options.menuContainer).data('mageMenu');

if (typeof menu === 'undefined') {
$(this.options.menuContainer).on('menucreate', function () {
originalInit();
});
} else {
this._super();
}
},

/** @inheritdoc */
_render: function () {
this._appendCatalogCrumbs();
Expand Down Expand Up @@ -88,14 +71,10 @@ define([
* @private
*/
_getCategoryCrumb: function (menuItem) {
var categoryId = /(\d+)/i.exec(menuItem.attr('id'))[0],
categoryName = menuItem.text(),
categoryUrl = menuItem.attr('href');

return {
'name': 'category' + categoryId,
'label': categoryName,
'link': categoryUrl,
'name': 'category',
'label': menuItem.text(),
'link': menuItem.attr('href'),
'title': ''
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define([
'Magento_Theme/js/model/breadcrumb-list': jasmine.createSpyObj(['push'])
},
defaultContext = require.s.contexts._,
menuItem = $('<li class="level0"><a href="http://localhost.com/cat1.html" id="ui-id-3">Cat1</a></li>')[0],
menuItem = $('<li class="level0"><a href="http://localhost.com/cat1.html">Cat1</a></li>')[0],

/**
* Create context object.
Expand Down Expand Up @@ -112,14 +112,14 @@ define([
});

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

expect(widget).toBeDefined();
expect(widget).toEqual(jasmine.any(Function));
expect(widget.prototype._getCategoryCrumb).toBeDefined();
expect(widget.prototype._getCategoryCrumb(item)).toEqual(jasmine.objectContaining(
{
'name': 'category3',
'name': 'category',
'label': 'Cat1',
'link': 'http://localhost.com/cat1.html'
}
Expand Down Expand Up @@ -228,7 +228,7 @@ define([
expect(result.length).toBe(1);
expect(result[0]).toEqual(jasmine.objectContaining(
{
'name': 'category3',
'name': 'category',
'label': 'Cat1',
'link': 'http://localhost.com/cat1.html'
}
Expand All @@ -239,10 +239,10 @@ define([
var result,
menuItems = $(
'<li class="level0 nav-1">' +
'<a href="http://localhost.com/cat1.html" id="ui-id-3">cat1</a>' +
'<a href="http://localhost.com/cat1.html">cat1</a>' +
'<ul>' +
'<li class="level1 nav-1-1">' +
'<a href="http://localhost.com/cat1/cat21.html" id="ui-id-9">cat21</a>' +
'<a href="http://localhost.com/cat1/cat21.html">cat21</a>' +
'</li>' +
'</ul>' +
'</li>'
Expand All @@ -258,14 +258,14 @@ define([

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

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

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

expect(result).toBeNull();
});
Expand Down

0 comments on commit 7b1d1b6

Please sign in to comment.