From 8d7de52522fc68f44713968d468f068b9843d913 Mon Sep 17 00:00:00 2001 From: yan Date: Tue, 11 Jul 2017 16:14:47 -0700 Subject: [PATCH] Set bookmark parent ID to 0 if parentFolderObjectId is empty fix https://github.com/brave/sync/issues/107 Test Plan: follow test plan in https://github.com/brave/sync/issues/107 --- js/state/syncUtil.js | 6 ++-- test/unit/state/syncUtilTest.js | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/js/state/syncUtil.js b/js/state/syncUtil.js index bfec693a950..2439eef3d19 100644 --- a/js/state/syncUtil.js +++ b/js/state/syncUtil.js @@ -120,8 +120,10 @@ module.exports.getSiteDataFromRecord = (record, appState, records) => { if (parentFolderObjectId && parentFolderObjectId.length > 0) { siteProps.parentFolderId = getFolderIdByObjectId(new Immutable.List(parentFolderObjectId), appState, records) - } else if (siteProps.hideInToolbar === true) { - siteProps.parentFolderId = -1 + } else { + // Null or empty parentFolderObjectId on a record corresponds to + // a top-level bookmark. -1 indicates a hidden bookmark. + siteProps.parentFolderId = siteProps.hideInToolbar ? -1 : 0 } } const siteDetail = new Immutable.Map(pickFields(siteProps, SITE_FIELDS)) diff --git a/test/unit/state/syncUtilTest.js b/test/unit/state/syncUtilTest.js index 5b959bdd6e2..ea46346d4e8 100644 --- a/test/unit/state/syncUtilTest.js +++ b/test/unit/state/syncUtilTest.js @@ -2,6 +2,7 @@ const syncUtil = require('../../../js/state/syncUtil') const assert = require('assert') +const Immutable = require('immutable') describe('syncUtil', () => { describe('createSiteData()', () => { @@ -150,4 +151,65 @@ describe('syncUtil', () => { assert.deepEqual(syncUtil.ipcSafeObject(deepObject), deepExpected) }) }) + + describe('getSiteDataFromRecord()', () => { + it('update bookmark parent folder to null -> overrides existing parent folder', () => { + const objectId = [96, 46, 213, 0, 13, 111, 180, 184, 65, 66, 173, 27, 207, 29, 32, 108] + const records = [{ + action: 1, + bookmark: { + isFolder: true, + parentFolderObjectId: null, + site: { + creationTime: 0, + customTitle: '', + favicon: '', + lastAccessedTime: 0, + location: '', + title: 'Folder1' + } + }, + deviceId: [1], + objectData: 'bookmark', + objectId, + syncTimestamp: 1499736988267 + }] + const existingObject = { + lastAccessedTime: 0, + tags: ['bookmark-folder'], + objectId, + order: 9, + folderId: 2, + customTitle: 'Folder1', // XXX: Android uses title whereas laptop uses customTitle + parentFolderId: 1 + } + const appState = { + sites: { + '2': existingObject + }, + sync: { + objectsById: { + [objectId.join('|')]: ['sites', '2'] + } + } + } + const result = syncUtil.getSiteDataFromRecord(records[0], + Immutable.fromJS(appState), Immutable.fromJS(records)) + assert.equal(result.tag, 'bookmark-folder') + assert.deepEqual(result.siteDetail.toJS(), + { + objectId, + title: 'Folder1', + favicon: '', + location: '', + parentFolderId: 0, + folderId: 2, + tags: ['bookmark-folder'], + lastAccessedTime: 0, + creationTime: 0 + } + ) + assert.deepEqual(result.existingObjectData.toJS(), existingObject) + }) + }) })