From d83631d7f22e83de3751910bbf57a72366463b7e Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Wed, 20 Jan 2021 15:53:12 -0400 Subject: [PATCH] [FIX] Spotlight returning duplicated entries (#2805) * Update rocketchat.js * Updated search function * Minor improvements * Remove atIndex * Add remove logic to remove duplicate data from response Co-authored-by: Diego Mello --- app/lib/rocketchat.js | 24 +++++++++++-------- e2e/tests/assorted/05-joinpublicroom.spec.js | 4 ++-- .../assorted/08-joinprotectedroom.spec.js | 4 ++-- e2e/tests/onboarding/06-roomslist.spec.js | 2 +- e2e/tests/room/01-createroom.spec.js | 4 ++-- e2e/tests/room/03-roomactions.spec.js | 4 ++-- e2e/tests/room/04-roominfo.spec.js | 4 ++-- package.json | 6 +++-- 8 files changed, 29 insertions(+), 23 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 58aa40ed4..721222754 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -627,8 +627,7 @@ const RocketChat = { fname: sub.fname, avatarETag: sub.avatarETag, t: sub.t, - encrypted: sub.encrypted, - search: true + encrypted: sub.encrypted }; } return sub; @@ -648,7 +647,7 @@ const RocketChat = { return []; } - let data = await this.localSearch({ text, filterUsers, filterRooms }); + const data = await this.localSearch({ text, filterUsers, filterRooms }); const usernames = data.map(sub => sub.name); try { @@ -658,13 +657,18 @@ const RocketChat = { new Promise((resolve, reject) => this.oldPromise = reject) ]); if (filterUsers) { - data = data.concat(users.map(user => ({ - ...user, - rid: user.username, - name: user.username, - t: 'd', - search: true - }))); + users + .filter((item1, index) => users.findIndex(item2 => item2._id === item1._id) === index) // Remove duplicated data from response + .filter(user => !data.some(sub => user.username === sub.name)) // Make sure to remove users already on local database + .forEach((user) => { + data.push({ + ...user, + rid: user.username, + name: user.username, + t: 'd', + search: true + }); + }); } if (filterRooms) { rooms.forEach((room) => { diff --git a/e2e/tests/assorted/05-joinpublicroom.spec.js b/e2e/tests/assorted/05-joinpublicroom.spec.js index 1c946f0c2..90707f9f9 100644 --- a/e2e/tests/assorted/05-joinpublicroom.spec.js +++ b/e2e/tests/assorted/05-joinpublicroom.spec.js @@ -9,8 +9,8 @@ const room = data.channels.detoxpublic.name; async function navigateToRoom() { await searchRoom(room); - await waitFor(element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0)).toBeVisible().withTimeout(60000); - await element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0).tap(); + await waitFor(element(by.id(`rooms-list-view-item-${ room }`))).toBeVisible().withTimeout(60000); + await element(by.id(`rooms-list-view-item-${ room }`)).tap(); await waitFor(element(by.id('room-view'))).toBeVisible().withTimeout(5000); } diff --git a/e2e/tests/assorted/08-joinprotectedroom.spec.js b/e2e/tests/assorted/08-joinprotectedroom.spec.js index d6e5605f7..32b23e9b3 100644 --- a/e2e/tests/assorted/08-joinprotectedroom.spec.js +++ b/e2e/tests/assorted/08-joinprotectedroom.spec.js @@ -10,8 +10,8 @@ const joinCode = data.channels.detoxpublicprotected.joinCode async function navigateToRoom() { await searchRoom(room); - await waitFor(element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0)).toBeVisible().withTimeout(60000); - await element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0).tap(); + await waitFor(element(by.id(`rooms-list-view-item-${ room }`))).toBeVisible().withTimeout(60000); + await element(by.id(`rooms-list-view-item-${ room }`)).tap(); await waitFor(element(by.id('room-view'))).toBeVisible().withTimeout(5000); } diff --git a/e2e/tests/onboarding/06-roomslist.spec.js b/e2e/tests/onboarding/06-roomslist.spec.js index bbe0b886b..e213b7f2c 100644 --- a/e2e/tests/onboarding/06-roomslist.spec.js +++ b/e2e/tests/onboarding/06-roomslist.spec.js @@ -18,7 +18,7 @@ describe('Rooms list screen', () => { }); it('should have room item', async() => { - await expect(element(by.id('rooms-list-view-item-general')).atIndex(0)).toExist(); + await expect(element(by.id('rooms-list-view-item-general'))).toExist(); }); // Render - Header diff --git a/e2e/tests/room/01-createroom.spec.js b/e2e/tests/room/01-createroom.spec.js index 5a726a967..07ecd8030 100644 --- a/e2e/tests/room/01-createroom.spec.js +++ b/e2e/tests/room/01-createroom.spec.js @@ -67,12 +67,12 @@ describe('Create room screen', () => { it('should select/unselect user', async() => { // Spotlight issues - await element(by.id('select-users-view-item-rocket.cat')).atIndex(0).tap(); + await element(by.id('select-users-view-item-rocket.cat')).tap(); await waitFor(element(by.id('selected-user-rocket.cat'))).toBeVisible().withTimeout(10000); await element(by.id('selected-user-rocket.cat')).tap(); await waitFor(element(by.id('selected-user-rocket.cat'))).toBeNotVisible().withTimeout(10000); // Spotlight issues - await element(by.id('select-users-view-item-rocket.cat')).atIndex(0).tap(); + await element(by.id('select-users-view-item-rocket.cat')).tap(); await waitFor(element(by.id('selected-user-rocket.cat'))).toBeVisible().withTimeout(10000); }); diff --git a/e2e/tests/room/03-roomactions.spec.js b/e2e/tests/room/03-roomactions.spec.js index 4cdbbff71..74b3114b2 100644 --- a/e2e/tests/room/03-roomactions.spec.js +++ b/e2e/tests/room/03-roomactions.spec.js @@ -13,8 +13,8 @@ async function navigateToRoomActions(type) { room = data.groups.private.name; } await searchRoom(room); - await waitFor(element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0)).toExist().withTimeout(60000); - await element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0).tap(); + await waitFor(element(by.id(`rooms-list-view-item-${ room }`))).toExist().withTimeout(60000); + await element(by.id(`rooms-list-view-item-${ room }`)).tap(); await waitFor(element(by.id('room-view'))).toExist().withTimeout(2000); await element(by.id('room-view-header-actions')).tap(); await waitFor(element(by.id('room-actions-view'))).toExist().withTimeout(5000); diff --git a/e2e/tests/room/04-roominfo.spec.js b/e2e/tests/room/04-roominfo.spec.js index d8f079b50..9fd9aebbf 100644 --- a/e2e/tests/room/04-roominfo.spec.js +++ b/e2e/tests/room/04-roominfo.spec.js @@ -14,8 +14,8 @@ async function navigateToRoomInfo(type) { room = privateRoomName; } await searchRoom(room); - await waitFor(element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0)).toExist().withTimeout(60000); - await element(by.id(`rooms-list-view-item-${ room }`)).atIndex(0).tap(); + await waitFor(element(by.id(`rooms-list-view-item-${ room }`))).toExist().withTimeout(60000); + await element(by.id(`rooms-list-view-item-${ room }`)).tap(); await waitFor(element(by.id('room-view'))).toExist().withTimeout(2000); await element(by.id('room-view-header-actions')).tap(); await waitFor(element(by.id('room-actions-view'))).toExist().withTimeout(5000); diff --git a/package.json b/package.json index 26768e8ea..a8b85b5e7 100644 --- a/package.json +++ b/package.json @@ -193,7 +193,8 @@ "build": "xcodebuild -workspace ios/RocketChatRN.xcworkspace -scheme RocketChatRN -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build", "type": "ios.simulator", "device": { - "type": "iPhone 11 Pro" + "type": "iPhone 11 Pro", + "os": "13.7" } }, "ios.sim.release": { @@ -201,7 +202,8 @@ "build": "xcodebuild -workspace ios/RocketChatRN.xcworkspace -scheme RocketChatRN -configuration Release -sdk iphonesimulator -derivedDataPath ios/build", "type": "ios.simulator", "device": { - "type": "iPhone 11 Pro" + "type": "iPhone 11 Pro", + "os": "13.7" }, "artifacts": { "plugins": {