diff --git a/app/browser/reducers/sitesReducer.js b/app/browser/reducers/sitesReducer.js index 12f5e31048d..65f412c592b 100644 --- a/app/browser/reducers/sitesReducer.js +++ b/app/browser/reducers/sitesReducer.js @@ -21,13 +21,20 @@ const syncEnabled = () => { return getSetting(settings.SYNC_ENABLED) === true } +const updateTabBookmarked = (state, tabValue) => { + if (!tabValue || !tabValue.get('tabId')) { + return state + } + const bookmarked = siteUtil.isLocationBookmarked(state, tabValue.get('url')) + return tabState.updateTabValue(state, tabValue.set('bookmarked', bookmarked)) +} + const updateActiveTabBookmarked = (state) => { const tab = tabState.getActiveTab(state) if (!tab) { return state } - const bookmarked = siteUtil.isLocationBookmarked(state, tab.get('url')) - return tabState.updateTabValue(state, tab.set('bookmarked', bookmarked)) + return updateTabBookmarked(state, tab) } const sitesReducer = (state, action, immutableAction) => { @@ -135,6 +142,7 @@ const sitesReducer = (state, action, immutableAction) => { state = syncUtil.updateSiteCache(state, siteDetail) } } + state = updateTabBookmarked(state, action.tabValue) break case appConstants.APP_CREATE_TAB_REQUESTED: { const createProperties = immutableAction.get('createProperties') diff --git a/test/bookmark-components/bookmarksTest.js b/test/bookmark-components/bookmarksTest.js index 9d7e7098d88..7cf8f2c6eda 100644 --- a/test/bookmark-components/bookmarksTest.js +++ b/test/bookmark-components/bookmarksTest.js @@ -1,4 +1,4 @@ -/* global describe, it, before */ +/* global describe, it, before, beforeEach */ const Brave = require('../lib/brave') const Immutable = require('immutable') @@ -249,6 +249,41 @@ describe('bookmark tests', function () { }) }) + describe('bookmark star button is preserved', function () { + Brave.beforeEach(this) + beforeEach(function * () { + this.page1Url = Brave.server.url('page1.html') + this.page2Url = Brave.server.url('page2.html') + yield setup(this.app.client) + yield this.app.client + .addSite({ + location: this.page1Url, + folderId: 1, + parentFolderId: 0, + tags: [siteTags.BOOKMARK] + }, siteTags.BOOKMARK) + }) + + it('on new active tabs', function * () { + yield this.app.client + .waitForVisible(navigatorNotBookmarked) + .newTab({ url: this.page1Url }) + .waitForVisible(navigatorBookmarked) + }) + it('on new active tabs', function * () { + yield this.app.client + .waitForVisible(navigatorNotBookmarked) + .newTab({ url: this.page1Url, active: false }) + .waitForUrl(this.page1Url) + .tabByIndex(0) + .loadUrl(this.page2Url) + .waitForUrl(this.page2Url) + .windowByUrl(Brave.browserWindowUrl) + .ipcSend('shortcut-next-tab') + .waitForVisible(navigatorBookmarked) + }) + }) + describe('menu behavior', function () { Brave.beforeAll(this)