From dc5d3b7ad01644d918f792a7456e11a78473cb26 Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Sun, 28 Aug 2016 03:09:07 -0700 Subject: [PATCH] Clearing history using modal now clears bookmark timestamps Fixes https://github.com/brave/browser-laptop/issues/3346 --- js/state/siteUtil.js | 8 +++++++- test/unit/state/siteUtilTest.js | 34 +++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/js/state/siteUtil.js b/js/state/siteUtil.js index 0f81d645992..5d2b8f0fc20 100644 --- a/js/state/siteUtil.js +++ b/js/state/siteUtil.js @@ -372,7 +372,13 @@ module.exports.filterSitesRelativeTo = function (sites, relSite) { * @param sites The application state's Immutable sites list. */ module.exports.clearSitesWithoutTags = function (sites) { - return sites.filter((site) => site.get('tags') && site.get('tags').size > 0) + let clearedSites = sites.filter((site) => site.get('tags') && site.get('tags').size > 0) + clearedSites.forEach((site, index) => { + if (site.get('lastAccessedTime')) { + clearedSites = clearedSites.setIn([index, 'lastAccessedTime'], null) + } + }) + return clearedSites } /** diff --git a/test/unit/state/siteUtilTest.js b/test/unit/state/siteUtilTest.js index a5d56a20f75..6dfacb99562 100644 --- a/test/unit/state/siteUtilTest.js +++ b/test/unit/state/siteUtilTest.js @@ -469,15 +469,33 @@ describe('siteUtil', function () { describe('clearSitesWithoutTags', function () { it('does not remove sites which have a valid `tags` property', function () { - const sites = [ - Immutable.fromJS({ - tags: [siteTags.BOOKMARK_FOLDER] - }), - Immutable.fromJS({ - tags: [siteTags.BOOKMARK] - })] + const sites = Immutable.fromJS([ + { tags: [siteTags.BOOKMARK_FOLDER] }, + { tags: [siteTags.BOOKMARK] } + ]) const processedSites = siteUtil.clearSitesWithoutTags(sites) - assert.deepEqual(sites, processedSites) + assert.deepEqual(processedSites.toJS(), sites.toJS()) + }) + it('sets the lastAccessedTime for all entries to null', function () { + const sites = Immutable.fromJS([ + { + location: 'location1', + tags: [], + lastAccessedTime: 123 + }, + { + location: 'location2', + tags: [siteTags.BOOKMARK], + lastAccessedTime: 123 + } + ]) + const expectedSites = Immutable.fromJS([{ + location: 'location2', + tags: [siteTags.BOOKMARK], + lastAccessedTime: null + }]) + const processedSites = siteUtil.clearSitesWithoutTags(sites) + assert.deepEqual(processedSites.toJS(), expectedSites.toJS()) }) })