forked from brave/browser-laptop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follow up for sites splits PR brave#10296
Resolves brave#10296 Resolves brave#10348 Resolves brave#10503 Auditors: Test Plan:
- Loading branch information
Showing
4 changed files
with
305 additions
and
10 deletions.
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 |
---|---|---|
@@ -0,0 +1,223 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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 */ | ||
const mockery = require('mockery') | ||
const Immutable = require('immutable') | ||
const assert = require('assert') | ||
|
||
const siteTags = require('../../../../../js/constants/siteTags') | ||
const {STATE_SITES} = require('../../../../../js/constants/stateConstants') | ||
require('../../../braveUnit') | ||
|
||
describe('bookmarkFoldersState unit test', function () { | ||
let bookmarkFoldersState | ||
|
||
const state = Immutable.fromJS({ | ||
bookmarks: {}, | ||
bookmarkFolders: {}, | ||
cache: { | ||
bookmarkOrder: {} | ||
} | ||
}) | ||
|
||
const stateWithData = Immutable.fromJS({ | ||
bookmarks: {}, | ||
bookmarkFolders: { | ||
'1': { | ||
title: 'folder1', | ||
folderId: 1, | ||
key: '1', | ||
parentFolderId: 0, | ||
partitionNumber: 0, | ||
objectId: null, | ||
type: siteTags.BOOKMARK_FOLDER | ||
}, | ||
'2': { | ||
title: 'folder2', | ||
folderId: 2, | ||
key: '2', | ||
parentFolderId: 1, | ||
partitionNumber: 0, | ||
objectId: null, | ||
type: siteTags.BOOKMARK_FOLDER | ||
}, | ||
'69': { | ||
title: 'folder69', | ||
folderId: 69, | ||
key: '69', | ||
parentFolderId: 0, | ||
partitionNumber: 0, | ||
objectId: null, | ||
type: siteTags.BOOKMARK_FOLDER | ||
} | ||
}, | ||
cache: { | ||
bookmarkOrder: { | ||
'0': [ | ||
{ | ||
key: '1', | ||
order: 0, | ||
type: siteTags.BOOKMARK_FOLDER | ||
}, | ||
{ | ||
key: '69', | ||
order: 1, | ||
type: siteTags.BOOKMARK_FOLDER | ||
} | ||
], | ||
'1': [ | ||
{ | ||
key: '2', | ||
order: 0, | ||
type: siteTags.BOOKMARK_FOLDER | ||
} | ||
] | ||
} | ||
} | ||
}) | ||
|
||
before(function () { | ||
mockery.enable({ | ||
warnOnReplace: false, | ||
warnOnUnregistered: false, | ||
useCleanCache: true | ||
}) | ||
bookmarkFoldersState = require('../../../../../app/common/state/bookmarkFoldersState') | ||
}) | ||
|
||
after(function () { | ||
mockery.disable() | ||
}) | ||
|
||
describe('getFolders', function () { | ||
it('return folders', function () { | ||
const newState = bookmarkFoldersState.getFolders(stateWithData) | ||
assert.deepEqual(newState.toJS(), stateWithData.get(STATE_SITES.BOOKMARK_FOLDERS).toJS()) | ||
}) | ||
}) | ||
|
||
describe('getFolder', function () { | ||
it('null case', function () { | ||
const newState = bookmarkFoldersState.getFolder(stateWithData) | ||
assert.deepEqual(newState, Immutable.Map()) | ||
}) | ||
|
||
it('folder key is not found', function () { | ||
const newState = bookmarkFoldersState.getFolder(stateWithData, '100') | ||
assert.deepEqual(newState, Immutable.Map()) | ||
}) | ||
|
||
it('folder key is found', function () { | ||
const newState = bookmarkFoldersState.getFolder(stateWithData, '1') | ||
assert.deepEqual(newState.toJS(), stateWithData.getIn([STATE_SITES.BOOKMARK_FOLDERS, '1']).toJS()) | ||
}) | ||
}) | ||
|
||
describe('getFoldersByParentId', function () { | ||
it('null case', function () { | ||
const newState = bookmarkFoldersState.getFoldersByParentId(stateWithData) | ||
assert.deepEqual(newState, Immutable.List()) | ||
}) | ||
|
||
it('parent folder is not found', function () { | ||
const newState = bookmarkFoldersState.getFoldersByParentId(stateWithData, '1000') | ||
assert.deepEqual(newState, Immutable.List()) | ||
}) | ||
|
||
it('parent folder is found, but dont have any items', function () { | ||
const newState = bookmarkFoldersState.getFoldersByParentId(stateWithData, '69') | ||
assert.deepEqual(newState, Immutable.List()) | ||
}) | ||
|
||
it('parent folder has child item', function () { | ||
const newState = bookmarkFoldersState.getFoldersByParentId(stateWithData, '1') | ||
assert.deepEqual(newState, Immutable.fromJS([ | ||
{ | ||
title: 'folder2', | ||
folderId: 2, | ||
key: '2', | ||
parentFolderId: 1, | ||
partitionNumber: 0, | ||
objectId: null, | ||
type: siteTags.BOOKMARK_FOLDER | ||
} | ||
])) | ||
}) | ||
}) | ||
|
||
describe('addFolder', function () { | ||
it('null case', function () { | ||
const newState = bookmarkFoldersState.addFolder(state) | ||
assert.deepEqual(newState.toJS(), state.toJS()) | ||
}) | ||
|
||
it('folder key is provided', function () { | ||
const newState = bookmarkFoldersState.addFolder(state, { | ||
title: 'Brave', | ||
key: 10 | ||
}) | ||
const expectedState = state | ||
.setIn(['bookmarkFolders', '10'], Immutable.fromJS({ | ||
title: 'Brave', | ||
key: '10' | ||
})) | ||
.setIn(['cache', 'bookmarkOrder', '0'], Immutable.fromJS([ | ||
{ | ||
key: '10', | ||
order: 0, | ||
type: siteTags.BOOKMARK_FOLDER | ||
} | ||
])) | ||
assert.deepEqual(newState.toJS(), expectedState.toJS()) | ||
}) | ||
|
||
it('folder key is not provided', function () { | ||
const newState = bookmarkFoldersState.addFolder(stateWithData, { | ||
title: 'Brave' | ||
}) | ||
assert.deepEqual(newState.toJS(), stateWithData.toJS()) | ||
}) | ||
}) | ||
|
||
describe('editFolder', function () { | ||
it('', function () { | ||
|
||
}) | ||
|
||
it('', function () { | ||
|
||
}) | ||
}) | ||
|
||
describe('removeFolder', function () { | ||
it('', function () { | ||
|
||
}) | ||
|
||
it('', function () { | ||
|
||
}) | ||
}) | ||
|
||
describe('getFoldersWithoutKey', function () { | ||
it('', function () { | ||
|
||
}) | ||
|
||
it('', function () { | ||
|
||
}) | ||
}) | ||
|
||
describe('moveFolder', function () { | ||
it('', function () { | ||
|
||
}) | ||
|
||
it('', function () { | ||
|
||
}) | ||
}) | ||
}) |