Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Add addSite with list to rebuild #4590

Merged
merged 1 commit into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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