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

Commit

Permalink
Merge pull request #3459 from bsclifton/bookmark-folders-history
Browse files Browse the repository at this point in the history
History bugfixes
  • Loading branch information
bridiver authored Aug 26, 2016
2 parents 74c3a33 + 1d8d935 commit a991cd3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
9 changes: 7 additions & 2 deletions js/about/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const aboutActions = require('./aboutActions')
const getSetting = require('../settings').getSetting
const SortableTable = require('../components/sortableTable')
const Button = require('../components/button')
const siteUtil = require('../state/siteUtil')

const ipc = window.chrome.ipc

Expand Down Expand Up @@ -71,7 +72,11 @@ class GroupedHistoryList extends ImmutableComponent {
}
return result
})
if (reduced) return reduced
if (reduced) {
return Array.isArray(reduced)
? reduced
: [{date: this.getDayString(locale, reduced), entries: [reduced]}]
}
return []
}
render () {
Expand Down Expand Up @@ -125,7 +130,7 @@ class AboutHistory extends React.Component {
})
}
historyDescendingOrder () {
return this.state.history.filter((site) => site.get('lastAccessedTime'))
return this.state.history.filter((site) => siteUtil.isHistoryEntry(site))
.sort((left, right) => {
if (left.get('lastAccessedTime') < right.get('lastAccessedTime')) return 1
if (left.get('lastAccessedTime') > right.get('lastAccessedTime')) return -1
Expand Down
15 changes: 15 additions & 0 deletions js/state/siteUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,21 @@ module.exports.isFolder = function (siteDetail) {
return false
}

/**
* Determines if the site detail is a history entry.
* @param siteDetail The site detail to check.
* @return true if the site detail is a history entry.
*/
module.exports.isHistoryEntry = function (siteDetail) {
if (siteDetail && typeof siteDetail.get('location') === 'string') {
if (siteDetail.get('location').startsWith('about:')) {
return false
}
return !!siteDetail.get('lastAccessedTime') && !module.exports.isFolder(siteDetail)
}
return false
}

/**
* Obtains an array of folders
*/
Expand Down
44 changes: 44 additions & 0 deletions test/unit/state/siteUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,50 @@ describe('siteUtil', function () {
})
})

describe('isHistoryEntry', function () {
it('returns true for a typical history entry', function () {
const siteDetail = Immutable.fromJS({
location: testUrl1,
lastAccessedTime: 123
})
assert.equal(siteUtil.isHistoryEntry(siteDetail), true)
})
it('returns true for a bookmark history entry which has lastAccessedTime', function () {
const siteDetail = Immutable.fromJS({
location: testUrl1,
tags: [siteTags.BOOKMARK],
lastAccessedTime: 123
})
assert.equal(siteUtil.isHistoryEntry(siteDetail), true)
})
it('returns false for a bookmark entry with falsey lastAccessedTime', function () {
const siteDetail = Immutable.fromJS({
location: testUrl1,
tags: [siteTags.BOOKMARK]
})
assert.equal(siteUtil.isHistoryEntry(siteDetail), false)
})
it('returns false for a bookmarks folder', function () {
const siteDetail = Immutable.fromJS({
location: testUrl1,
tags: [siteTags.BOOKMARK_FOLDER],
lastAccessedTime: 123
})
assert.equal(siteUtil.isHistoryEntry(siteDetail), false)
})
it('returns false if input is falsey', function () {
assert.equal(siteUtil.isHistoryEntry(null), false)
assert.equal(siteUtil.isHistoryEntry(undefined), false)
})
it('returns false for about: pages', function () {
const siteDetail = Immutable.fromJS({
location: 'about:fake-page-here',
lastAccessedTime: 123
})
assert.equal(siteUtil.isHistoryEntry(siteDetail), false)
})
})

describe('getFolders', function () {
})

Expand Down

0 comments on commit a991cd3

Please sign in to comment.