This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 973
Hide bookmark bar when removing last item #14048
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/* global describe, it, before, after, afterEach */ | ||
/* global describe, it, before, after, beforeEach, afterEach */ | ||
const mockery = require('mockery') | ||
const Immutable = require('immutable') | ||
const assert = require('assert') | ||
|
@@ -11,6 +11,8 @@ const fakeElectron = require('../../../lib/fakeElectron') | |
const fakeAdBlock = require('../../../lib/fakeAdBlock') | ||
|
||
const appConstants = require('../../../../../js/constants/appConstants') | ||
const appActions = require('../../../../../js/actions/appActions') | ||
const settingsConstants = require('../../../../../js/constants/settings') | ||
const siteTags = require('../../../../../js/constants/siteTags') | ||
require('../../../braveUnit') | ||
|
||
|
@@ -31,7 +33,8 @@ describe('bookmarksReducer unit test', function () { | |
bookmarkLocation: {} | ||
}, | ||
historySites: {}, | ||
tabs: [] | ||
tabs: [], | ||
settings: {} | ||
}) | ||
|
||
const stateWithData = Immutable.fromJS({ | ||
|
@@ -133,7 +136,10 @@ describe('bookmarksReducer unit test', function () { | |
} | ||
}, | ||
historySites: {}, | ||
tabs: [] | ||
tabs: [], | ||
settings: { | ||
[settingsConstants.SHOW_BOOKMARKS_TOOLBAR]: true | ||
} | ||
}) | ||
|
||
before(function () { | ||
|
@@ -144,6 +150,7 @@ describe('bookmarksReducer unit test', function () { | |
}) | ||
mockery.registerMock('electron', fakeElectron) | ||
mockery.registerMock('ad-block', fakeAdBlock) | ||
mockery.registerMock('../../../js/actions/appActions', appActions) | ||
bookmarksReducer = require('../../../../../app/browser/reducers/bookmarksReducer') | ||
bookmarksState = require('../../../../../app/common/state/bookmarksState') | ||
bookmarkLocationCache = require('../../../../../app/common/cache/bookmarkLocationCache') | ||
|
@@ -516,13 +523,19 @@ describe('bookmarksReducer unit test', function () { | |
|
||
describe('APP_REMOVE_BOOKMARK', function () { | ||
let spy | ||
let onChangeSettingSpy | ||
|
||
beforeEach(function () { | ||
spy = sinon.spy(bookmarksState, 'removeBookmark') | ||
onChangeSettingSpy = sinon.spy(appActions, 'changeSetting') | ||
}) | ||
|
||
afterEach(function () { | ||
spy.restore() | ||
onChangeSettingSpy.restore() | ||
}) | ||
|
||
it('null case', function () { | ||
spy = sinon.spy(bookmarksState, 'removeBookmark') | ||
const newState = bookmarksReducer(state, { | ||
actionType: appConstants.APP_REMOVE_BOOKMARK | ||
}) | ||
|
@@ -531,7 +544,6 @@ describe('bookmarksReducer unit test', function () { | |
}) | ||
|
||
it('check if delete is working', function () { | ||
spy = sinon.spy(bookmarksState, 'removeBookmark') | ||
const newState = bookmarksReducer(stateWithData, { | ||
actionType: appConstants.APP_REMOVE_BOOKMARK, | ||
bookmarkKey: 'https://clifton.io/|0|0' | ||
|
@@ -548,6 +560,19 @@ describe('bookmarksReducer unit test', function () { | |
.deleteIn(['cache', 'bookmarkLocation', 'https://clifton.io/']) | ||
assert.equal(spy.calledOnce, true) | ||
assert.deepEqual(newState.toJS(), expectedState.toJS()) | ||
console.log('settings', newState.get('settings').toJS(), newState.getIn(['settings', settingsConstants.SHOW_BOOKMARKS_TOOLBAR])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops, left a console.log in there 😄 |
||
assert.ok(onChangeSettingSpy.neverCalledWith(settingsConstants.SHOW_BOOKMARKS_TOOLBAR, false), 'bookmarks toolbar enabled setting is unaffected by removing 1 bookmark') | ||
}) | ||
|
||
it('hides bookmarks toolbar when all toolbar bookmarks are removed', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a test for bookmarksReducer too? |
||
let newState = stateWithData | ||
for (const bookmarkKey of stateWithData.get('bookmarks').keys()) { | ||
newState = bookmarksReducer(newState, { | ||
actionType: appConstants.APP_REMOVE_BOOKMARK, | ||
bookmarkKey | ||
}) | ||
} | ||
assert.ok(onChangeSettingSpy.calledWith(settingsConstants.SHOW_BOOKMARKS_TOOLBAR, false)) | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little nit-picky... but could we move this code to app/common/lib/bookmarkUtils? Since it's the same as the code above in bookmarkFoldersReducer.js, each of these could be replaced with a single call (maybe the method would be called like
closeBookmarksToolbarIfEmpty
or something like that)Should make the logic easier to unit test too 😄 👍