From 4c79b7ef31bcc74fcb02f85d8ac17eb36064d166 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Fri, 19 May 2023 17:55:55 -0300 Subject: [PATCH 01/29] Exclude empty chat reports from LNH --- src/libs/ReportUtils.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 6122701476f7..81c60962a615 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1941,6 +1941,11 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr return false; } + // Exclude empty chats + if (isChatReport() && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml)) { + return false; + } + return true; } From aa395b7aa3ea10395584c0a595eb0894ec65da6e Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Fri, 19 May 2023 17:59:12 -0300 Subject: [PATCH 02/29] Fix typo in isChatReport call --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 81c60962a615..ea77510a77c2 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1942,7 +1942,7 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr } // Exclude empty chats - if (isChatReport() && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml)) { + if (isChatReport(report) && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml)) { return false; } From 872a064fd4412871210047d71eb69fa8c2336f5f Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Tue, 30 May 2023 18:35:16 -0300 Subject: [PATCH 03/29] Add empty chat LNH test to SidebarFilterTest --- tests/unit/SidebarFilterTest.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unit/SidebarFilterTest.js b/tests/unit/SidebarFilterTest.js index 0c6bc75f5e68..33e1e8ab3c65 100644 --- a/tests/unit/SidebarFilterTest.js +++ b/tests/unit/SidebarFilterTest.js @@ -65,6 +65,30 @@ describe('Sidebar', () => { ); }); + it('excludes an empty chat report', () => { + LHNTestUtils.getDefaultRenderedSidebarLinks(); + + // Given a new report + const report = LHNTestUtils.getFakeReport(['emptychat+1@test.com', 'emptychat+2@test.com'], 0); + + return ( + waitForPromisesToResolve() + // When Onyx is updated to contain that report + .then(() => + Onyx.multiSet({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }), + ) + + // Then no reports are rendered in the LHN + .then(() => { + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); + expect(optionRows).toHaveLength(0); + }) + ); + }); + it('includes or excludes policy expense chats depending on the beta', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); From 9896a54aa0ce6f5a75749454e8e4bd819de45404 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Fri, 2 Jun 2023 15:51:39 -0300 Subject: [PATCH 04/29] Add excludeEmptyChats logic to shouldReportBeInOptionList --- src/libs/ReportUtils.js | 7 ++++--- src/libs/SidebarUtils.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 6ef9874fea8e..354de36f7625 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1806,9 +1806,10 @@ function canSeeDefaultRoom(report, policies, betas) { * @param {Object} iouReports * @param {String[]} betas * @param {Object} policies - * @returns {boolean} + * @param {Boolean} excludeEmptyChats + * @returns {Boolean} */ -function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, currentUserLogin, iouReports, betas, policies) { +function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, currentUserLogin, iouReports, betas, policies, excludeEmptyChats = false) { const isInDefaultMode = !isInGSDMode; // Exclude reports that have no data because there wouldn't be anything to show in the option item. @@ -1861,7 +1862,7 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr } // Exclude empty chats - if (isChatReport(report) && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml)) { + if (excludeEmptyChats && isChatReport(report) && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml)) { return false; } diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 87e8b97d0bd0..13d1fcc9d710 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -99,7 +99,7 @@ function getOrderedReportIDs(reportIDFromRoute) { const isInDefaultMode = !isInGSDMode; // Filter out all the reports that shouldn't be displayed - const reportsToDisplay = _.filter(allReports, (report) => ReportUtils.shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, currentUserLogin, allReports, betas, policies)); + const reportsToDisplay = _.filter(allReports, (report) => ReportUtils.shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, currentUserLogin, allReports, betas, policies, true)); if (_.isEmpty(reportsToDisplay)) { // Display Concierge chat report when there is no report to be displayed const conciergeChatReport = _.find(allReports, ReportUtils.isConciergeChatReport); From 8c4344fcf540b9474ab6389846fff7418cc713af Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Fri, 2 Jun 2023 15:54:15 -0300 Subject: [PATCH 05/29] Exclude threads, default rooms and policy rooms from empty chat logic in shouldReportBeInOptionList --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 354de36f7625..d6e92c4cab02 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1862,7 +1862,7 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr } // Exclude empty chats - if (excludeEmptyChats && isChatReport(report) && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml)) { + if (excludeEmptyChats && isChatReport(report) && !isChatRoom(report) && !isThread(report) && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml)) { return false; } From 13450093c8b79dca1fadcfc315e75d7a3b6f18ba Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Fri, 2 Jun 2023 16:23:04 -0300 Subject: [PATCH 06/29] Add another test to SidebarFilterTest for reports with drafts that should render in LNH --- tests/unit/SidebarFilterTest.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/unit/SidebarFilterTest.js b/tests/unit/SidebarFilterTest.js index 33e1e8ab3c65..8444683d6263 100644 --- a/tests/unit/SidebarFilterTest.js +++ b/tests/unit/SidebarFilterTest.js @@ -89,6 +89,33 @@ describe('Sidebar', () => { ); }); + it('includes an empty chat report if it has a draft', () => { + LHNTestUtils.getDefaultRenderedSidebarLinks(); + + // Given a new report + const report = { + ... LHNTestUtils.getFakeReport(['emptychat+1@test.com', 'emptychat+2@test.com'], 0), + hasDraft: true, + } + + return ( + waitForPromisesToResolve() + // When Onyx is updated to contain that report + .then(() => + Onyx.multiSet({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }), + ) + + // Then no reports are rendered in the LHN + .then(() => { + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); + expect(optionRows).toHaveLength(1); + }) + ); + }); + it('includes or excludes policy expense chats depending on the beta', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); From b20f5b9f6eaa22c7f136aa6b38087d27a57db1ce Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Fri, 2 Jun 2023 16:25:43 -0300 Subject: [PATCH 07/29] Fix policy expense beta test in SidebarFilterTest --- tests/unit/SidebarFilterTest.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/SidebarFilterTest.js b/tests/unit/SidebarFilterTest.js index 8444683d6263..2e9a817f0c00 100644 --- a/tests/unit/SidebarFilterTest.js +++ b/tests/unit/SidebarFilterTest.js @@ -6,6 +6,7 @@ import waitForPromisesToResolve from '../utils/waitForPromisesToResolve'; import CONST from '../../src/CONST'; import DateUtils from '../../src/libs/DateUtils'; import * as Localize from '../../src/libs/Localize'; +import * as Report from '../../src/libs/actions/Report'; // Be sure to include the mocked permissions library or else the beta tests won't work jest.mock('../../src/libs/Permissions'); @@ -137,6 +138,9 @@ describe('Sidebar', () => { }), ) + // When the report has at least one ADDCOMMENT action to show in the LNH + .then(() => Report.addComment(report.reportID, 'Hi, this is a comment')) + // Then no reports are rendered in the LHN .then(() => { const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); From a1d349d0a677b426d87638c61ed59552351d979c Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Mon, 5 Jun 2023 16:08:53 -0300 Subject: [PATCH 08/29] Linting --- src/libs/SidebarUtils.js | 4 +++- tests/unit/SidebarFilterTest.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index 13d1fcc9d710..bc384ac8347b 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -99,7 +99,9 @@ function getOrderedReportIDs(reportIDFromRoute) { const isInDefaultMode = !isInGSDMode; // Filter out all the reports that shouldn't be displayed - const reportsToDisplay = _.filter(allReports, (report) => ReportUtils.shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, currentUserLogin, allReports, betas, policies, true)); + const reportsToDisplay = _.filter(allReports, (report) => + ReportUtils.shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, currentUserLogin, allReports, betas, policies, true), + ); if (_.isEmpty(reportsToDisplay)) { // Display Concierge chat report when there is no report to be displayed const conciergeChatReport = _.find(allReports, ReportUtils.isConciergeChatReport); diff --git a/tests/unit/SidebarFilterTest.js b/tests/unit/SidebarFilterTest.js index 2e9a817f0c00..e6d46f14bc25 100644 --- a/tests/unit/SidebarFilterTest.js +++ b/tests/unit/SidebarFilterTest.js @@ -95,9 +95,9 @@ describe('Sidebar', () => { // Given a new report const report = { - ... LHNTestUtils.getFakeReport(['emptychat+1@test.com', 'emptychat+2@test.com'], 0), + ...LHNTestUtils.getFakeReport(['emptychat+1@test.com', 'emptychat+2@test.com'], 0), hasDraft: true, - } + }; return ( waitForPromisesToResolve() From 9e7e220919b7f9aa12b243422e9f0855286cd5d3 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Mon, 5 Jun 2023 16:34:22 -0300 Subject: [PATCH 09/29] Fix empty chat with draft LNH test --- tests/unit/SidebarFilterTest.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unit/SidebarFilterTest.js b/tests/unit/SidebarFilterTest.js index e6d46f14bc25..5ffe1ec2538c 100644 --- a/tests/unit/SidebarFilterTest.js +++ b/tests/unit/SidebarFilterTest.js @@ -105,6 +105,7 @@ describe('Sidebar', () => { .then(() => Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + [ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails, }), ) @@ -117,7 +118,7 @@ describe('Sidebar', () => { ); }); - it('includes or excludes policy expense chats depending on the beta', () => { + it('includes or excludes policy expensechats depending on the beta', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); // Given a policy expense report @@ -138,7 +139,7 @@ describe('Sidebar', () => { }), ) - // When the report has at least one ADDCOMMENT action to show in the LNH + // When the report has at least one ADDCOMMENT action to be rendered in the LNH .then(() => Report.addComment(report.reportID, 'Hi, this is a comment')) // Then no reports are rendered in the LHN From 3ba65beba4ad1f313c9022325077879bc10f2be8 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Mon, 5 Jun 2023 16:57:46 -0300 Subject: [PATCH 10/29] Add lastMessageText to SideBarOrderTest reports so they show in LNH --- tests/unit/SidebarOrderTest.js | 54 ++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/tests/unit/SidebarOrderTest.js b/tests/unit/SidebarOrderTest.js index 2f929cb4e1a6..b6fdb7e1f9ce 100644 --- a/tests/unit/SidebarOrderTest.js +++ b/tests/unit/SidebarOrderTest.js @@ -102,12 +102,15 @@ describe('Sidebar', () => { // Given three unread reports in the recently updated order of 3, 2, 1 const report1 = { ...LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com'], 3), + lastMessageHtml: 'unread message from report 1', }; const report2 = { ...LHNTestUtils.getFakeReport(['email3@test.com', 'email4@test.com'], 2), + lastMessageHtml: 'unread message from report 2', }; const report3 = { ...LHNTestUtils.getFakeReport(['email5@test.com', 'email6@test.com'], 1), + lastMessageHtml: 'unread message from report 3', }; return ( @@ -141,10 +144,17 @@ describe('Sidebar', () => { // And the currently viewed report is the first report const report1 = { ...LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com'], 3), + lastMessageHtml: 'unread message from report 1', hasDraft: true, }; - const report2 = LHNTestUtils.getFakeReport(['email3@test.com', 'email4@test.com'], 2); - const report3 = LHNTestUtils.getFakeReport(['email5@test.com', 'email6@test.com'], 1); + const report2 = { + ...LHNTestUtils.getFakeReport(['email3@test.com', 'email4@test.com'], 2), + lastMessageHtml: 'unread message from report 2', + }; + const report3 = { + ...LHNTestUtils.getFakeReport(['email5@test.com', 'email6@test.com'], 1), + lastMessageHtml: 'unread message from report 3', + }; const reportIDFromRoute = report1.reportID; LHNTestUtils.getDefaultRenderedSidebarLinks(reportIDFromRoute); return ( @@ -180,9 +190,18 @@ describe('Sidebar', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); // Given three reports in the recently updated order of 3, 2, 1 - const report1 = LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com'], 3); - const report2 = LHNTestUtils.getFakeReport(['email3@test.com', 'email4@test.com'], 2); - const report3 = LHNTestUtils.getFakeReport(['email5@test.com', 'email6@test.com'], 1); + const report1 = { + ...LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com'], 3), + lastMessageHtml: 'unread message from report 1', + }; + const report2 = { + ...LHNTestUtils.getFakeReport(['email3@test.com', 'email4@test.com'], 2), + lastMessageHtml: 'unread message from report 2', + }; + const report3 = { + ...LHNTestUtils.getFakeReport(['email5@test.com', 'email6@test.com'], 1), + lastMessageHtml: 'unread message from report 3', + }; return ( waitForPromisesToResolve() @@ -221,12 +240,19 @@ describe('Sidebar', () => { // Given three reports in the recently updated order of 3, 2, 1 // And the second report has a draft // And the currently viewed report is the second report - const report1 = LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com'], 3); + const report1 = { + ...LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com'], 3), + lastMessageHtml: 'unread message from report 1', + }; const report2 = { ...LHNTestUtils.getFakeReport(['email3@test.com', 'email4@test.com'], 2), + lastMessageHtml: 'unread message from report 2', hasDraft: true, }; - const report3 = LHNTestUtils.getFakeReport(['email5@test.com', 'email6@test.com'], 1); + const report3 = { + ...LHNTestUtils.getFakeReport(['email5@test.com', 'email6@test.com'], 1), + lastMessageHtml: 'unread message from report 3', + }; const reportIDFromRoute = report2.reportID; LHNTestUtils.getDefaultRenderedSidebarLinks(reportIDFromRoute); @@ -525,12 +551,19 @@ describe('Sidebar', () => { // Given three reports, with the first report being archived const report1 = { ...LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com']), + lastMessageHtml: 'message from report 1', chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS.CLOSED, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, }; - const report2 = LHNTestUtils.getFakeReport(['email3@test.com', 'email4@test.com']); - const report3 = LHNTestUtils.getFakeReport(['email5@test.com', 'email6@test.com']); + const report2 = { + ...LHNTestUtils.getFakeReport(['email3@test.com', 'email4@test.com']), + lastMessageHtml: 'message from report 2', + }; + const report3 = { + ...LHNTestUtils.getFakeReport(['email5@test.com', 'email6@test.com']), + lastMessageHtml: 'message from report 3', + }; // Given the user is in all betas const betas = [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS, CONST.BETAS.POLICY_EXPENSE_CHAT]; @@ -747,14 +780,17 @@ describe('Sidebar', () => { const lastVisibleActionCreated = DateUtils.getDBTime(); const report1 = { ...LHNTestUtils.getFakeReport(['email1@test.com', 'email2@test.com']), + lastMessageHtml: 'message from report 1', lastVisibleActionCreated, }; const report2 = { ...LHNTestUtils.getFakeReport(['email3@test.com', 'email4@test.com']), + lastMessageHtml: 'message from report 2', lastVisibleActionCreated, }; const report3 = { ...LHNTestUtils.getFakeReport(['email5@test.com', 'email6@test.com']), + lastMessageHtml: 'message from report 3', lastVisibleActionCreated, }; From a7777edc5ec490dc09a70225f3e715f6590415bf Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Mon, 5 Jun 2023 16:58:26 -0300 Subject: [PATCH 11/29] Change LNH empty chat check order --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 5778882e062f..f2b0edebdb07 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1859,7 +1859,7 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr } // Exclude empty chats - if (excludeEmptyChats && isChatReport(report) && !isChatRoom(report) && !isThread(report) && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml)) { + if (excludeEmptyChats && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml) && isChatReport(report) && !isChatRoom(report) && !isThread(report)) { return false; } From 45c7b60b0f2259d57def15fdfdbcf2e82760c9e1 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Mon, 5 Jun 2023 20:26:17 -0300 Subject: [PATCH 12/29] Do not include groups in logic that excludes empty chats from LNH --- src/libs/ReportUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index f2b0edebdb07..c847d654466f 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1858,8 +1858,8 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr return false; } - // Exclude empty chats - if (excludeEmptyChats && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml) && isChatReport(report) && !isChatRoom(report) && !isThread(report)) { + // Exclude empty chats between two users + if (excludeEmptyChats && report.participants.length < 3 && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml) && isChatReport(report) && !isChatRoom(report) && !isThread(report)) { return false; } From 1af5873311a611c234891d3ee35f40af6b3c4657 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Mon, 5 Jun 2023 20:43:46 -0300 Subject: [PATCH 13/29] Fix group chat check for excluding empty chats from newDot --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index c847d654466f..da0f1a3e8616 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1859,7 +1859,7 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr } // Exclude empty chats between two users - if (excludeEmptyChats && report.participants.length < 3 && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml) && isChatReport(report) && !isChatRoom(report) && !isThread(report)) { + if (excludeEmptyChats && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml) && !_.isEmpty(report.participants) && report.participants.length < 3 && isChatReport(report) && !isChatRoom(report) && !isThread(report)) { return false; } From 74b557a0094663191113010213e0c81929f6a5cf Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Mon, 5 Jun 2023 20:44:09 -0300 Subject: [PATCH 14/29] Lint ReportUtils --- src/libs/ReportUtils.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index da0f1a3e8616..9e4f4435563a 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1859,7 +1859,16 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr } // Exclude empty chats between two users - if (excludeEmptyChats && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml) && !_.isEmpty(report.participants) && report.participants.length < 3 && isChatReport(report) && !isChatRoom(report) && !isThread(report)) { + if ( + excludeEmptyChats && + _.isEmpty(report.lastMessageText) && + _.isEmpty(report.lastMessageHtml) && + !_.isEmpty(report.participants) && + report.participants.length < 3 && + isChatReport(report) && + !isChatRoom(report) && + !isThread(report) + ) { return false; } From 70c93d3895bde686a1d24c292ef1286c75f3f092 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Mon, 5 Jun 2023 21:02:15 -0300 Subject: [PATCH 15/29] Exclude empty group chats from the LNH --- src/libs/ReportUtils.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d20b4f0a45e4..3327b7674b16 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1873,8 +1873,6 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr excludeEmptyChats && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml) && - !_.isEmpty(report.participants) && - report.participants.length < 3 && isChatReport(report) && !isChatRoom(report) && !isThread(report) From d529c54f1c644c0baa520b38c57eb8fc75df1e94 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Tue, 13 Jun 2023 19:22:42 -0300 Subject: [PATCH 16/29] Lint ReportUtils --- src/libs/ReportUtils.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 47ab70970184..f8ac1688f8d8 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1883,14 +1883,7 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr } // Exclude empty chats between two users - if ( - excludeEmptyChats && - _.isEmpty(report.lastMessageText) && - _.isEmpty(report.lastMessageHtml) && - isChatReport(report) && - !isChatRoom(report) && - !isThread(report) - ) { + if (excludeEmptyChats && _.isEmpty(report.lastMessageText) && _.isEmpty(report.lastMessageHtml) && isChatReport(report) && !isChatRoom(report) && !isThread(report)) { return false; } From 066dcebdd737cb86b667e2268e5b0db442a4d00f Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Thu, 29 Jun 2023 16:12:22 -0300 Subject: [PATCH 17/29] Fixing tests by using lastMessageText instead of lastMessageHtml --- src/libs/ReportUtils.js | 2 +- tests/unit/SidebarOrderTest.js | 36 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d6caaed0ffae..48b4102a3a1e 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1995,7 +1995,7 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep return false; } - // Hide chats between two users that haven't been commented on + // Hide chats between two users that haven't been commented on from the LNH if (excludeEmptyChats && _.isEmpty(report.lastMessageText) && isChatReport(report) && !isChatRoom(report)) { return false; } diff --git a/tests/unit/SidebarOrderTest.js b/tests/unit/SidebarOrderTest.js index 80b1a419c923..312f7558a448 100644 --- a/tests/unit/SidebarOrderTest.js +++ b/tests/unit/SidebarOrderTest.js @@ -102,15 +102,15 @@ describe('Sidebar', () => { // Given three unread reports in the recently updated order of 3, 2, 1 const report1 = { ...LHNTestUtils.getFakeReport([1, 2], 3), - lastMessageHtml: 'unread message from report 1', + lastMessageText: 'unread message from report 1', }; const report2 = { ...LHNTestUtils.getFakeReport([3, 4], 2), - lastMessageHtml: 'unread message from report 2', + lastMessageText: 'unread message from report 2', }; const report3 = { ...LHNTestUtils.getFakeReport([5, 6], 1), - lastMessageHtml: 'unread message from report 3', + lastMessageText: 'unread message from report 3', }; return ( @@ -144,16 +144,16 @@ describe('Sidebar', () => { // And the currently viewed report is the first report const report1 = { ...LHNTestUtils.getFakeReport([1, 2], 3), - lastMessageHtml: 'unread message from report 1', + lastMessageText: 'unread message from report 1', hasDraft: true, }; const report2 = { ...LHNTestUtils.getFakeReport([3, 4], 2), - lastMessageHtml: 'unread message from report 2', + lastMessageText: 'unread message from report 2', }; const report3 = { ...LHNTestUtils.getFakeReport([5, 6], 1), - lastMessageHtml: 'unread message from report 3', + lastMessageText: 'unread message from report 3', }; const currentReportId = report1.reportID; LHNTestUtils.getDefaultRenderedSidebarLinks(currentReportId); @@ -193,15 +193,15 @@ describe('Sidebar', () => { // Given three reports in the recently updated order of 3, 2, 1 const report1 = { ...LHNTestUtils.getFakeReport([1, 2], 3), - lastMessageHtml: 'unread message from report 1', + lastMessageText: 'unread message from report 1', }; const report2 = { ...LHNTestUtils.getFakeReport([3, 4], 2), - lastMessageHtml: 'unread message from report 2', + lastMessageText: 'unread message from report 2', }; const report3 = { ...LHNTestUtils.getFakeReport([5, 6], 1), - lastMessageHtml: 'unread message from report 3', + lastMessageText: 'unread message from report 3', }; return ( @@ -243,16 +243,16 @@ describe('Sidebar', () => { // And the currently viewed report is the second report const report1 = { ...LHNTestUtils.getFakeReport([1, 2], 3), - lastMessageHtml: 'unread message from report 1' + lastMessageText: 'unread message from report 1' }; const report2 = { ...LHNTestUtils.getFakeReport([3, 4], 2), - lastMessageHtml: 'unread message from report 2', + lastMessageText: 'unread message from report 2', hasDraft: true, }; const report3 = { ...LHNTestUtils.getFakeReport([5, 6], 1), - lastMessageHtml: 'unread message from report 3', + lastMessageText: 'unread message from report 3', }; const currentReportId = report2.reportID; LHNTestUtils.getDefaultRenderedSidebarLinks(currentReportId); @@ -552,18 +552,18 @@ describe('Sidebar', () => { // Given three reports, with the first report being archived const report1 = { ...LHNTestUtils.getFakeReport([1, 2]), - lastMessageHtml: 'message from report 1', + lastMessageText: 'message from report 1', chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS.CLOSED, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, }; const report2 = { ...LHNTestUtils.getFakeReport([3, 4]), - lastMessageHtml: 'message from report 2' + lastMessageText: 'message from report 2' }; const report3 = { ...LHNTestUtils.getFakeReport([5, 6]), - lastMessageHtml: 'message from report 3' + lastMessageText: 'message from report 3' }; // Given the user is in all betas @@ -781,17 +781,17 @@ describe('Sidebar', () => { const lastVisibleActionCreated = DateUtils.getDBTime(); const report1 = { ...LHNTestUtils.getFakeReport([1, 2]), - lastMessageHtml: 'message from report 1', + lastMessageText: 'message from report 1', lastVisibleActionCreated, }; const report2 = { ...LHNTestUtils.getFakeReport([3, 4]), - lastMessageHtml: 'message from report 2', + lastMessageText: 'message from report 2', lastVisibleActionCreated, }; const report3 = { ...LHNTestUtils.getFakeReport([5, 6]), - lastMessageHtml: 'message from report 3', + lastMessageText: 'message from report 3', lastVisibleActionCreated, }; From 6161296b66b83ed2efab4fbef1325676eaf91a62 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Thu, 29 Jun 2023 16:38:38 -0300 Subject: [PATCH 18/29] Fix new sidebarFilterTest tests --- tests/unit/SidebarFilterTest.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/unit/SidebarFilterTest.js b/tests/unit/SidebarFilterTest.js index 19f2b2a2ff9f..d5c5e142dc1c 100644 --- a/tests/unit/SidebarFilterTest.js +++ b/tests/unit/SidebarFilterTest.js @@ -83,9 +83,9 @@ describe('Sidebar', () => { // Then no reports are rendered in the LHN .then(() => { - const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); - const optionRows = screen.queryAllByAccessibilityHint(hintText); - expect(optionRows).toHaveLength(0); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); + expect(displayNames).toHaveLength(0); }) ); }); @@ -94,8 +94,8 @@ describe('Sidebar', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); // Given a new report - const report = { - ...LHNTestUtils.getFakeReport(['emptychat+1@test.com', 'emptychat+2@test.com'], 0), + const report = { + ...LHNTestUtils.getFakeReport([1, 2], 0), hasDraft: true, }; @@ -105,15 +105,15 @@ describe('Sidebar', () => { .then(() => Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, - [ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails, + [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, }), ) // Then no reports are rendered in the LHN .then(() => { - const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); - const optionRows = screen.queryAllByAccessibilityHint(hintText); - expect(optionRows).toHaveLength(1); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); + expect(displayNames).toHaveLength(1); }) ); }); From 1e93d7b5196aab43da0752cdc52ce6812b39a3b0 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Thu, 29 Jun 2023 17:00:13 -0300 Subject: [PATCH 19/29] Lint tests --- tests/unit/SidebarFilterTest.js | 2 +- tests/unit/SidebarOrderTest.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/SidebarFilterTest.js b/tests/unit/SidebarFilterTest.js index d5c5e142dc1c..20acba5777ea 100644 --- a/tests/unit/SidebarFilterTest.js +++ b/tests/unit/SidebarFilterTest.js @@ -94,7 +94,7 @@ describe('Sidebar', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); // Given a new report - const report = { + const report = { ...LHNTestUtils.getFakeReport([1, 2], 0), hasDraft: true, }; diff --git a/tests/unit/SidebarOrderTest.js b/tests/unit/SidebarOrderTest.js index 312f7558a448..1ba5a7e9a374 100644 --- a/tests/unit/SidebarOrderTest.js +++ b/tests/unit/SidebarOrderTest.js @@ -243,7 +243,7 @@ describe('Sidebar', () => { // And the currently viewed report is the second report const report1 = { ...LHNTestUtils.getFakeReport([1, 2], 3), - lastMessageText: 'unread message from report 1' + lastMessageText: 'unread message from report 1', }; const report2 = { ...LHNTestUtils.getFakeReport([3, 4], 2), @@ -559,11 +559,11 @@ describe('Sidebar', () => { }; const report2 = { ...LHNTestUtils.getFakeReport([3, 4]), - lastMessageText: 'message from report 2' + lastMessageText: 'message from report 2', }; const report3 = { ...LHNTestUtils.getFakeReport([5, 6]), - lastMessageText: 'message from report 3' + lastMessageText: 'message from report 3', }; // Given the user is in all betas From 8576cd0e5d51e46e689ee82c843e41f27e8f923a Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Thu, 6 Jul 2023 18:21:15 -0300 Subject: [PATCH 20/29] Replace getChatByParticipantsByLoginList call with getChatByParticipants in navigateToAndOpenReport --- src/libs/actions/Report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index e7e1a82100aa..289b5c8262cc 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -494,7 +494,7 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p function navigateToAndOpenReport(userLogins) { let newChat = {}; const formattedUserLogins = _.map(userLogins, (login) => OptionsListUtils.addSMSDomainIfPhoneNumber(login).toLowerCase()); - const chat = ReportUtils.getChatByParticipantsByLoginList(formattedUserLogins); + const chat = ReportUtils.getChatByParticipants(formattedUserLogins); if (!chat) { const participantAccountIDs = PersonalDetailsUtils.getAccountIDsByLogins(userLogins); newChat = ReportUtils.buildOptimisticChatReport(participantAccountIDs); From c26cfdc41928e6587723cf5f8dcb28b2cf3f7867 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Thu, 6 Jul 2023 18:37:14 -0300 Subject: [PATCH 21/29] Undo previous change in navigateToAndOpenReport and call navigateToAndOpenReportWithAccountIDs instead --- src/libs/actions/Report.js | 2 +- src/pages/NewChatPage.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 289b5c8262cc..e7e1a82100aa 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -494,7 +494,7 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p function navigateToAndOpenReport(userLogins) { let newChat = {}; const formattedUserLogins = _.map(userLogins, (login) => OptionsListUtils.addSMSDomainIfPhoneNumber(login).toLowerCase()); - const chat = ReportUtils.getChatByParticipants(formattedUserLogins); + const chat = ReportUtils.getChatByParticipantsByLoginList(formattedUserLogins); if (!chat) { const participantAccountIDs = PersonalDetailsUtils.getAccountIDsByLogins(userLogins); newChat = ReportUtils.buildOptimisticChatReport(participantAccountIDs); diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index 8927088c3f67..1c1fa95447ec 100755 --- a/src/pages/NewChatPage.js +++ b/src/pages/NewChatPage.js @@ -145,7 +145,11 @@ function NewChatPage(props) { * @param {Object} option */ function createChat(option) { - Report.navigateToAndOpenReport([option.login]); + if (option.accountID) { + Report.navigateToAndOpenReportWithAccountIDs([option.accountID]); + } else { + Report.navigateToAndOpenReport([option.login]); + } } /** From 91135bf5baa71490a11e34d6df005cdd740d0ded Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Mon, 7 Aug 2023 19:34:54 -0300 Subject: [PATCH 22/29] Reintroduce excludeEmptyChats logic --- src/libs/ReportUtils.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 9bd5856f1cd5..f34005726381 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2332,8 +2332,8 @@ function canAccessReport(report, policies, betas, allReportActions) { * @param {Object} iouReports * @param {String[]} betas * @param {Object} policies - * @param {Boolean} excludeEmptyChats * @param {Object} allReportActions + * @param {Boolean} excludeEmptyChats * @returns {boolean} */ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouReports, betas, policies, allReportActions, excludeEmptyChats = false) { @@ -2397,6 +2397,16 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep return false; } + // Hide thread reports that haven't been commented on + if (isThread(report) && _.isEmpty(report.lastMessageText)) { + return false; + } + + // Hide chats between two users that haven't been commented on from the LNH + if (excludeEmptyChats && _.isEmpty(report.lastMessageText) && isChatReport(report) && !isChatRoom(report)) { + return false; + } + return true; } From f05a02a71c3edec90a007e2061200820a328d2a9 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Tue, 8 Aug 2023 15:53:24 -0300 Subject: [PATCH 23/29] Reintroduce navigateToAndOpenReport login navigation --- src/pages/NewChatPage.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index 025ac4da9e92..94f84aae6943 100755 --- a/src/pages/NewChatPage.js +++ b/src/pages/NewChatPage.js @@ -146,11 +146,7 @@ function NewChatPage(props) { * @param {Object} option */ function createChat(option) { - if (option.accountID) { - Report.navigateToAndOpenReportWithAccountIDs([option.accountID]); - } else { - Report.navigateToAndOpenReport([option.login]); - } + Report.navigateToAndOpenReport([option.login]); } /** From 9c4558011415f7df9dd6a2ed300ba7067d715375 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Tue, 8 Aug 2023 16:13:34 -0300 Subject: [PATCH 24/29] Use getLastVisibleMessage to check for empty chats in shouldReportBeInOptionList --- src/libs/ReportUtils.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 0efa8cd0f5d1..5e00c352e7e1 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2399,14 +2399,16 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep return false; } - // Hide thread reports that haven't been commented on - if (isThread(report) && _.isEmpty(report.lastMessageText)) { - return false; - } - - // Hide chats between two users that haven't been commented on from the LNH - if (excludeEmptyChats && _.isEmpty(report.lastMessageText) && isChatReport(report) && !isChatRoom(report)) { - return false; + const isEmptyChat = !ReportActionsUtils.getLastVisibleMessage(report).lastMessageText; + if (excludeEmptyChats && isEmptyChat) { + // Hide thread reports that haven't been commented on + if(isThread(report)) { + return false; + } + // Hide chats between two users that haven't been commented on from the LNH + if (isChatReport(report) && !isChatRoom(report)) { + return false; + } } return true; From aa01affcb063dca969b655a7602d4356ec4ae6ac Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Tue, 8 Aug 2023 16:15:36 -0300 Subject: [PATCH 25/29] Reuse isEmptyChat for empty chat threads check in shouldReportBeInOptionList --- src/libs/ReportUtils.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 5e00c352e7e1..7b9405de37ce 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2368,8 +2368,10 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep return true; } + const isEmptyChat = !ReportActionsUtils.getLastVisibleMessage(report).lastMessageText; + // Hide only chat threads that haven't been commented on (other threads are actionable) - if (isChatThread(report) && !report.lastMessageText) { + if (isChatThread(report) && isEmptyChat) { return false; } @@ -2399,7 +2401,6 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep return false; } - const isEmptyChat = !ReportActionsUtils.getLastVisibleMessage(report).lastMessageText; if (excludeEmptyChats && isEmptyChat) { // Hide thread reports that haven't been commented on if(isThread(report)) { From d9d1a7ee20410becbc42741512ecd385d25f6dd8 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Tue, 8 Aug 2023 17:17:36 -0300 Subject: [PATCH 26/29] Fix typo and lint --- src/libs/ReportUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 7b9405de37ce..cdc6f94402bd 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2368,7 +2368,7 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep return true; } - const isEmptyChat = !ReportActionsUtils.getLastVisibleMessage(report).lastMessageText; + const isEmptyChat = !ReportActionsUtils.getLastVisibleMessage(report.reportID).lastMessageText; // Hide only chat threads that haven't been commented on (other threads are actionable) if (isChatThread(report) && isEmptyChat) { @@ -2403,7 +2403,7 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep if (excludeEmptyChats && isEmptyChat) { // Hide thread reports that haven't been commented on - if(isThread(report)) { + if (isThread(report)) { return false; } // Hide chats between two users that haven't been commented on from the LNH From b90eb0779ca629965fefbeb61154a8c3bc28b3c7 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Tue, 8 Aug 2023 18:04:37 -0300 Subject: [PATCH 27/29] Remove duplicated and faulty logic that hides empty threads --- src/libs/ReportUtils.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index cdc6f94402bd..59d1eaf81cea 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2401,15 +2401,9 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep return false; } - if (excludeEmptyChats && isEmptyChat) { - // Hide thread reports that haven't been commented on - if (isThread(report)) { - return false; - } - // Hide chats between two users that haven't been commented on from the LNH - if (isChatReport(report) && !isChatRoom(report)) { - return false; - } + // Hide chats between two users that haven't been commented on from the LNH + if (excludeEmptyChats && isEmptyChat && isChatReport(report) && !isChatRoom(report)) { + return false; } return true; From 32e84eceb944f7fe24ec318d521d7644af575ec4 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Wed, 9 Aug 2023 14:51:12 -0300 Subject: [PATCH 28/29] Fix SidebarOrderTest tests --- tests/unit/SidebarOrderTest.js | 100 +++++++++++++++------------------ 1 file changed, 46 insertions(+), 54 deletions(-) diff --git a/tests/unit/SidebarOrderTest.js b/tests/unit/SidebarOrderTest.js index 9229adfa7034..85e465809f98 100644 --- a/tests/unit/SidebarOrderTest.js +++ b/tests/unit/SidebarOrderTest.js @@ -7,6 +7,7 @@ import * as LHNTestUtils from '../utils/LHNTestUtils'; import CONST from '../../src/CONST'; import DateUtils from '../../src/libs/DateUtils'; import * as Localize from '../../src/libs/Localize'; +import * as Report from '../../src/libs/actions/Report'; // Be sure to include the mocked Permissions and Expensicons libraries or else the beta tests won't work jest.mock('../../src/libs/Permissions'); @@ -106,18 +107,14 @@ describe('Sidebar', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); // Given three unread reports in the recently updated order of 3, 2, 1 - const report1 = { - ...LHNTestUtils.getFakeReport([1, 2], 3), - lastMessageText: 'unread message from report 1', - }; - const report2 = { - ...LHNTestUtils.getFakeReport([3, 4], 2), - lastMessageText: 'unread message from report 2', - }; - const report3 = { - ...LHNTestUtils.getFakeReport([5, 6], 1), - lastMessageText: 'unread message from report 3', - }; + const report1 = LHNTestUtils.getFakeReport([1, 2], 3); + const report2 = LHNTestUtils.getFakeReport([3, 4], 2); + const report3 = LHNTestUtils.getFakeReport([5, 6], 1); + + // Each report has at least one ADDCOMMENT action so should be rendered in the LNH + Report.addComment(report1.reportID, 'Hi, this is a comment'); + Report.addComment(report2.reportID, 'Hi, this is a comment'); + Report.addComment(report3.reportID, 'Hi, this is a comment'); return ( waitForPromisesToResolve() @@ -136,6 +133,7 @@ describe('Sidebar', () => { .then(() => { const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); const displayNames = screen.queryAllByLabelText(hintText); + expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Three, Four'); @@ -150,17 +148,16 @@ describe('Sidebar', () => { // And the currently viewed report is the first report const report1 = { ...LHNTestUtils.getFakeReport([1, 2], 3), - lastMessageText: 'unread message from report 1', hasDraft: true, }; - const report2 = { - ...LHNTestUtils.getFakeReport([3, 4], 2), - lastMessageText: 'unread message from report 2', - }; - const report3 = { - ...LHNTestUtils.getFakeReport([5, 6], 1), - lastMessageText: 'unread message from report 3', - }; + const report2 = LHNTestUtils.getFakeReport([3, 4], 2); + const report3 = LHNTestUtils.getFakeReport([5, 6], 1); + + // Each report has at least one ADDCOMMENT action so should be rendered in the LNH + Report.addComment(report1.reportID, 'Hi, this is a comment'); + Report.addComment(report2.reportID, 'Hi, this is a comment'); + Report.addComment(report3.reportID, 'Hi, this is a comment'); + const currentReportId = report1.reportID; LHNTestUtils.getDefaultRenderedSidebarLinks(currentReportId); @@ -197,18 +194,14 @@ describe('Sidebar', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); // Given three reports in the recently updated order of 3, 2, 1 - const report1 = { - ...LHNTestUtils.getFakeReport([1, 2], 3), - lastMessageText: 'unread message from report 1', - }; - const report2 = { - ...LHNTestUtils.getFakeReport([3, 4], 2), - lastMessageText: 'unread message from report 2', - }; - const report3 = { - ...LHNTestUtils.getFakeReport([5, 6], 1), - lastMessageText: 'unread message from report 3', - }; + const report1 = LHNTestUtils.getFakeReport([1, 2], 3); + const report2 = LHNTestUtils.getFakeReport([3, 4], 2); + const report3 = LHNTestUtils.getFakeReport([5, 6], 1); + + // Each report has at least one ADDCOMMENT action so should be rendered in the LNH + Report.addComment(report1.reportID, 'Hi, this is a comment'); + Report.addComment(report2.reportID, 'Hi, this is a comment'); + Report.addComment(report3.reportID, 'Hi, this is a comment'); return ( waitForPromisesToResolve() @@ -247,19 +240,18 @@ describe('Sidebar', () => { // Given three reports in the recently updated order of 3, 2, 1 // And the second report has a draft // And the currently viewed report is the second report - const report1 = { - ...LHNTestUtils.getFakeReport([1, 2], 3), - lastMessageText: 'unread message from report 1', - }; + const report1 = LHNTestUtils.getFakeReport([1, 2], 3); const report2 = { ...LHNTestUtils.getFakeReport([3, 4], 2), - lastMessageText: 'unread message from report 2', hasDraft: true, }; - const report3 = { - ...LHNTestUtils.getFakeReport([5, 6], 1), - lastMessageText: 'unread message from report 3', - }; + const report3 = LHNTestUtils.getFakeReport([5, 6], 1); + + // Each report has at least one ADDCOMMENT action so should be rendered in the LNH + Report.addComment(report1.reportID, 'Hi, this is a comment'); + Report.addComment(report2.reportID, 'Hi, this is a comment'); + Report.addComment(report3.reportID, 'Hi, this is a comment'); + const currentReportId = report2.reportID; LHNTestUtils.getDefaultRenderedSidebarLinks(currentReportId); @@ -558,19 +550,17 @@ describe('Sidebar', () => { // Given three reports, with the first report being archived const report1 = { ...LHNTestUtils.getFakeReport([1, 2]), - lastMessageText: 'message from report 1', chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, statusNum: CONST.REPORT.STATUS.CLOSED, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, }; - const report2 = { - ...LHNTestUtils.getFakeReport([3, 4]), - lastMessageText: 'message from report 2', - }; - const report3 = { - ...LHNTestUtils.getFakeReport([5, 6]), - lastMessageText: 'message from report 3', - }; + const report2 = LHNTestUtils.getFakeReport([3, 4]); + const report3 = LHNTestUtils.getFakeReport([5, 6]); + + // Each report has at least one ADDCOMMENT action so should be rendered in the LNH + Report.addComment(report1.reportID, 'Hi, this is a comment'); + Report.addComment(report2.reportID, 'Hi, this is a comment'); + Report.addComment(report3.reportID, 'Hi, this is a comment'); // Given the user is in all betas const betas = [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS, CONST.BETAS.POLICY_EXPENSE_CHAT]; @@ -787,20 +777,22 @@ describe('Sidebar', () => { const lastVisibleActionCreated = DateUtils.getDBTime(); const report1 = { ...LHNTestUtils.getFakeReport([1, 2]), - lastMessageText: 'message from report 1', lastVisibleActionCreated, }; const report2 = { ...LHNTestUtils.getFakeReport([3, 4]), - lastMessageText: 'message from report 2', lastVisibleActionCreated, }; const report3 = { ...LHNTestUtils.getFakeReport([5, 6]), - lastMessageText: 'message from report 3', lastVisibleActionCreated, }; + // Each report has at least one ADDCOMMENT action so should be rendered in the LNH + Report.addComment(report1.reportID, 'Hi, this is a comment'); + Report.addComment(report2.reportID, 'Hi, this is a comment'); + Report.addComment(report3.reportID, 'Hi, this is a comment'); + LHNTestUtils.getDefaultRenderedSidebarLinks('0'); return ( waitForPromisesToResolve() From 382691b6987bb905855918eb94a8095f6a9512e6 Mon Sep 17 00:00:00 2001 From: Paulo Vale Date: Wed, 9 Aug 2023 15:15:59 -0300 Subject: [PATCH 29/29] Keep empty policy expense chats in LNH --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 8aebe7257b05..d4ad1be7d5b2 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2408,7 +2408,7 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep } // Hide chats between two users that haven't been commented on from the LNH - if (excludeEmptyChats && isEmptyChat && isChatReport(report) && !isChatRoom(report)) { + if (excludeEmptyChats && isEmptyChat && isChatReport(report) && !isChatRoom(report) && !isPolicyExpenseChat(report)) { return false; }