diff --git a/app/common/lib/menuUtil.js b/app/common/lib/menuUtil.js index 8409b89f74b..103ddc9ce9e 100644 --- a/app/common/lib/menuUtil.js +++ b/app/common/lib/menuUtil.js @@ -161,13 +161,7 @@ const isItemValid = (currentItem, previousItem) => { * - entries which don't have a label or type */ module.exports.sanitizeTemplateItems = (template) => { - const reduced = template.reduce((previousValue, currentValue, currentIndex, array) => { - const result = currentIndex === 1 ? [] : previousValue - if (currentIndex === 1) { - if (isItemValid(previousValue)) { - result.push(previousValue) - } - } + const reduced = template.reduce((result, currentValue, currentIndex, array) => { const previousItem = result.length > 0 ? result[result.length - 1] : undefined @@ -175,7 +169,7 @@ module.exports.sanitizeTemplateItems = (template) => { result.push(currentValue) } return result - }) + }, []) const result = Array.isArray(reduced) ? reduced diff --git a/test/unit/app/common/lib/menuUtilTest.js b/test/unit/app/common/lib/menuUtilTest.js index b3d61a28016..128457c7547 100644 --- a/test/unit/app/common/lib/menuUtilTest.js +++ b/test/unit/app/common/lib/menuUtilTest.js @@ -285,5 +285,11 @@ describe('menuUtil tests', function () { const expectedResult = [] assert.deepEqual(result, expectedResult) }) + it('supports empty arrays', function () { + const template = [] + const result = menuUtil.sanitizeTemplateItems(template) + const expectedResult = [] + assert.deepEqual(result, expectedResult) + }) }) })