diff --git a/app/common/lib/menuUtil.js b/app/browser/lib/menuUtil.js similarity index 76% rename from app/common/lib/menuUtil.js rename to app/browser/lib/menuUtil.js index 909a82360b7..cc2f7068d06 100644 --- a/app/common/lib/menuUtil.js +++ b/app/browser/lib/menuUtil.js @@ -69,7 +69,7 @@ module.exports.setTemplateItemChecked = (template, label, checked) => { return null } -const createBookmarkTemplateItems = (bookmarks, parentFolderId) => { +const createBookmarkMenuItems = (bookmarks, parentFolderId) => { const filteredBookmarks = parentFolderId ? bookmarks.filter((bookmark) => bookmark.get('parentFolderId') === parentFolderId) : bookmarks.filter((bookmark) => !bookmark.get('parentFolderId')) @@ -99,7 +99,7 @@ const createBookmarkTemplateItems = (bookmarks, parentFolderId) => { const submenuItems = bookmarks.filter((bookmark) => bookmark.get('parentFolderId') === folderId) payload.push({ label: site.get('customTitle') || site.get('title'), - submenu: submenuItems.count() > 0 ? createBookmarkTemplateItems(bookmarks, folderId) : null + submenu: submenuItems.count() > 0 ? createBookmarkMenuItems(bookmarks, folderId) : null }) } }) @@ -107,18 +107,15 @@ const createBookmarkTemplateItems = (bookmarks, parentFolderId) => { } /** - * Used to create bookmarks and bookmark folder entries for the "Bookmarks" menu + * Add bookmarks / folders to "Bookmarks" menu * * @param sites The application state's Immutable sites list */ -module.exports.createBookmarkTemplateItems = (sites) => { - return createBookmarkTemplateItems(siteUtil.getBookmarks(sites)) +module.exports.createBookmarkMenuItems = (sites) => { + return createBookmarkMenuItems(siteUtil.getBookmarks(sites)) } -/** - * Create "recently closed" history entries for the "History" menu - */ -module.exports.createRecentlyClosedTemplateItems = (lastClosedFrames) => { +module.exports.createRecentlyClosedMenuItems = (lastClosedFrames) => { const payload = [] if (lastClosedFrames && lastClosedFrames.size > 0) { payload.push( @@ -144,36 +141,3 @@ module.exports.createRecentlyClosedTemplateItems = (lastClosedFrames) => { } return payload } - -const isItemValid = (currentItem, previousItem) => { - if (previousItem && previousItem === CommonMenu.separatorMenuItem) { - if (currentItem === CommonMenu.separatorMenuItem) { - return false - } - } - return currentItem && (typeof currentItem.label === 'string' || typeof currentItem.type === 'string') -} - -/** - * Remove invalid entries from a menu template: - * - null or falsey entries - * - extra menu separators - * - entries which don't have a label or type - */ -module.exports.sanitizeTemplateItems = (template) => { - return template.reduce((previousValue, currentValue, currentIndex, array) => { - const result = currentIndex === 1 ? [] : previousValue - if (currentIndex === 1) { - if (isItemValid(previousValue)) { - result.push(previousValue) - } - } - const previousItem = result.length > 0 - ? result[result.length - 1] - : undefined - if (isItemValid(currentValue, previousItem)) { - result.push(currentValue) - } - return result - }) -} diff --git a/app/browser/menu.js b/app/browser/menu.js index 2a4866af3c0..293d97c226c 100644 --- a/app/browser/menu.js +++ b/app/browser/menu.js @@ -20,7 +20,7 @@ const siteTags = require('../../js/constants/siteTags') const dialog = electron.dialog const BrowserWindow = electron.BrowserWindow const {fileUrl} = require('../../js/lib/appUrlUtil') -const menuUtil = require('../common/lib/menuUtil') +const menuUtil = require('./lib/menuUtil') const getSetting = require('../../js/settings').getSetting const locale = require('../locale') const {isSiteBookmarked} = require('../../js/state/siteUtil') @@ -329,7 +329,7 @@ const createHistorySubmenu = () => { } } ] - submenu = submenu.concat(menuUtil.createRecentlyClosedTemplateItems(Immutable.fromJS(Object.keys(closedFrames).map(key => closedFrames[key])))) + submenu = submenu.concat(menuUtil.createRecentlyClosedMenuItems(Immutable.fromJS(Object.keys(closedFrames).map(key => closedFrames[key])))) submenu.push( // TODO: recently visited @@ -374,7 +374,7 @@ const createBookmarksSubmenu = () => { CommonMenu.importBrowserDataMenuItem() ] - const bookmarks = menuUtil.createBookmarkTemplateItems(appStore.getState().get('sites')) + const bookmarks = menuUtil.createBookmarkMenuItems(appStore.getState().get('sites')) if (bookmarks.length > 0) { submenu.push(CommonMenu.separatorMenuItem) submenu = submenu.concat(bookmarks) diff --git a/app/common/lib/historyUtil.js b/app/common/lib/historyUtil.js index e42e76c8821..108590b073f 100644 --- a/app/common/lib/historyUtil.js +++ b/app/common/lib/historyUtil.js @@ -34,7 +34,7 @@ module.exports.groupEntriesByDay = (history, locale) => { const reduced = history.reduce((previousValue, currentValue, currentIndex, array) => { const result = currentIndex === 1 ? [] : previousValue if (currentIndex === 1) { - const firstDate = getDayString(previousValue, locale) + const firstDate = getDayString(currentValue, locale) result.push({date: firstDate, entries: [previousValue]}) } const date = getDayString(currentValue, locale) diff --git a/js/contextMenus.js b/js/contextMenus.js index 7dd5d5fe106..badbc862909 100644 --- a/js/contextMenus.js +++ b/js/contextMenus.js @@ -19,7 +19,6 @@ const siteTags = require('./constants/siteTags') const dragTypes = require('./constants/dragTypes') const siteUtil = require('./state/siteUtil') const downloadUtil = require('./state/downloadUtil') -const menuUtil = require('../app/common/lib/menuUtil') const CommonMenu = require('../app/common/commonMenu') const dnd = require('./dnd') const dndData = require('./dndData') @@ -125,79 +124,79 @@ function findBarTemplateInit () { } function tabsToolbarTemplateInit (activeFrame, closestDestinationDetail, isParent) { - const template = [ + const menu = [ CommonMenu.bookmarksManagerMenuItem(), CommonMenu.bookmarksToolbarMenuItem(), CommonMenu.separatorMenuItem ] if (!isDarwin) { - template.push(CommonMenu.autoHideMenuBarMenuItem(), + menu.push(CommonMenu.autoHideMenuBarMenuItem(), CommonMenu.separatorMenuItem) } - template.push(addBookmarkMenuItem('addBookmark', siteUtil.getDetailFromFrame(activeFrame, siteTags.BOOKMARK), closestDestinationDetail, isParent), + menu.push(addBookmarkMenuItem('addBookmark', siteUtil.getDetailFromFrame(activeFrame, siteTags.BOOKMARK), closestDestinationDetail, isParent), addFolderMenuItem(closestDestinationDetail, isParent)) - return menuUtil.sanitizeTemplateItems(template) + return menu } function downloadsToolbarTemplateInit (downloadId, downloadItem) { - const template = [] + const menu = [] if (downloadItem) { const downloads = appStoreRenderer.state.get('downloads') if (downloadUtil.shouldAllowPause(downloadItem)) { - template.push({ + menu.push({ label: locale.translation('downloadItemPause'), click: downloadActions.pauseDownload.bind(null, downloadId) }) } if (downloadUtil.shouldAllowResume(downloadItem)) { - template.push({ + menu.push({ label: locale.translation('downloadItemResume'), click: downloadActions.resumeDownload.bind(null, downloadId) }) } if (downloadUtil.shouldAllowCancel(downloadItem)) { - template.push({ + menu.push({ label: locale.translation('downloadItemCancel'), click: downloadActions.cancelDownload.bind(null, downloadId) }) } if (downloadUtil.shouldAllowRedownload(downloadItem)) { - template.push({ + menu.push({ label: locale.translation('downloadItemRedownload'), click: downloadActions.redownloadURL.bind(null, downloadItem, downloadId) }) } if (downloadUtil.shouldAllowCopyLink(downloadItem)) { - template.push({ + menu.push({ label: locale.translation('downloadItemCopyLink'), click: downloadActions.copyLinkToClipboard.bind(null, downloadItem) }) } if (downloadUtil.shouldAllowOpenDownloadLocation(downloadItem)) { - template.push({ + menu.push({ label: locale.translation('downloadItemPath'), click: downloadActions.locateShellPath.bind(null, downloadItem) }) } if (downloadUtil.shouldAllowDelete(downloadItem)) { - template.push({ + menu.push({ label: locale.translation('downloadItemDelete'), click: downloadActions.deleteDownload.bind(null, downloads, downloadItem, downloadId) }) } if (downloadUtil.shouldAllowRemoveFromList(downloadItem)) { - template.push({ + menu.push({ label: locale.translation('downloadItemClear'), click: downloadActions.clearDownload.bind(null, downloads, downloadId) }) @@ -205,26 +204,26 @@ function downloadsToolbarTemplateInit (downloadId, downloadItem) { } if (windowStore.getState().getIn(['ui', 'downloadsToolbar', 'isVisible'])) { - if (template.length) { - template.push(CommonMenu.separatorMenuItem) + if (menu.length) { + menu.push(CommonMenu.separatorMenuItem) } - template.push({ + menu.push({ label: locale.translation('downloadToolbarHide'), click: () => { windowActions.setDownloadsToolbarVisible(false) } }) } - if (template.length) { - template.push(CommonMenu.separatorMenuItem) + if (menu.length) { + menu.push(CommonMenu.separatorMenuItem) } - template.push({ + menu.push({ label: locale.translation('downloadItemClearCompleted'), click: () => { appActions.clearCompletedDownloads() } }) - return menuUtil.sanitizeTemplateItems(template) + return menu } function siteDetailTemplateInit (siteDetail, activeFrame) { @@ -332,7 +331,7 @@ function siteDetailTemplateInit (siteDetail, activeFrame) { addFolderMenuItem(siteDetail, true)) } - return menuUtil.sanitizeTemplateItems(template) + return template } function showBookmarkFolderInit (allBookmarkItems, parentBookmarkFolder, activeFrame) { @@ -360,7 +359,7 @@ function showBookmarkFolderInit (allBookmarkItems, parentBookmarkFolder, activeF function bookmarkItemsInit (allBookmarkItems, items, activeFrame) { const btbMode = getSetting(settings.BOOKMARKS_TOOLBAR_MODE) const showFavicon = (btbMode === bookmarksToolbarMode.TEXT_AND_FAVICONS || btbMode === bookmarksToolbarMode.FAVICONS_ONLY) - const template = items.map((site) => { + return items.map((site) => { const isFolder = siteUtil.isFolder(site) let faIcon if (showFavicon && !site.get('favicon')) { @@ -401,7 +400,6 @@ function bookmarkItemsInit (allBookmarkItems, items, activeFrame) { } return templateItem }).toJS() - return menuUtil.sanitizeTemplateItems(template) } function moreBookmarksTemplateInit (allBookmarkItems, bookmarks, activeFrame) { @@ -413,14 +411,14 @@ function moreBookmarksTemplateInit (allBookmarkItems, bookmarks, activeFrame) { windowActions.setContextMenuDetail() } }) - return menuUtil.sanitizeTemplateItems(template) + return template } function usernameTemplateInit (usernames, origin, action) { - let template = [] + let items = [] for (let username in usernames) { let password = usernames[username] - template.push({ + items.push({ label: username, click: (item, focusedWindow) => { windowActions.setActiveFrameShortcut(null, messages.FILL_PASSWORD, { @@ -433,11 +431,11 @@ function usernameTemplateInit (usernames, origin, action) { } }) } - return menuUtil.sanitizeTemplateItems(template) + return items } function autofillTemplateInit (suggestions, frame) { - const template = [] + const items = [] for (let i = 0; i < suggestions.length; ++i) { let value const frontendId = suggestions[i].frontend_id @@ -451,9 +449,9 @@ function autofillTemplateInit (suggestions, frame) { value = 'Autofill Settings' } if (frontendId === -3) { // POPUP_ITEM_ID_SEPARATOR - template.push(CommonMenu.separatorMenuItem) + items.push(CommonMenu.separatorMenuItem) } else { - template.push({ + items.push({ label: value, click: (item, focusedWindow) => { ipc.send('autofill-selection-clicked', frame.get('tabId'), value, frontendId, i) @@ -462,15 +460,15 @@ function autofillTemplateInit (suggestions, frame) { }) } } - return menuUtil.sanitizeTemplateItems(template) + return items } function tabTemplateInit (frameProps) { const frameKey = frameProps.get('key') - const template = [CommonMenu.newTabMenuItem(frameProps.get('key'))] + const items = [CommonMenu.newTabMenuItem(frameProps.get('key'))] const location = frameProps.get('location') if (location !== 'about:newtab') { - template.push( + items.push( CommonMenu.separatorMenuItem, { label: locale.translation('reloadTab'), @@ -494,7 +492,7 @@ function tabTemplateInit (frameProps) { if (!frameProps.get('isPrivate')) { const isPinned = frameProps.get('pinnedLocation') if (!(location === 'about:blank' || location === 'about:newtab' || isIntermediateAboutPage(location))) { - template.push({ + items.push({ label: locale.translation(isPinned ? 'unpinTab' : 'pinTab'), click: (item) => { // Handle converting the current tab window into a pinned site @@ -504,7 +502,7 @@ function tabTemplateInit (frameProps) { } } - // template.push({ + // items.push({ // label: locale.translation('moveTabToNewWindow'), // enabled: false, // click: (item, focusedWindow) => { @@ -512,7 +510,7 @@ function tabTemplateInit (frameProps) { // } // }) - template.push(CommonMenu.separatorMenuItem, + items.push(CommonMenu.separatorMenuItem, { label: locale.translation('muteOtherTabs'), click: (item, focusedWindow) => { @@ -523,7 +521,7 @@ function tabTemplateInit (frameProps) { if (frameProps.get('audioPlaybackActive')) { const isMuted = frameProps.get('audioMuted') - template.push({ + items.push({ label: locale.translation(isMuted ? 'unmuteTab' : 'muteTab'), click: (item) => { windowActions.setAudioMuted(frameProps, !isMuted) @@ -531,10 +529,10 @@ function tabTemplateInit (frameProps) { }) } - template.push(CommonMenu.separatorMenuItem) + items.push(CommonMenu.separatorMenuItem) if (!frameProps.get('pinnedLocation')) { - template.push({ + items.push({ label: locale.translation('closeTab'), click: (item, focusedWindow) => { if (focusedWindow) { @@ -545,7 +543,7 @@ function tabTemplateInit (frameProps) { }) } - template.push({ + items.push({ label: locale.translation('closeOtherTabs'), click: (item, focusedWindow) => { if (focusedWindow) { @@ -568,22 +566,22 @@ function tabTemplateInit (frameProps) { } }, CommonMenu.separatorMenuItem) - template.push(Object.assign({}, + items.push(Object.assign({}, CommonMenu.reopenLastClosedTabItem(), { enabled: windowStore.getState().get('closedFrames').size > 0 } )) - return menuUtil.sanitizeTemplateItems(template) + return items } function getMisspelledSuggestions (selection, isMisspelled, suggestions) { const hasSelection = selection.length > 0 - const template = [] + const items = [] if (hasSelection) { if (suggestions.length > 0) { // Map the first 3 suggestions to menu items that allows click // to replace the text. - template.push(...suggestions.slice(0, 3).map((suggestion) => { + items.push(...suggestions.slice(0, 3).map((suggestion) => { return { label: suggestion, click: () => { @@ -593,7 +591,7 @@ function getMisspelledSuggestions (selection, isMisspelled, suggestions) { }), CommonMenu.separatorMenuItem) } if (isMisspelled) { - template.push({ + items.push({ label: locale.translation('learnSpelling'), click: () => { appActions.addWord(selection, true) @@ -610,16 +608,16 @@ function getMisspelledSuggestions (selection, isMisspelled, suggestions) { }, CommonMenu.separatorMenuItem) } } - return menuUtil.sanitizeTemplateItems(template) + return items } function getEditableItems (selection, editFlags) { const hasSelection = selection.length > 0 const hasClipboard = clipboard.readText().length > 0 - const template = [] + const items = [] if (!editFlags || editFlags.canCut) { - template.push({ + items.push({ label: locale.translation('cut'), enabled: hasSelection, accelerator: 'CmdOrCtrl+X', @@ -627,7 +625,7 @@ function getEditableItems (selection, editFlags) { }) } if (!editFlags || editFlags.canCopy) { - template.push({ + items.push({ label: locale.translation('copy'), enabled: hasSelection, accelerator: 'CmdOrCtrl+C', @@ -635,14 +633,14 @@ function getEditableItems (selection, editFlags) { }) } if (!editFlags || editFlags.canPaste) { - template.push({ + items.push({ label: locale.translation('paste'), accelerator: 'CmdOrCtrl+V', enabled: hasClipboard, role: 'paste' }) } - return menuUtil.sanitizeTemplateItems(template) + return items } function hamburgerTemplateInit (location, e) { @@ -685,7 +683,7 @@ function hamburgerTemplateInit (location, e) { }, { label: locale.translation('bravery'), submenu: [ - // CommonMenu.braveryGlobalMenuItem(), +// CommonMenu.braveryGlobalMenuItem(), CommonMenu.braverySiteMenuItem(), CommonMenu.braveryPaymentsMenuItem() ] @@ -709,7 +707,7 @@ function hamburgerTemplateInit (location, e) { }, CommonMenu.quitMenuItem() ] - return menuUtil.sanitizeTemplateItems(template) + return template } const openInNewTabMenuItem = (location, isPrivate, partitionNumber, parentFrameKey) => { @@ -892,7 +890,7 @@ function mainTemplateInit (nodeProps, frame) { } }) } - return menuUtil.sanitizeTemplateItems(template) + return template } const isLink = nodeProps.linkURL && nodeProps.linkURL !== '' @@ -1213,7 +1211,7 @@ function mainTemplateInit (nodeProps, frame) { ) } - return menuUtil.sanitizeTemplateItems(template) + return template } function onHamburgerMenu (location, e) { diff --git a/test/unit/app/common/state/aboutHistoryStateTest.js b/test/unit/common/state/aboutHistoryStateTest.js similarity index 92% rename from test/unit/app/common/state/aboutHistoryStateTest.js rename to test/unit/common/state/aboutHistoryStateTest.js index ac40ae6c82f..eb1f13f13fe 100644 --- a/test/unit/app/common/state/aboutHistoryStateTest.js +++ b/test/unit/common/state/aboutHistoryStateTest.js @@ -1,5 +1,5 @@ /* global describe, it */ -const aboutHistoryState = require('../../../../../app/common/state/aboutHistoryState') +const aboutHistoryState = require('../../../../app/common/state/aboutHistoryState') const Immutable = require('immutable') const assert = require('assert') diff --git a/test/unit/app/common/state/aboutNewTabStateTest.js b/test/unit/common/state/aboutNewTabStateTest.js similarity index 97% rename from test/unit/app/common/state/aboutNewTabStateTest.js rename to test/unit/common/state/aboutNewTabStateTest.js index 9349f47907a..c2d2a489b66 100644 --- a/test/unit/app/common/state/aboutNewTabStateTest.js +++ b/test/unit/common/state/aboutNewTabStateTest.js @@ -1,8 +1,8 @@ /* global describe, it */ -const aboutNewTabState = require('../../../../../app/common/state/aboutNewTabState') +const aboutNewTabState = require('../../../../app/common/state/aboutNewTabState') const Immutable = require('immutable') const assert = require('assert') -const siteTags = require('../../../../../js/constants/siteTags') +const siteTags = require('../../../../js/constants/siteTags') const defaultAppState = Immutable.fromJS({ about: { diff --git a/test/unit/app/common/state/basicAuthStateTest.js b/test/unit/common/state/basicAuthStateTest.js similarity index 97% rename from test/unit/app/common/state/basicAuthStateTest.js rename to test/unit/common/state/basicAuthStateTest.js index df354f2cf71..21b07203594 100644 --- a/test/unit/app/common/state/basicAuthStateTest.js +++ b/test/unit/common/state/basicAuthStateTest.js @@ -1,6 +1,6 @@ /* global describe, it, before */ -const basicAuthState = require('../../../../../app/common/state/basicAuthState') -const tabState = require('../../../../../app/common/state/tabState') +const basicAuthState = require('../../../../app/common/state/basicAuthState') +const tabState = require('../../../../app/common/state/tabState') const Immutable = require('immutable') const assert = require('assert') diff --git a/test/unit/app/common/state/extensionStateTest.js b/test/unit/common/state/extensionStateTest.js similarity index 99% rename from test/unit/app/common/state/extensionStateTest.js rename to test/unit/common/state/extensionStateTest.js index 4a263faa54c..a15ee503e3a 100644 --- a/test/unit/app/common/state/extensionStateTest.js +++ b/test/unit/common/state/extensionStateTest.js @@ -1,5 +1,5 @@ /* global describe, it, before */ -const extensionState = require('../../../../../app/common/state/extensionState') +const extensionState = require('../../../../app/common/state/extensionState') const Immutable = require('immutable') const assert = require('assert') diff --git a/test/unit/app/common/state/tabStateTest.js b/test/unit/common/state/tabStateTest.js similarity index 99% rename from test/unit/app/common/state/tabStateTest.js rename to test/unit/common/state/tabStateTest.js index 2daf1b33182..cc6b0653326 100644 --- a/test/unit/app/common/state/tabStateTest.js +++ b/test/unit/common/state/tabStateTest.js @@ -1,5 +1,5 @@ /* global describe, it, before */ -const tabState = require('../../../../../app/common/state/tabState') +const tabState = require('../../../../app/common/state/tabState') const Immutable = require('immutable') const assert = require('assert') diff --git a/test/unit/app/common/lib/formatUtilTest.js b/test/unit/lib/formatUtilTest.js similarity index 96% rename from test/unit/app/common/lib/formatUtilTest.js rename to test/unit/lib/formatUtilTest.js index ad995e78000..7d9d404e5b6 100644 --- a/test/unit/app/common/lib/formatUtilTest.js +++ b/test/unit/lib/formatUtilTest.js @@ -1,8 +1,8 @@ /* global describe, before, after, it */ -const formatUtil = require('../../../../../app/common/lib/formatUtil') +const formatUtil = require('../../../app/common/lib/formatUtil') const assert = require('assert') -require('../../../braveUnit') +require('../braveUnit') describe('formatUtil', function () { describe('formatAccelerator', function () { diff --git a/test/unit/app/common/lib/historyUtilTest.js b/test/unit/lib/historyUtilTest.js similarity index 97% rename from test/unit/app/common/lib/historyUtilTest.js rename to test/unit/lib/historyUtilTest.js index dc39ec646f2..bcd6f484faf 100644 --- a/test/unit/app/common/lib/historyUtilTest.js +++ b/test/unit/lib/historyUtilTest.js @@ -1,9 +1,8 @@ /* global describe, it */ const assert = require('assert') const Immutable = require('immutable') -const historyUtil = require('../../../../../app/common/lib/historyUtil') - -require('../../../braveUnit') +const historyUtil = require('../../../app/common/lib/historyUtil') +require('../braveUnit') describe('historyUtil', function () { const historyDayOne = Immutable.fromJS({ diff --git a/test/unit/app/common/lib/httpUtilTest.js b/test/unit/lib/httpUtilTest.js similarity index 95% rename from test/unit/app/common/lib/httpUtilTest.js rename to test/unit/lib/httpUtilTest.js index 824d200b530..7b1fe40299d 100644 --- a/test/unit/app/common/lib/httpUtilTest.js +++ b/test/unit/lib/httpUtilTest.js @@ -1,8 +1,8 @@ /* global describe, it */ -const httpUtil = require('../../../../../app/common/lib/httpUtil') +const httpUtil = require('../../../app/common/lib/httpUtil') const assert = require('assert') -require('../../../braveUnit') +require('../braveUnit') describe('httpUtil test', function () { describe('responseHasContent', function () { diff --git a/test/unit/app/common/lib/ledgerUtilTest.js b/test/unit/lib/ledgerUtilTest.js similarity index 95% rename from test/unit/app/common/lib/ledgerUtilTest.js rename to test/unit/lib/ledgerUtilTest.js index df643fb74ba..96fdc376c89 100644 --- a/test/unit/app/common/lib/ledgerUtilTest.js +++ b/test/unit/lib/ledgerUtilTest.js @@ -1,8 +1,8 @@ /* global describe, it */ -const ledgerUtil = require('../../../../../app/common/lib/ledgerUtil') +const ledgerUtil = require('../../../app/common/lib/ledgerUtil') const assert = require('assert') -require('../../../braveUnit') +require('../braveUnit') describe('ledgerUtil test', function () { describe('shouldTrackView', function () { diff --git a/test/unit/app/common/lib/menuUtilTest.js b/test/unit/lib/menuUtilTest.js similarity index 73% rename from test/unit/app/common/lib/menuUtilTest.js rename to test/unit/lib/menuUtilTest.js index edf140f1fdd..e7f3f82f6b4 100644 --- a/test/unit/app/common/lib/menuUtilTest.js +++ b/test/unit/lib/menuUtilTest.js @@ -1,14 +1,12 @@ /* global describe, before, after, it */ -const siteTags = require('../../../../../js/constants/siteTags') +const siteTags = require('../../../js/constants/siteTags') const mockery = require('mockery') const assert = require('assert') const Immutable = require('immutable') +require('../braveUnit') -require('../../../braveUnit') - -describe('menuUtil tests', function () { +describe('menuUtil', function () { let menuUtil - let separator before(function () { mockery.enable({ @@ -16,10 +14,8 @@ describe('menuUtil tests', function () { warnOnUnregistered: false, useCleanCache: true }) - // This is required; commonMenu is included by menuUtil (and references electron) - mockery.registerMock('electron', require('../../../lib/fakeElectron')) - menuUtil = require('../../../../../app/common/lib/menuUtil') - separator = require('../../../../../app/common/commonMenu').separatorMenuItem + mockery.registerMock('electron', require('./fakeElectron')) + menuUtil = require('../../../app/browser/lib/menuUtil') }) after(function () { @@ -120,13 +116,13 @@ describe('menuUtil tests', function () { }) }) - describe('createBookmarkTemplateItems', function () { + describe('createBookmarkMenuItems', function () { it('returns an array of items w/ the bookmark tag', function () { const appStateSites = Immutable.fromJS([ { tags: [siteTags.BOOKMARK], title: 'my website', location: 'https://brave.com' } ]) - const menuItems = menuUtil.createBookmarkTemplateItems(appStateSites) + const menuItems = menuUtil.createBookmarkMenuItems(appStateSites) assert.equal(Array.isArray(menuItems), true) assert.equal(menuItems.length, 1) @@ -137,7 +133,7 @@ describe('menuUtil tests', function () { { tags: [siteTags.BOOKMARK], customTitle: 'use this', title: 'not this', location: 'https://brave.com' } ]) - const menuItems = menuUtil.createBookmarkTemplateItems(appStateSites) + const menuItems = menuUtil.createBookmarkMenuItems(appStateSites) assert.equal(menuItems[0].label, 'use this') }) @@ -148,7 +144,7 @@ describe('menuUtil tests', function () { ] }) - const menuItems = menuUtil.createBookmarkTemplateItems(appStateSites) + const menuItems = menuUtil.createBookmarkMenuItems(appStateSites) assert.deepEqual(menuItems, []) }) @@ -159,7 +155,7 @@ describe('menuUtil tests', function () { ] }) - const menuItems = menuUtil.createBookmarkTemplateItems(appStateSites) + const menuItems = menuUtil.createBookmarkMenuItems(appStateSites) assert.deepEqual(menuItems, []) }) @@ -168,7 +164,7 @@ describe('menuUtil tests', function () { { tags: [siteTags.PINNED], title: 'pinned site', location: 'https://pinned-website.com' }, { tags: [siteTags.BOOKMARK], title: 'my website', location: 'https://brave.com' } ]) - const menuItems = menuUtil.createBookmarkTemplateItems(appStateSites) + const menuItems = menuUtil.createBookmarkMenuItems(appStateSites) assert.equal(menuItems.length, 1) assert.equal(menuItems[0].label, 'my website') @@ -178,7 +174,7 @@ describe('menuUtil tests', function () { { tags: [siteTags.BOOKMARK_FOLDER], title: 'my folder', folderId: 123 }, { tags: [siteTags.BOOKMARK], title: 'my website', location: 'https://brave.com', parentFolderId: 123 } ]) - const menuItems = menuUtil.createBookmarkTemplateItems(appStateSites) + const menuItems = menuUtil.createBookmarkMenuItems(appStateSites) assert.equal(menuItems.length, 1) assert.equal(menuItems[0].label, 'my folder') @@ -191,20 +187,20 @@ describe('menuUtil tests', function () { { tags: [siteTags.BOOKMARK], title: 'my website', location: 'https://brave.com', parentFolderId: 123 } ]) - const menuItems = menuUtil.createBookmarkTemplateItems(appStateSites) + const menuItems = menuUtil.createBookmarkMenuItems(appStateSites) assert.equal(menuItems.length, 1) assert.equal(menuItems[0].label, 'use this') }) }) - describe('createRecentlyClosedTemplateItems', function () { + describe('createRecentlyClosedMenuItems', function () { it('returns an array of closedFrames preceded by a separator and "Recently Closed" items', function () { const windowStateClosedFrames = Immutable.fromJS([{ title: 'sample', location: 'https://brave.com' }]) - const menuItems = menuUtil.createRecentlyClosedTemplateItems(windowStateClosedFrames) + const menuItems = menuUtil.createRecentlyClosedMenuItems(windowStateClosedFrames) assert.equal(Array.isArray(menuItems), true) assert.equal(menuItems.length, 3) @@ -228,38 +224,11 @@ describe('menuUtil tests', function () { { title: 'site10', location: 'https://brave10.com' }, { title: 'site11', location: 'https://brave11.com' } ]) - const menuItems = menuUtil.createRecentlyClosedTemplateItems(windowStateClosedFrames) + const menuItems = menuUtil.createRecentlyClosedMenuItems(windowStateClosedFrames) assert.equal(menuItems.length, 12) assert.equal(menuItems[2].label, windowStateClosedFrames.get(1).get('title')) assert.equal(menuItems[11].label, windowStateClosedFrames.get(10).get('title')) }) }) - - describe('sanitizeTemplateItems', function () { - it('removes entries which are falsey', function () { - const template = [null, undefined, false, {label: 'lol'}] - const result = menuUtil.sanitizeTemplateItems(template) - const expectedResult = [{label: 'lol'}] - assert.deepEqual(result, expectedResult) - }) - it('removes duplicate menu separators', function () { - const template = [separator, separator, {label: 'lol'}] - const result = menuUtil.sanitizeTemplateItems(template) - const expectedResult = [separator, {label: 'lol'}] - assert.deepEqual(result, expectedResult) - }) - it('removes items which are missing label or type', function () { - const template = [{}, {test: 'test'}, {label: 'lol'}] - const result = menuUtil.sanitizeTemplateItems(template) - const expectedResult = [{label: 'lol'}] - assert.deepEqual(result, expectedResult) - }) - it('removes items which have non-string values for label or type', function () { - const template = [{label: true}, {type: function () { console.log('test') }}, {label: 'lol'}] - const result = menuUtil.sanitizeTemplateItems(template) - const expectedResult = [{label: 'lol'}] - assert.deepEqual(result, expectedResult) - }) - }) }) diff --git a/test/unit/app/common/lib/platformUtilTest.js b/test/unit/lib/platformUtilTest.js similarity index 90% rename from test/unit/app/common/lib/platformUtilTest.js rename to test/unit/lib/platformUtilTest.js index b6bffc2ff55..f241a6d0e22 100644 --- a/test/unit/app/common/lib/platformUtilTest.js +++ b/test/unit/lib/platformUtilTest.js @@ -1,9 +1,9 @@ /* global describe, it */ const mockery = require('mockery') const assert = require('assert') -let platformUtil = require('../../../../../app/common/lib/platformUtil') +let platformUtil = require('../../../app/common/lib/platformUtil') -require('../../../braveUnit') +require('../braveUnit') describe('platformUtil', function () { const mockWin7 = { @@ -26,11 +26,11 @@ describe('platformUtil', function () { const loadMocks = (osMock) => { mockery.enable({ warnOnReplace: false, warnOnUnregistered: false, useCleanCache: true }) mockery.registerMock('os', osMock) - platformUtil = require('../../../../../app/common/lib/platformUtil') + platformUtil = require('../../../app/common/lib/platformUtil') } const unloadMocks = () => { mockery.disable() - platformUtil = require('../../../../../app/common/lib/platformUtil') + platformUtil = require('../../../app/common/lib/platformUtil') } describe('getPlatformStyles', function () {