Skip to content

Commit 08c5c1f

Browse files
committed
Add addSite with list to rebuild
fix brave#4586 Auditors: @bsclifton Test Plan: 1. Import bookmarks from other browsers or html file 2. The imported bookmarks should show in "Bookmarks" menu
1 parent 99a205b commit 08c5c1f

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

app/browser/menu.js

+13
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,19 @@ const doAction = (action) => {
615615
appDispatcher.waitFor([appStore.dispatchToken], () => {
616616
createMenu()
617617
})
618+
} else if (action.siteDetail.constructor === Immutable.List && action.tag === undefined) {
619+
let shouldRebuild = false
620+
action.siteDetail.forEach((site) => {
621+
const tag = site.getIn(['tags', 0])
622+
if (tag === siteTags.BOOKMARK || tag === siteTags.BOOKMARK_FOLDER) {
623+
shouldRebuild = true
624+
}
625+
})
626+
if (shouldRebuild) {
627+
appDispatcher.waitFor([appStore.dispatchToken], () => {
628+
createMenu()
629+
})
630+
}
618631
}
619632
break
620633
case appConstants.APP_REMOVE_SITE:

test/components/bookmarksTest.js

+39
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* global describe, it, before */
22

33
const Brave = require('../lib/brave')
4+
const Immutable = require('immutable')
45
const {urlInput, navigator, navigatorNotBookmarked, saveButton, deleteButton} = require('../lib/selectors')
56
const siteTags = require('../../js/constants/siteTags')
67

@@ -196,5 +197,43 @@ describe('bookmark tests', function () {
196197
})
197198
})
198199
})
200+
201+
it('rebuilds the menu when add a list of items', function * () {
202+
const bookmarkTitle = 'bookmark-rebuild-menu-demo'
203+
const folderName = 'bookmark-folder-rebuild-menu-demo'
204+
const sites = Immutable.fromJS([
205+
{
206+
customTitle: folderName,
207+
folderId: 1,
208+
parentFolderId: 0,
209+
tags: [siteTags.BOOKMARK_FOLDER]
210+
},
211+
{
212+
lastAccessedTime: 123,
213+
title: bookmarkTitle,
214+
location: 'https://brave.com',
215+
tags: [siteTags.BOOKMARK]
216+
}
217+
])
218+
yield this.app.client
219+
.addSiteList(sites)
220+
.waitUntil(function () {
221+
return this.getAppState().then((val) => {
222+
const bookmarksMenu = val.value.menu.template.find((item) => {
223+
return item.label === 'Bookmarks'
224+
})
225+
if (bookmarksMenu && bookmarksMenu.submenu) {
226+
const bookmark = bookmarksMenu.submenu.find((item) => {
227+
return item.label === bookmarkTitle
228+
})
229+
const bookmarkFolder = bookmarksMenu.submenu.find((item) => {
230+
return item.label === folderName
231+
})
232+
if (bookmark && bookmarkFolder) return true
233+
}
234+
return false
235+
})
236+
})
237+
})
199238
})
200239
})

test/lib/brave.js

+11
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,17 @@ var exports = {
286286
}, siteDetail, tag).then((response) => response.value)
287287
})
288288

289+
/**
290+
* Adds a list sites to the sites list, including bookmark and foler.
291+
*
292+
* @param {object} siteDetail - Properties for the siteDetail to add
293+
*/
294+
this.app.client.addCommand('addSiteList', function (siteDetail) {
295+
return this.execute(function (siteDetail) {
296+
return require('../../../js/actions/appActions').addSite(siteDetail)
297+
}, siteDetail).then((response) => response.value)
298+
})
299+
289300
/**
290301
* Removes a site from the sites list, or removes a bookmark.
291302
*

0 commit comments

Comments
 (0)