From 956dc143ec5351550be83b884d0cacf5ad1a3853 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Mon, 4 Apr 2022 19:36:11 -0400 Subject: [PATCH 01/20] Show empty policyExpenseChats in LHN just like defaultRooms --- src/libs/OptionsListUtils.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 8c600a2cb4eb..ae048986670a 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -431,6 +431,7 @@ function getOptions(reports, personalDetails, activeReportID, { const isChatRoom = ReportUtils.isChatRoom(report); const isDefaultRoom = ReportUtils.isDefaultRoom(report); const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); + const isArchivedRoom = ReportUtils.isArchivedRoom(report); const logins = lodashGet(report, ['participants'], []); // Report data can sometimes be incomplete. If we have no logins or reportID then we will skip this entry. @@ -445,7 +446,12 @@ function getOptions(reports, personalDetails, activeReportID, { : ''; const reportContainsIOUDebt = iouReportOwner && iouReportOwner !== currentUserLogin; - const shouldFilterReportIfEmpty = !showReportsWithNoComments && report.lastMessageTimestamp === 0 && !isDefaultRoom; + const shouldFilterReportIfEmpty = !showReportsWithNoComments && report.lastMessageTimestamp === 0 + + // We make exceptions for active defaultRooms and policyExpenseChats so we can immediately + // highlight them in the LHN when they are created and have no messsages yet + && (!isArchivedRoom && (isDefaultRoom || isPolicyExpenseChat)); + const shouldFilterReportIfRead = hideReadReports && report.unreadActionCount === 0; const shouldFilterReport = shouldFilterReportIfEmpty || shouldFilterReportIfRead; if (report.reportID !== activeReportID From 42158c43059282c016062e9ba661745cef281680 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Tue, 5 Apr 2022 12:20:01 -0400 Subject: [PATCH 02/20] Fix boolean logic so active rooms are showing instead of inactive ones --- src/libs/OptionsListUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 23428d8b693d..4e3f0bf6d922 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -450,7 +450,7 @@ function getOptions(reports, personalDetails, activeReportID, { // We make exceptions for active defaultRooms and policyExpenseChats so we can immediately // highlight them in the LHN when they are created and have no messsages yet - && (!isArchivedRoom && (isDefaultRoom || isPolicyExpenseChat)); + && !(!isArchivedRoom && (isDefaultRoom || isPolicyExpenseChat)); const shouldFilterReportIfRead = hideReadReports && report.unreadActionCount === 0; const shouldFilterReport = shouldFilterReportIfEmpty || shouldFilterReportIfRead; From 9d7ca21db1d02a9cea661be3929e191ad6b379f4 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Thu, 7 Apr 2022 11:40:55 -0400 Subject: [PATCH 03/20] =?UTF-8?q?Remove=C2=A0extra=20variable=20use?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/OptionsListUtils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 4e3f0bf6d922..f0ac086cc8d2 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -431,7 +431,6 @@ function getOptions(reports, personalDetails, activeReportID, { const isChatRoom = ReportUtils.isChatRoom(report); const isDefaultRoom = ReportUtils.isDefaultRoom(report); const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); - const isArchivedRoom = ReportUtils.isArchivedRoom(report); const logins = lodashGet(report, ['participants'], []); // Report data can sometimes be incomplete. If we have no logins or reportID then we will skip this entry. @@ -450,7 +449,7 @@ function getOptions(reports, personalDetails, activeReportID, { // We make exceptions for active defaultRooms and policyExpenseChats so we can immediately // highlight them in the LHN when they are created and have no messsages yet - && !(!isArchivedRoom && (isDefaultRoom || isPolicyExpenseChat)); + && !(!ReportUtils.isArchivedRoom(report) && (isDefaultRoom || isPolicyExpenseChat)); const shouldFilterReportIfRead = hideReadReports && report.unreadActionCount === 0; const shouldFilterReport = shouldFilterReportIfEmpty || shouldFilterReportIfRead; From b0727c256b7e5cb4304d877c386a25b1ae18033e Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Thu, 7 Apr 2022 11:43:17 -0400 Subject: [PATCH 04/20] more clear comment --- src/libs/OptionsListUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index f0ac086cc8d2..1675806beb4f 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -447,7 +447,7 @@ function getOptions(reports, personalDetails, activeReportID, { const reportContainsIOUDebt = iouReportOwner && iouReportOwner !== currentUserLogin; const shouldFilterReportIfEmpty = !showReportsWithNoComments && report.lastMessageTimestamp === 0 - // We make exceptions for active defaultRooms and policyExpenseChats so we can immediately + // We make exceptions for nonarchived defaultRooms and policyExpenseChats so we can immediately // highlight them in the LHN when they are created and have no messsages yet && !(!ReportUtils.isArchivedRoom(report) && (isDefaultRoom || isPolicyExpenseChat)); From b289cf615db34691e522ddbaed6391dba43e4388 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Fri, 15 Apr 2022 12:55:18 -0400 Subject: [PATCH 05/20] Better comment --- src/libs/OptionsListUtils.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 5495bf66b65d..b3489fdd1d87 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -450,8 +450,9 @@ function getOptions(reports, personalDetails, activeReportID, { const reportContainsIOUDebt = iouReportOwner && iouReportOwner !== currentUserLogin; const shouldFilterReportIfEmpty = !showReportsWithNoComments && report.lastMessageTimestamp === 0 - // We make exceptions for nonarchived defaultRooms and policyExpenseChats so we can immediately - // highlight them in the LHN when they are created and have no messsages yet + // We make exceptions for defaultRooms and policyExpenseChats so we can immediately + // highlight them in the LHN when they are created and have no messsages yet. We do + // not give archived rooms this exception since they do not need to be higlihted. && !(!ReportUtils.isArchivedRoom(report) && (isDefaultRoom || isPolicyExpenseChat)); const shouldFilterReportIfRead = hideReadReports && report.unreadActionCount === 0; From 4158a3bef7c1ff08fec19c2c5f47c0dda593fe00 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Fri, 15 Apr 2022 12:56:23 -0400 Subject: [PATCH 06/20] DRY variables --- src/libs/OptionsListUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index b3489fdd1d87..cdf6b385104e 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -482,7 +482,7 @@ function getOptions(reports, personalDetails, activeReportID, { // Save the report in the map if this is a single participant so we can associate the reportID with the // personal detail option later. Individuals should not be associated with single participant // policyExpenseChats or chatRooms since those are not people. - if (logins.length <= 1 && !ReportUtils.isPolicyExpenseChat(report) && !ReportUtils.isChatRoom(report)) { + if (logins.length <= 1 && !isPolicyExpenseChat && !isChatRoom) { reportMapForLogins[logins[0]] = report; } const isSearchingSomeonesPolicyExpenseChat = !report.isOwnPolicyExpenseChat && searchValue !== ''; From 4fcb88d883bda6e1578a4cbbb52c9691571430bd Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Fri, 15 Apr 2022 14:58:21 -0400 Subject: [PATCH 07/20] Add empty policyExpenseChat for tests --- tests/unit/OptionsListUtilsTest.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 15a9a7978304..726c1e258665 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -100,6 +100,22 @@ describe('OptionsListUtils', () => { iouReportID: 100, hasOutstandingIOU: true, }, + + // Note: This reoprt is a PolicyExpenseChat without any messages in it + 10: { + chatType: "policyExpenseChat", + hasOutstandingIOU: false, + isOwnPolicyExpenseChat: true, + isPinned: false, + lastMessageTimestamp: 0, + lastVisitedTimestamp: 1610666739302, + participants: ['test3@instantworkspace.com'], + policyID: "Whatever", + reportID: 10, + reportName: "Someone's workspace", + unreadActionCount: 0, + visibility: undefined, + }, }; // And a set of personalDetails some with existing reports and some without From d038730d636125afb39646636dd6621e6b87da98 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Fri, 15 Apr 2022 15:08:49 -0400 Subject: [PATCH 08/20] Add default room for testing --- tests/unit/OptionsListUtilsTest.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 726c1e258665..633c59d5773a 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -116,6 +116,21 @@ describe('OptionsListUtils', () => { unreadActionCount: 0, visibility: undefined, }, + + // Note: This reoprt is a defaultRoom without any messages in it + 11: { + chatType: "defaultRoom", + hasOutstandingIOU: false, + isPinned: false, + lastMessageTimestamp: 0, + lastVisitedTimestamp: 1610666739302, + participants: ['test3@instantworkspace.com'], + policyID: "Whatever", + reportID: 11, + reportName: "#admins", + unreadActionCount: 0, + visibility: undefined, + }, }; // And a set of personalDetails some with existing reports and some without @@ -659,8 +674,9 @@ describe('OptionsListUtils', () => { const results = OptionsListUtils.getSidebarOptions(REPORTS_WITH_MORE_PINS, PERSONAL_DETAILS, 0, CONST.PRIORITY_MODE.GSD); // Then expect all of the reports to be shown both multiple and single participant except the - // report that has no lastMessageTimestamp and the chat with Thor who's message is read - expect(results.recentReports.length).toBe(_.size(REPORTS_WITH_MORE_PINS) - 2); + // report that has no lastMessageTimestamp, the chat with Thor who's message is read, and the + // empty PolicyExpenseChats and DefaultRooms + expect(results.recentReports.length).toBe(_.size(REPORTS_WITH_MORE_PINS) - 4); // That no personalDetails are shown expect(results.personalDetails.length).toBe(0); From 3fefa46750d28bcacbc93cad9a12ce699630ba80 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Fri, 15 Apr 2022 15:12:15 -0400 Subject: [PATCH 09/20] Fix test for defaultRooms --- tests/unit/OptionsListUtilsTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 633c59d5773a..b018a8f1fd4b 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -119,7 +119,7 @@ describe('OptionsListUtils', () => { // Note: This reoprt is a defaultRoom without any messages in it 11: { - chatType: "defaultRoom", + chatType: "policyAdmins", hasOutstandingIOU: false, isPinned: false, lastMessageTimestamp: 0, @@ -644,7 +644,7 @@ describe('OptionsListUtils', () => { ); // Then expect all of the reports to be shown both multiple and single participant except the - // unpinned report that has no lastMessageTimestamp + // unpinned report that has no lastMessageTimestamp and is not a policyExpenseChat or defaultRoom expect(results.recentReports.length).toBe(_.size(reportsWithAddedPinnedMessagelessReport) - 1); const numberOfPinnedReports = _.filter(results.recentReports, report => report.isPinned).length; From 8f702f32ba302c899f51d624c6125f40bb54daa0 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Fri, 15 Apr 2022 15:13:36 -0400 Subject: [PATCH 10/20] Better comment --- tests/unit/OptionsListUtilsTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index b018a8f1fd4b..b1de46f4b588 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -101,7 +101,7 @@ describe('OptionsListUtils', () => { hasOutstandingIOU: true, }, - // Note: This reoprt is a PolicyExpenseChat without any messages in it + // Note: This reoprt is a policyExpenseChat without any messages in it (i.e. no lastMessageTimestamp) 10: { chatType: "policyExpenseChat", hasOutstandingIOU: false, @@ -117,7 +117,7 @@ describe('OptionsListUtils', () => { visibility: undefined, }, - // Note: This reoprt is a defaultRoom without any messages in it + // Note: This reoprt is a defaultRoom without any messages in it (i.e. no lastMessageTimestamp) 11: { chatType: "policyAdmins", hasOutstandingIOU: false, From a532e98304f584bb9ab45d74b734662d42128c4b Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Fri, 15 Apr 2022 15:19:58 -0400 Subject: [PATCH 11/20] use singlequotes for style --- tests/unit/OptionsListUtilsTest.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index b1de46f4b588..667ed04ee033 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -103,31 +103,31 @@ describe('OptionsListUtils', () => { // Note: This reoprt is a policyExpenseChat without any messages in it (i.e. no lastMessageTimestamp) 10: { - chatType: "policyExpenseChat", + chatType: 'policyExpenseChat', hasOutstandingIOU: false, isOwnPolicyExpenseChat: true, isPinned: false, lastMessageTimestamp: 0, lastVisitedTimestamp: 1610666739302, participants: ['test3@instantworkspace.com'], - policyID: "Whatever", + policyID: 'Whatever', reportID: 10, - reportName: "Someone's workspace", + reportName: 'Someone's workspace', unreadActionCount: 0, visibility: undefined, }, // Note: This reoprt is a defaultRoom without any messages in it (i.e. no lastMessageTimestamp) 11: { - chatType: "policyAdmins", + chatType: 'policyAdmins', hasOutstandingIOU: false, isPinned: false, lastMessageTimestamp: 0, lastVisitedTimestamp: 1610666739302, participants: ['test3@instantworkspace.com'], - policyID: "Whatever", + policyID: 'Whatever', reportID: 11, - reportName: "#admins", + reportName: '#admins', unreadActionCount: 0, visibility: undefined, }, From 4f7b7567d9fc52be0b3908530f519a1a88bd47f0 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Fri, 15 Apr 2022 15:20:28 -0400 Subject: [PATCH 12/20] Fix typo --- tests/unit/OptionsListUtilsTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 667ed04ee033..5b9c078f50cc 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -112,7 +112,7 @@ describe('OptionsListUtils', () => { participants: ['test3@instantworkspace.com'], policyID: 'Whatever', reportID: 10, - reportName: 'Someone's workspace', + reportName: "Someone's workspace", unreadActionCount: 0, visibility: undefined, }, From b41b27e27fb50fcecffd99e2aa24430f216e235e Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Mon, 18 Apr 2022 11:47:02 -0400 Subject: [PATCH 13/20] Better test comments --- tests/unit/OptionsListUtilsTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 5b9c078f50cc..f31916fb0133 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -643,8 +643,8 @@ describe('OptionsListUtils', () => { CONST.PRIORITY_MODE.DEFAULT, ); - // Then expect all of the reports to be shown both multiple and single participant except the - // unpinned report that has no lastMessageTimestamp and is not a policyExpenseChat or defaultRoom + // Then expect all of the reports to be shown, both multiple and single participant, except the + // unpinned reports that have no lastMessageTimestamp (excluding policyExpenseChats and defaultRooms) expect(results.recentReports.length).toBe(_.size(reportsWithAddedPinnedMessagelessReport) - 1); const numberOfPinnedReports = _.filter(results.recentReports, report => report.isPinned).length; @@ -675,7 +675,7 @@ describe('OptionsListUtils', () => { // Then expect all of the reports to be shown both multiple and single participant except the // report that has no lastMessageTimestamp, the chat with Thor who's message is read, and the - // empty PolicyExpenseChats and DefaultRooms + // empty policyExpenseChats and defaultRooms expect(results.recentReports.length).toBe(_.size(REPORTS_WITH_MORE_PINS) - 4); // That no personalDetails are shown From 5bbe6705ca78ce2f47ecd403a17a00b1b2cbbe4f Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Mon, 18 Apr 2022 12:55:09 -0400 Subject: [PATCH 14/20] Remove policyExpenseChat and defaultRooms from general report filtering tests --- tests/unit/OptionsListUtilsTest.js | 40 +++--------------------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index f31916fb0133..15a9a7978304 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -100,37 +100,6 @@ describe('OptionsListUtils', () => { iouReportID: 100, hasOutstandingIOU: true, }, - - // Note: This reoprt is a policyExpenseChat without any messages in it (i.e. no lastMessageTimestamp) - 10: { - chatType: 'policyExpenseChat', - hasOutstandingIOU: false, - isOwnPolicyExpenseChat: true, - isPinned: false, - lastMessageTimestamp: 0, - lastVisitedTimestamp: 1610666739302, - participants: ['test3@instantworkspace.com'], - policyID: 'Whatever', - reportID: 10, - reportName: "Someone's workspace", - unreadActionCount: 0, - visibility: undefined, - }, - - // Note: This reoprt is a defaultRoom without any messages in it (i.e. no lastMessageTimestamp) - 11: { - chatType: 'policyAdmins', - hasOutstandingIOU: false, - isPinned: false, - lastMessageTimestamp: 0, - lastVisitedTimestamp: 1610666739302, - participants: ['test3@instantworkspace.com'], - policyID: 'Whatever', - reportID: 11, - reportName: '#admins', - unreadActionCount: 0, - visibility: undefined, - }, }; // And a set of personalDetails some with existing reports and some without @@ -643,8 +612,8 @@ describe('OptionsListUtils', () => { CONST.PRIORITY_MODE.DEFAULT, ); - // Then expect all of the reports to be shown, both multiple and single participant, except the - // unpinned reports that have no lastMessageTimestamp (excluding policyExpenseChats and defaultRooms) + // Then expect all of the reports to be shown both multiple and single participant except the + // unpinned report that has no lastMessageTimestamp expect(results.recentReports.length).toBe(_.size(reportsWithAddedPinnedMessagelessReport) - 1); const numberOfPinnedReports = _.filter(results.recentReports, report => report.isPinned).length; @@ -674,9 +643,8 @@ describe('OptionsListUtils', () => { const results = OptionsListUtils.getSidebarOptions(REPORTS_WITH_MORE_PINS, PERSONAL_DETAILS, 0, CONST.PRIORITY_MODE.GSD); // Then expect all of the reports to be shown both multiple and single participant except the - // report that has no lastMessageTimestamp, the chat with Thor who's message is read, and the - // empty policyExpenseChats and defaultRooms - expect(results.recentReports.length).toBe(_.size(REPORTS_WITH_MORE_PINS) - 4); + // report that has no lastMessageTimestamp and the chat with Thor who's message is read + expect(results.recentReports.length).toBe(_.size(REPORTS_WITH_MORE_PINS) - 2); // That no personalDetails are shown expect(results.personalDetails.length).toBe(0); From fb12ea46584e30e9396648678ac3689375b43e74 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Mon, 18 Apr 2022 12:56:06 -0400 Subject: [PATCH 15/20] Add separate tests for empty policyExpenseChats and defaultRooms in sidebarOptions --- tests/unit/OptionsListUtilsTest.js | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 15a9a7978304..4b5c2cf313f9 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -675,4 +675,54 @@ describe('OptionsListUtils', () => { // Spider-Man report name is last report and has unread message expect(results.recentReports[8].login).toBe('peterparker@expensify.com'); })); + + it('getSidebarOptions() with empty policyExpenseChats and defaultRooms', () => { + const reportsWithEmptyChatRooms = { + ...REPORTS, + + // Note: This report is a policyExpenseChat without any messages in it (i.e. no lastMessageTimestamp) + 10: { + chatType: 'policyExpenseChat', + hasOutstandingIOU: false, + isOwnPolicyExpenseChat: true, + isPinned: false, + lastMessageTimestamp: 0, + lastVisitedTimestamp: 1610666739302, + participants: ['test3@instantworkspace.com'], + policyID: 'Whatever', + reportID: 10, + reportName: "Someone's workspace", + unreadActionCount: 0, + visibility: undefined, + }, + + // Note: This report is a defaultRoom without any messages in it (i.e. no lastMessageTimestamp) + 11: { + chatType: 'policyAdmins', + hasOutstandingIOU: false, + isPinned: false, + lastMessageTimestamp: 0, + lastVisitedTimestamp: 1610666739302, + participants: ['test3@instantworkspace.com'], + policyID: 'Whatever', + reportID: 11, + reportName: '#admins', + unreadActionCount: 0, + visibility: undefined, + }, + }; + + // First we call getSidebarOptions() with no search value and default priority mode + let results = OptionsListUtils.getSidebarOptions( + reportsWithEmptyChatRooms, + PERSONAL_DETAILS, + 0, + CONST.PRIORITY_MODE.DEFAULT, + ); + + // Then expect all of the reports to be shown except the unpinned reports that have no lastMessageTimestamp + // and are not policyExpenseChats or defaultRooms. The archived policyExpenseChats and defaultRooms should + // also not be included + expect(results.recentReports.length).toBe(_.size(reportsWithEmptyChatRooms) - 1); + }); }); From 03ce590c6a4c91af623b56626f4e0c39aa0bdd4b Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Mon, 18 Apr 2022 13:06:08 -0400 Subject: [PATCH 16/20] Add archived rooms to empty rooms tests --- tests/unit/OptionsListUtilsTest.js | 43 +++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 4b5c2cf313f9..09c81a0cdd57 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -680,7 +680,7 @@ describe('OptionsListUtils', () => { const reportsWithEmptyChatRooms = { ...REPORTS, - // Note: This report is a policyExpenseChat without any messages in it (i.e. no lastMessageTimestamp) + // This report is a policyExpenseChat without any messages in it (i.e. no lastMessageTimestamp) 10: { chatType: 'policyExpenseChat', hasOutstandingIOU: false, @@ -696,19 +696,54 @@ describe('OptionsListUtils', () => { visibility: undefined, }, - // Note: This report is a defaultRoom without any messages in it (i.e. no lastMessageTimestamp) + // This is an archived version of the above policyExpenseChat 11: { - chatType: 'policyAdmins', + chatType: 'policyExpenseChat', hasOutstandingIOU: false, + isOwnPolicyExpenseChat: true, isPinned: false, lastMessageTimestamp: 0, lastVisitedTimestamp: 1610666739302, participants: ['test3@instantworkspace.com'], policyID: 'Whatever', reportID: 11, + reportName: "Someone's workspace", + unreadActionCount: 0, + visibility: undefined, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS.CLOSED, + }, + + // Note: This report is a defaultRoom without any messages in it (i.e. no lastMessageTimestamp) + 12: { + chatType: 'policyAdmins', + hasOutstandingIOU: false, + isPinned: false, + lastMessageTimestamp: 0, + lastVisitedTimestamp: 1610666739302, + participants: ['test3@instantworkspace.com'], + policyID: 'Whatever', + reportID: 12, + reportName: '#admins', + unreadActionCount: 0, + visibility: undefined, + }, + + // This is an archived version of the above defaultRoom + 13: { + chatType: 'policyAdmins', + hasOutstandingIOU: false, + isPinned: false, + lastMessageTimestamp: 0, + lastVisitedTimestamp: 1610666739302, + participants: ['test3@instantworkspace.com'], + policyID: 'Whatever', + reportID: 13, reportName: '#admins', unreadActionCount: 0, visibility: undefined, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS.CLOSED, }, }; @@ -723,6 +758,6 @@ describe('OptionsListUtils', () => { // Then expect all of the reports to be shown except the unpinned reports that have no lastMessageTimestamp // and are not policyExpenseChats or defaultRooms. The archived policyExpenseChats and defaultRooms should // also not be included - expect(results.recentReports.length).toBe(_.size(reportsWithEmptyChatRooms) - 1); + expect(results.recentReports.length).toBe(_.size(reportsWithEmptyChatRooms) - 3); }); }); From 00af71e720bfa20e93c3469707b5823cbeb2fe29 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Mon, 18 Apr 2022 13:21:29 -0400 Subject: [PATCH 17/20] Add test for GSD priority --- tests/unit/OptionsListUtilsTest.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 09c81a0cdd57..9e73d97169cc 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -759,5 +759,18 @@ describe('OptionsListUtils', () => { // and are not policyExpenseChats or defaultRooms. The archived policyExpenseChats and defaultRooms should // also not be included expect(results.recentReports.length).toBe(_.size(reportsWithEmptyChatRooms) - 3); + + // Now we call getSidebarOptions() with no search value and GSD priority mode + results = OptionsListUtils.getSidebarOptions( + reportsWithEmptyChatRooms, + PERSONAL_DETAILS, + 0, + CONST.PRIORITY_MODE.GSD, + ); + + // Then expect all of the reports to be shown except the unpinned reports that have no lastMessageTimestamp + // and are not policyExpenseChats or defaultRooms. The archived policyExpenseChats and defaultRooms should + // also not be included + expect(results.recentReports.length).toBe(_.size(reportsWithEmptyChatRooms) - 5); }); }); From c002367bda0251e12077532a3a3c1e557a2b4f6f Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Mon, 18 Apr 2022 13:35:51 -0400 Subject: [PATCH 18/20] Make this test only use relevant types of chats --- tests/unit/OptionsListUtilsTest.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 9e73d97169cc..90658104c01e 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -678,8 +678,6 @@ describe('OptionsListUtils', () => { it('getSidebarOptions() with empty policyExpenseChats and defaultRooms', () => { const reportsWithEmptyChatRooms = { - ...REPORTS, - // This report is a policyExpenseChat without any messages in it (i.e. no lastMessageTimestamp) 10: { chatType: 'policyExpenseChat', @@ -755,10 +753,8 @@ describe('OptionsListUtils', () => { CONST.PRIORITY_MODE.DEFAULT, ); - // Then expect all of the reports to be shown except the unpinned reports that have no lastMessageTimestamp - // and are not policyExpenseChats or defaultRooms. The archived policyExpenseChats and defaultRooms should - // also not be included - expect(results.recentReports.length).toBe(_.size(reportsWithEmptyChatRooms) - 3); + // Then expect all of the reports to be shown except the archived policyExpenseChats and defaultRooms + expect(results.recentReports.length).toBe(_.size(reportsWithEmptyChatRooms) - 2); // Now we call getSidebarOptions() with no search value and GSD priority mode results = OptionsListUtils.getSidebarOptions( @@ -771,6 +767,6 @@ describe('OptionsListUtils', () => { // Then expect all of the reports to be shown except the unpinned reports that have no lastMessageTimestamp // and are not policyExpenseChats or defaultRooms. The archived policyExpenseChats and defaultRooms should // also not be included - expect(results.recentReports.length).toBe(_.size(reportsWithEmptyChatRooms) - 5); + expect(results.recentReports.length).toBe(0); }); }); From be38bd084fe9cd6e0052ef581d1a20302ab38c50 Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Mon, 18 Apr 2022 13:50:16 -0400 Subject: [PATCH 19/20] Add more details to tests --- tests/unit/OptionsListUtilsTest.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 90658104c01e..0bf51cd742c7 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -756,6 +756,12 @@ describe('OptionsListUtils', () => { // Then expect all of the reports to be shown except the archived policyExpenseChats and defaultRooms expect(results.recentReports.length).toBe(_.size(reportsWithEmptyChatRooms) - 2); + expect(results.recentReports[0].isPolicyExpenseChat).toBe(true); + expect(results.recentReports[0].text).toBe("Someone's workspace"); + + expect(results.recentReports[1].isChatRoom).toBe(true); + expect(results.recentReports[1].text).toBe('#admins'); + // Now we call getSidebarOptions() with no search value and GSD priority mode results = OptionsListUtils.getSidebarOptions( reportsWithEmptyChatRooms, @@ -764,9 +770,7 @@ describe('OptionsListUtils', () => { CONST.PRIORITY_MODE.GSD, ); - // Then expect all of the reports to be shown except the unpinned reports that have no lastMessageTimestamp - // and are not policyExpenseChats or defaultRooms. The archived policyExpenseChats and defaultRooms should - // also not be included + // None of the chats should be here since they've all been read expect(results.recentReports.length).toBe(0); }); }); From 156d7af1d03bf1097eba0da5b304ae379df9a20d Mon Sep 17 00:00:00 2001 From: Amal Nazeem Date: Mon, 18 Apr 2022 13:56:24 -0400 Subject: [PATCH 20/20] Fix comment typo --- tests/unit/OptionsListUtilsTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 0bf51cd742c7..3fb6441c6602 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -712,7 +712,7 @@ describe('OptionsListUtils', () => { statusNum: CONST.REPORT.STATUS.CLOSED, }, - // Note: This report is a defaultRoom without any messages in it (i.e. no lastMessageTimestamp) + // This report is a defaultRoom without any messages in it (i.e. no lastMessageTimestamp) 12: { chatType: 'policyAdmins', hasOutstandingIOU: false,