Skip to content

Commit

Permalink
Add addSite with list to rebuild
Browse files Browse the repository at this point in the history
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
  • Loading branch information
darkdh committed Oct 6, 2016
1 parent 99a205b commit 08c5c1f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,19 @@ const doAction = (action) => {
appDispatcher.waitFor([appStore.dispatchToken], () => {
createMenu()
})
} else if (action.siteDetail.constructor === Immutable.List && action.tag === undefined) {
let shouldRebuild = false
action.siteDetail.forEach((site) => {
const tag = site.getIn(['tags', 0])
if (tag === siteTags.BOOKMARK || tag === siteTags.BOOKMARK_FOLDER) {
shouldRebuild = true
}
})
if (shouldRebuild) {
appDispatcher.waitFor([appStore.dispatchToken], () => {
createMenu()
})
}
}
break
case appConstants.APP_REMOVE_SITE:
Expand Down
39 changes: 39 additions & 0 deletions test/components/bookmarksTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global describe, it, before */

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

Expand Down Expand Up @@ -196,5 +197,43 @@ describe('bookmark tests', function () {
})
})
})

it('rebuilds the menu when add a list of items', function * () {
const bookmarkTitle = 'bookmark-rebuild-menu-demo'
const folderName = 'bookmark-folder-rebuild-menu-demo'
const sites = Immutable.fromJS([
{
customTitle: folderName,
folderId: 1,
parentFolderId: 0,
tags: [siteTags.BOOKMARK_FOLDER]
},
{
lastAccessedTime: 123,
title: bookmarkTitle,
location: 'https://brave.com',
tags: [siteTags.BOOKMARK]
}
])
yield this.app.client
.addSiteList(sites)
.waitUntil(function () {
return this.getAppState().then((val) => {
const bookmarksMenu = val.value.menu.template.find((item) => {
return item.label === 'Bookmarks'
})
if (bookmarksMenu && bookmarksMenu.submenu) {
const bookmark = bookmarksMenu.submenu.find((item) => {
return item.label === bookmarkTitle
})
const bookmarkFolder = bookmarksMenu.submenu.find((item) => {
return item.label === folderName
})
if (bookmark && bookmarkFolder) return true
}
return false
})
})
})
})
})
11 changes: 11 additions & 0 deletions test/lib/brave.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,17 @@ var exports = {
}, siteDetail, tag).then((response) => response.value)
})

/**
* Adds a list sites to the sites list, including bookmark and foler.
*
* @param {object} siteDetail - Properties for the siteDetail to add
*/
this.app.client.addCommand('addSiteList', function (siteDetail) {
return this.execute(function (siteDetail) {
return require('../../../js/actions/appActions').addSite(siteDetail)
}, siteDetail).then((response) => response.value)
})

/**
* Removes a site from the sites list, or removes a bookmark.
*
Expand Down

0 comments on commit 08c5c1f

Please sign in to comment.