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

Commit 52731d8

Browse files
committed
Adds more unit tests
1 parent 6955ca1 commit 52731d8

File tree

8 files changed

+334
-74
lines changed

8 files changed

+334
-74
lines changed

app/browser/api/topSites.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const getTopSiteData = () => {
100100
.map((site, key) => {
101101
const bookmarkKey = bookmarkLocationCache.getCacheKey(state, site.get('location'))
102102

103-
site = site.set('bookmarked', !bookmarkKey.isEmpty())
103+
site = site.set('bookmarked', bookmarkKey.get(0, false))
104104
site = site.set('key', key)
105105
return site
106106
})
@@ -128,7 +128,7 @@ const getTopSiteData = () => {
128128
})
129129
.map(site => {
130130
const bookmarkKey = bookmarkLocationCache.getCacheKey(state, site.get('location'))
131-
return site.set('bookmarked', !bookmarkKey.isEmpty())
131+
return site.set('bookmarked', bookmarkKey.get(0, false))
132132
})
133133
sites = sites.concat(preDefined)
134134
}

app/common/lib/bookmarkUtil.js

+5-18
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ const isLocationBookmarked = (state, location) => {
195195
const bookmarks = bookmarksState.getBookmarks(state)
196196
const siteKeys = bookmarkLocationCache.getCacheKey(state, location)
197197

198-
if (siteKeys.isEmpty()) {
198+
if (siteKeys.isEmpty() || bookmarks.isEmpty()) {
199199
return false
200200
}
201201

@@ -218,20 +218,6 @@ const toCreateProperties = (bookmark) => {
218218
}
219219
}
220220

221-
/**
222-
* Filters bookmarks relative to a parent folder
223-
* @param state - The application state
224-
* @param folderKey The folder key to filter to
225-
*/
226-
const getBookmarksByParentId = (state, folderKey) => {
227-
const bookmarks = bookmarksState.getBookmarks(state)
228-
if (!folderKey) {
229-
return bookmarks
230-
}
231-
232-
return bookmarks.filter((bookmark) => bookmark.get('parentFolderId') === folderKey)
233-
}
234-
235221
const isBookmark = (bookmark) => {
236222
if (bookmark == null) {
237223
return false
@@ -241,9 +227,10 @@ const isBookmark = (bookmark) => {
241227
}
242228

243229
const updateTabBookmarked = (state, tabValue) => {
244-
if (!tabValue || !tabValue.get('tabId')) {
230+
if (!tabValue || !tabValue.has('tabId')) {
245231
return state
246232
}
233+
247234
const bookmarked = isLocationBookmarked(state, tabValue.get('url'))
248235
return tabState.updateTabValue(state, tabValue.set('bookmarked', bookmarked))
249236
}
@@ -253,7 +240,8 @@ const updateActiveTabBookmarked = (state) => {
253240
if (!tab) {
254241
return state
255242
}
256-
return updateTabBookmarked(state, tab)
243+
244+
return module.exports.updateTabBookmarked(state, tab)
257245
}
258246

259247
const getKey = (siteDetail) => {
@@ -282,7 +270,6 @@ module.exports = {
282270
getDetailFromFrame,
283271
isLocationBookmarked,
284272
toCreateProperties,
285-
getBookmarksByParentId,
286273
isBookmark,
287274
updateTabBookmarked,
288275
updateActiveTabBookmarked,

app/common/state/bookmarksState.js

+14
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,20 @@ const bookmarksState = {
283283
append
284284
)
285285
return state
286+
},
287+
288+
/**
289+
* Get bookmarks relative to a parent folder
290+
* @param state - The application state
291+
* @param folderKey The folder key to filter to
292+
*/
293+
getBookmarksByParentId: (state, folderKey) => {
294+
if (folderKey == null) {
295+
return Immutable.List()
296+
}
297+
298+
const cache = bookmarkOrderCache.getBookmarksByParentId(state, folderKey)
299+
return cache.map((item) => bookmarksState.getBookmark(state, item.get('key')))
286300
}
287301
}
288302

docs/state.md

+12
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ AppStore
7777
title: string
7878
}
7979
},
80+
cache: {
81+
bookmarLocation: {
82+
[location]: Array<string> // array of bookmark keys
83+
},
84+
bookmarkOrder: {
85+
[parentId]: [{
86+
key: string, // bookmark or folder key
87+
order: number,
88+
type: string // siteTags.BOOKMARK or siteTags.BOOKMARK_FOLDER
89+
}]
90+
}
91+
}
8092
clearBrowsingDataDefaults: {
8193
allSiteCookies: boolean,
8294
autocompleteData: boolean,

js/about/newtab.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class NewTabPage extends React.Component {
169169

170170
onToggleBookmark (site) {
171171
if (site.get('bookmarked')) {
172-
windowActions.editBookmark(site.get('key'))
172+
windowActions.editBookmark(site.get('bookmarked'))
173173
} else {
174174
windowActions.onBookmarkAdded(false, site)
175175
}

js/actions/bookmarkActions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const {getSetting} = require('../settings')
1616

1717
const bookmarkActions = {
1818
openBookmarksInFolder: function (folderDetail) {
19-
const bookmarks = bookmarksUtil.getBookmarksByParentId(appStoreRenderer.state, folderDetail.get('folderId'))
19+
const bookmarks = bookmarksState.getBookmarksByParentId(appStoreRenderer.state, folderDetail.get('folderId'))
2020

2121
// Only load the first 25 tabs as loaded
2222
bookmarks

0 commit comments

Comments
 (0)