From 219090eb39a9bbb157ffa21cf5e304a4e8e85c96 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 13:54:39 +0700 Subject: [PATCH 01/27] add shouldReportBeInOptionList test --- tests/unit/ReportUtilsTest.ts | 166 +++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index dc752ae73b1c..7ee447ec088d 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -4,9 +4,10 @@ import type {OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import DateUtils from '@libs/DateUtils'; import * as ReportUtils from '@libs/ReportUtils'; +import * as TransactionUtils from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx'; +import type {Beta, PersonalDetailsList, Policy, Report, ReportAction} from '@src/types/onyx'; import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; import * as NumberUtils from '../../src/libs/NumberUtils'; import * as LHNTestUtils from '../utils/LHNTestUtils'; @@ -1179,5 +1180,168 @@ describe('ReportUtils', () => { expect(ReportUtils.getGroupChatName(undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); }); + + describe('shouldReportBeInOptionList tests', () => { + afterEach(() => Onyx.clear()); + + it('should return false when the report is marked as hidden', () => { + const report: Report = { + ...LHNTestUtils.getFakeReport(), + participants: { + '1': { + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + }, + }, + }; + const currentReportId = ''; + const isInFocusMode = true; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + expect( + ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies: {}, doesReportHaveViolations: false, excludeEmptyChats: false}), + ).toBeFalsy(); + }); + + it('should return false when the report does not have participants', () => { + const report: Report = { + ...LHNTestUtils.getFakeReport(), + participants: {}, + }; + const currentReportId = ''; + const isInFocusMode = true; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + expect( + ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies: {}, doesReportHaveViolations: false, excludeEmptyChats: false}), + ).toBeFalsy(); + }); + + it('should return false when the report is the report that the user cannot access due to policy restrictions', () => { + const report: Report = { + ...LHNTestUtils.getFakeReport(), + chatType: CONST.REPORT.CHAT_TYPE.DOMAIN_ALL, + }; + const currentReportId = ''; + const isInFocusMode = false; + const betas: Beta[] = []; + expect( + ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies: {}, doesReportHaveViolations: false, excludeEmptyChats: false}), + ).toBeFalsy(); + }); + + it('should return false when the report is the single transaction thread', async () => { + const expenseReport = ReportUtils.buildOptimisticExpenseReport('212', '123', 100, 122, 'USD'); + const expenseTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', expenseReport.reportID); + const expenseCreatedAction = ReportUtils.buildOptimisticIOUReportAction( + 'create', + 100, + 'USD', + '', + [], + expenseTransaction.transactionID, + undefined, + expenseReport.reportID, + undefined, + false, + false, + undefined, + undefined, + ); + const transactionThreadReport = ReportUtils.buildTransactionThread(expenseCreatedAction, expenseReport); + expenseCreatedAction.childReportID = transactionThreadReport.reportID; + const currentReportId = '1'; + const isInFocusMode = false; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, expenseReport); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, { + [expenseCreatedAction.reportActionID]: expenseCreatedAction, + }); + expect( + ReportUtils.shouldReportBeInOptionList({ + report: transactionThreadReport, + currentReportId, + isInFocusMode, + betas, + policies: {}, + doesReportHaveViolations: false, + excludeEmptyChats: false, + }), + ).toBeFalsy(); + }); + + it('should return false when the report is empty chat and the excludeEmptyChats setting is true', () => { + const report = LHNTestUtils.getFakeReport(); + const currentReportId = ''; + const isInFocusMode = false; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + expect( + ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies: {}, doesReportHaveViolations: false, excludeEmptyChats: true}), + ).toBeFalsy(); + }); + + it('should return false when the user’s email is domain-based and the includeDomainEmail is false', () => { + const report = LHNTestUtils.getFakeReport(); + const currentReportId = ''; + const isInFocusMode = false; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + expect( + ReportUtils.shouldReportBeInOptionList({ + report, + currentReportId, + isInFocusMode, + betas, + policies: {}, + doesReportHaveViolations: false, + login: '+@domain.com', + excludeEmptyChats: false, + includeDomainEmail: false, + }), + ).toBeFalsy(); + }); + + it('should return false when the report has the parent message is pending removal', async () => { + const parentReport = LHNTestUtils.getFakeReport(); + const report = LHNTestUtils.getFakeReport(); + const parentReportAction: ReportAction = { + ...LHNTestUtils.getFakeReportAction(), + message: [ + { + type: 'COMMENT', + html: 'hey', + text: 'hey', + isEdited: false, + whisperedTo: [], + isDeletedParentAction: false, + moderationDecision: { + decision: CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE, + }, + }, + ], + childReportID: report.reportID, + }; + report.parentReportID = parentReport.reportID; + report.parentReportActionID = parentReportAction.reportActionID; + const currentReportId = ''; + const isInFocusMode = false; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`, parentReport); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport.reportID}`, { + [parentReportAction.reportActionID]: parentReportAction, + }); + + expect( + ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies: {}, doesReportHaveViolations: false, excludeEmptyChats: false}), + ).toBeFalsy(); + }); + + it('should return false when the report is read and we are in the focus mode', () => { + const report = LHNTestUtils.getFakeReport(); + const currentReportId = ''; + const isInFocusMode = true; + const betas = [CONST.BETAS.DEFAULT_ROOMS]; + expect( + ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies: {}, doesReportHaveViolations: false, excludeEmptyChats: false}), + ).toBeFalsy(); + }); + }); }); }); From e6002f55e7df8d6f7e3555de8251de1e35a0887c Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 14:01:01 +0700 Subject: [PATCH 02/27] add ui test for hidden report --- tests/ui/LHNItemsPresence.tsx | 23 ++++++++++++++++++++++- tests/unit/ReportUtilsTest.ts | 5 +---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 6693c90adaa0..45eaf46b819d 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -5,7 +5,7 @@ import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentU import * as Localize from '@libs/Localize'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetailsList} from '@src/types/onyx'; +import type {PersonalDetailsList, Report} from '@src/types/onyx'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import * as TestHelper from '../utils/TestHelper'; @@ -204,5 +204,26 @@ describe('SidebarLinksData', () => { // Then the empty report should not appear in the sidebar. expect(getOptionRows()).toHaveLength(0); }); + + it('should not display the report marked as hidden', async () => { + // When the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const report: Report = { + ...LHNTestUtils.getFakeReport(), + participants: { + [TEST_USER_ACCOUNT_ID]: { + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + }, + }, + }; + + // And a report marked as hidden is initialized in Onyx + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }); + + // Then hidden report should not appear in the sidebar. + expect(getOptionRows()).toHaveLength(0); + }); }); }); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 7ee447ec088d..92adb79daf6f 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1202,10 +1202,7 @@ describe('ReportUtils', () => { }); it('should return false when the report does not have participants', () => { - const report: Report = { - ...LHNTestUtils.getFakeReport(), - participants: {}, - }; + const report = LHNTestUtils.getFakeReport([]); const currentReportId = ''; const isInFocusMode = true; const betas = [CONST.BETAS.DEFAULT_ROOMS]; From 18596e8470b5815fc7588a7f996f794ec4689f70 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 14:09:42 +0700 Subject: [PATCH 03/27] add ui test for the default room --- tests/ui/LHNItemsPresence.tsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 45eaf46b819d..9911bbeea9d9 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -225,5 +225,28 @@ describe('SidebarLinksData', () => { // Then hidden report should not appear in the sidebar. expect(getOptionRows()).toHaveLength(0); }); + + it('should not display the report the user cannot access due to policy restrictions', async () => { + // When the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const report: Report = { + ...LHNTestUtils.getFakeReport(), + chatType: CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, + }; + + // An admin room is initialized in Onyx + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }); + + // The admin room should appear in the sidebar. + expect(getOptionRows()).toHaveLength(1); + + // When the defaultRooms beta is removed + await Onyx.merge(ONYXKEYS.BETAS, []); + + // The admin room should not appear in the sidebar. + expect(getOptionRows()).toHaveLength(0); + }); }); }); From 303544c817543bbf81bcd233edc4677303106a7b Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 14:14:09 +0700 Subject: [PATCH 04/27] fix default room ui test --- tests/ui/LHNItemsPresence.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 9911bbeea9d9..099555d0436b 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -231,21 +231,22 @@ describe('SidebarLinksData', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { ...LHNTestUtils.getFakeReport(), - chatType: CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, + chatType: CONST.REPORT.CHAT_TYPE.DOMAIN_ALL, + lastMessageText: 'fake last message', }; - // An admin room is initialized in Onyx + // A default room is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); - // The admin room should appear in the sidebar. + // The default room should appear in the sidebar. expect(getOptionRows()).toHaveLength(1); // When the defaultRooms beta is removed await Onyx.merge(ONYXKEYS.BETAS, []); - // The admin room should not appear in the sidebar. + // The default room should not appear in the sidebar. expect(getOptionRows()).toHaveLength(0); }); }); From 4450fb7557584028676315583f346d81e5a0170d Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 14:20:44 +0700 Subject: [PATCH 05/27] add ui test for single transaction thread --- tests/ui/LHNItemsPresence.tsx | 45 +++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 099555d0436b..7a53a52cb831 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -12,6 +12,8 @@ import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; +import * as ReportUtils from '@libs/ReportUtils'; +import * as TransactionUtils from '@libs/TransactionUtils'; // Be sure to include the mocked permissions library, as some components that are rendered // during the test depend on its methods. @@ -240,14 +242,49 @@ describe('SidebarLinksData', () => { [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); - // The default room should appear in the sidebar. - expect(getOptionRows()).toHaveLength(1); - - // When the defaultRooms beta is removed + // And the defaultRooms beta is removed await Onyx.merge(ONYXKEYS.BETAS, []); // The default room should not appear in the sidebar. expect(getOptionRows()).toHaveLength(0); }); + + it('should not display the single transaction thread', async () => { + // When the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const expenseReport = ReportUtils.buildOptimisticExpenseReport('212', '123', 100, 122, 'USD'); + const expenseTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', expenseReport.reportID); + const expenseCreatedAction = ReportUtils.buildOptimisticIOUReportAction( + 'create', + 100, + 'USD', + '', + [], + expenseTransaction.transactionID, + undefined, + expenseReport.reportID, + undefined, + false, + false, + undefined, + undefined, + ); + const transactionThreadReport = ReportUtils.buildTransactionThread(expenseCreatedAction, expenseReport); + expenseCreatedAction.childReportID = transactionThreadReport.reportID; + + // A single transaction thread is initialized in Onyx + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport.reportID}`]: transactionThreadReport, + }); + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, expenseReport); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, { + [expenseCreatedAction.reportActionID]: expenseCreatedAction, + }); + await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${expenseTransaction.transactionID}`, expenseTransaction); + + // This report should not appear in the sidebar. + expect(getOptionRows()).toHaveLength(0); + }); }); }); From 76ff4a2e843d497d23bf35a4b0bf9aec5e7c267a Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 14:27:57 +0700 Subject: [PATCH 06/27] add ui test for the report with parent message pending removal --- tests/ui/LHNItemsPresence.tsx | 44 ++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 7a53a52cb831..792463f8c5e8 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -3,17 +3,17 @@ import type {ComponentType} from 'react'; import Onyx from 'react-native-onyx'; import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; import * as Localize from '@libs/Localize'; +import * as ReportUtils from '@libs/ReportUtils'; +import * as TransactionUtils from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {PersonalDetailsList, Report} from '@src/types/onyx'; +import type {PersonalDetailsList, Report, ReportAction} from '@src/types/onyx'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; -import * as ReportUtils from '@libs/ReportUtils'; -import * as TransactionUtils from '@libs/TransactionUtils'; // Be sure to include the mocked permissions library, as some components that are rendered // during the test depend on its methods. @@ -286,5 +286,43 @@ describe('SidebarLinksData', () => { // This report should not appear in the sidebar. expect(getOptionRows()).toHaveLength(0); }); + + it('should not display the report with parent message is pending removal', async () => { + // When the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const parentReport = LHNTestUtils.getFakeReport(); + const report = LHNTestUtils.getFakeReport(); + const parentReportAction: ReportAction = { + ...LHNTestUtils.getFakeReportAction(), + message: [ + { + type: 'COMMENT', + html: 'hey', + text: 'hey', + isEdited: false, + whisperedTo: [], + isDeletedParentAction: false, + moderationDecision: { + decision: CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE, + }, + }, + ], + childReportID: report.reportID, + }; + report.parentReportID = parentReport.reportID; + report.parentReportActionID = parentReportAction.reportActionID; + + // And a report with parent message is pending removal is initialized in Onyx + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`, parentReport); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReport.reportID}`, { + [parentReportAction.reportActionID]: parentReportAction, + }); + + // This report should not appear in the sidebar. + expect(getOptionRows()).toHaveLength(0); + }); }); }); From 0dc095ef87939b0acb458f717f2121f5d48ec474 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 14:38:58 +0700 Subject: [PATCH 07/27] add ui test for read report in the focus mode --- tests/ui/LHNItemsPresence.tsx | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 792463f8c5e8..cb4e6a92d0c8 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -211,7 +211,7 @@ describe('SidebarLinksData', () => { // When the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { - ...LHNTestUtils.getFakeReport(), + ...createReport(), participants: { [TEST_USER_ACCOUNT_ID]: { notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, @@ -232,7 +232,7 @@ describe('SidebarLinksData', () => { // When the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { - ...LHNTestUtils.getFakeReport(), + ...createReport(), chatType: CONST.REPORT.CHAT_TYPE.DOMAIN_ALL, lastMessageText: 'fake last message', }; @@ -290,8 +290,8 @@ describe('SidebarLinksData', () => { it('should not display the report with parent message is pending removal', async () => { // When the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); - const parentReport = LHNTestUtils.getFakeReport(); - const report = LHNTestUtils.getFakeReport(); + const parentReport = createReport(); + const report = createReport(); const parentReportAction: ReportAction = { ...LHNTestUtils.getFakeReportAction(), message: [ @@ -324,5 +324,29 @@ describe('SidebarLinksData', () => { // This report should not appear in the sidebar. expect(getOptionRows()).toHaveLength(0); }); + + it('should not display the read report in the focus mode', async () => { + // When the SidebarLinks are rendered. + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const report = createReport(); + const reportAction = LHNTestUtils.getFakeReportAction(); + + // And a read report with a message is initialized in Onyx + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, { + [reportAction.reportActionID]: reportAction, + }); + + // This report should appear in the sidebar. + expect(getOptionRows()).toHaveLength(1); + + // When we are in the focus mode + await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.GSD); + + // This report should not appear in the sidebar. + expect(getOptionRows()).toHaveLength(0); + }); }); }); From 80877200debdbc3fc39af08c645218fdd12d5df5 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 9 Dec 2024 15:23:43 +0700 Subject: [PATCH 08/27] fix read report ui test --- tests/ui/LHNItemsPresence.tsx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index cb4e6a92d0c8..7918dec3acb3 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -329,20 +329,13 @@ describe('SidebarLinksData', () => { // When the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report = createReport(); - const reportAction = LHNTestUtils.getFakeReportAction(); - // And a read report with a message is initialized in Onyx + // A read report is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, { - [reportAction.reportActionID]: reportAction, - }); - - // This report should appear in the sidebar. - expect(getOptionRows()).toHaveLength(1); - // When we are in the focus mode + // And we are in the focus mode await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.GSD); // This report should not appear in the sidebar. From 75ef6bf1bc11c32e9c528ab3a196efc8764673d1 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:39:59 +0700 Subject: [PATCH 09/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 27d3bcc46f45..60efb4a7c0b5 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -390,7 +390,7 @@ describe('SidebarLinksData', () => { lastMessageText: 'fake last message', }; - // A default room is initialized in Onyx + // And a default room is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); From 42603f6909aeaadd22f0b5453203621e80c510f5 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:40:09 +0700 Subject: [PATCH 10/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 60efb4a7c0b5..84572ac65d3f 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -382,7 +382,7 @@ describe('SidebarLinksData', () => { }); it('should not display the report the user cannot access due to policy restrictions', async () => { - // When the SidebarLinks are rendered. + // When the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { ...createReport(), From 9f755dff0408c0a6a48d7ff5e936db7937c49182 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:40:15 +0700 Subject: [PATCH 11/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 84572ac65d3f..d50a1f42244c 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -361,7 +361,7 @@ describe('SidebarLinksData', () => { }); it('should not display the report marked as hidden', async () => { - // When the SidebarLinks are rendered. + // When the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { ...createReport(), From bb354fb56e8776195c90d357254747badd301c4d Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:40:24 +0700 Subject: [PATCH 12/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index d50a1f42244c..d59a27387ed9 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -372,7 +372,7 @@ describe('SidebarLinksData', () => { }, }; - // And a report marked as hidden is initialized in Onyx + // And a report with notification preference set as hidden is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); From 44423febda46a090a361a39c7ff39a1c6a6d1e17 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:40:31 +0700 Subject: [PATCH 13/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index d59a27387ed9..830230558430 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -474,7 +474,7 @@ describe('SidebarLinksData', () => { [parentReportAction.reportActionID]: parentReportAction, }); - // This report should not appear in the sidebar. + // This report should not appear in the sidebar until the moderation feature decides if the message should be removed expect(getOptionRows()).toHaveLength(0); }); From 6bfd5014d609b814460c58a94f08a69b04364811 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:40:40 +0700 Subject: [PATCH 14/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 830230558430..82e3d2de42ef 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -491,7 +491,7 @@ describe('SidebarLinksData', () => { // And we are in the focus mode await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.GSD); - // This report should not appear in the sidebar. + // Then this report should not appear in the sidebar. expect(getOptionRows()).toHaveLength(0); }); }); From 0f5a9ad6f5a4c82dba6e9b19e21234cb5cef4e1d Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:40:48 +0700 Subject: [PATCH 15/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 82e3d2de42ef..0529feb90a2d 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -483,7 +483,7 @@ describe('SidebarLinksData', () => { LHNTestUtils.getDefaultRenderedSidebarLinks(); const report = createReport(); - // A read report is initialized in Onyx + // And a read report is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); From 1390f9701764f84ca987ff553f8c9bbd89310bdb Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:41:05 +0700 Subject: [PATCH 16/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 0529feb90a2d..f7e56f0888f6 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -479,7 +479,7 @@ describe('SidebarLinksData', () => { }); it('should not display the read report in the focus mode', async () => { - // When the SidebarLinks are rendered. + // When the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); const report = createReport(); From 0949558f77c20fca26616c383d98f35383d3e2e4 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:41:15 +0700 Subject: [PATCH 17/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index f7e56f0888f6..eaccd8849e00 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -403,7 +403,7 @@ describe('SidebarLinksData', () => { }); it('should not display the single transaction thread', async () => { - // When the SidebarLinks are rendered. + // When the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); const expenseReport = ReportUtils.buildOptimisticExpenseReport('212', '123', 100, 122, 'USD'); const expenseTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', expenseReport.reportID); From 264fe1962f8d7fcff9063d7ba71cb884af29ba1f Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:41:27 +0700 Subject: [PATCH 18/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index eaccd8849e00..a74dbe4bf1ab 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -436,7 +436,7 @@ describe('SidebarLinksData', () => { }); await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${expenseTransaction.transactionID}`, expenseTransaction); - // This report should not appear in the sidebar. + // Then such report should not appear in the sidebar because the highest level context is on the workspace chat with GBR that is visible in the LHN expect(getOptionRows()).toHaveLength(0); }); From cdc867c9a3a902401190487bade10770c004459d Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:41:37 +0700 Subject: [PATCH 19/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index a74dbe4bf1ab..3ac6a1303182 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -441,7 +441,7 @@ describe('SidebarLinksData', () => { }); it('should not display the report with parent message is pending removal', async () => { - // When the SidebarLinks are rendered. + // When the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); const parentReport = createReport(); const report = createReport(); From 19147a1a01003c48370b016a945d2cbfbf892ffc Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:49:30 +0700 Subject: [PATCH 20/27] add a test case for empty notification --- tests/ui/LHNItemsPresence.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 3ac6a1303182..93c80ebf92be 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -381,6 +381,20 @@ describe('SidebarLinksData', () => { expect(getOptionRows()).toHaveLength(0); }); + it('should not display the report has empty notification preference', async () => { + // When the SidebarLinks are rendered + LHNTestUtils.getDefaultRenderedSidebarLinks(); + const report = createReport(false, [2]); + + // And a report with empty notification preference is initialized in Onyx + await initializeState({ + [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + }); + + // Then the report should not appear in the sidebar. + expect(getOptionRows()).toHaveLength(0); + }); + it('should not display the report the user cannot access due to policy restrictions', async () => { // When the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); From 5446ec90443957b70ef9fc20913ea842f57a05e7 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 15:59:56 +0700 Subject: [PATCH 21/27] fix read report test --- tests/ui/LHNItemsPresence.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 93c80ebf92be..87fbdfe794fd 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -495,17 +495,31 @@ describe('SidebarLinksData', () => { it('should not display the read report in the focus mode', async () => { // When the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); - const report = createReport(); + const report: Report = { + ...createReport(), + lastMessageText: 'fake last message', + lastActorAccountID: TEST_USER_ACCOUNT_ID, + }; - // And a read report is initialized in Onyx + // And a read report that isn't empty is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); - // And we are in the focus mode + await waitForBatchedUpdatesWithAct(); + + // And the user is in default mode + await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.DEFAULT); + + // Then the report should appear in the sidebar + expect(getOptionRows()).toHaveLength(1); + + await waitForBatchedUpdatesWithAct(); + + // When the user is in focus mode await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.GSD); - // Then this report should not appear in the sidebar. + // The report should not disappear in the sidebar because it's read expect(getOptionRows()).toHaveLength(0); }); }); From 8bbf6fe1d294a3b9551ad5dbbc47d911b20749c5 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 11 Dec 2024 22:25:35 +0700 Subject: [PATCH 22/27] Update tests/ui/LHNItemsPresence.tsx Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/ui/LHNItemsPresence.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 87fbdfe794fd..349d7afa272f 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -488,7 +488,7 @@ describe('SidebarLinksData', () => { [parentReportAction.reportActionID]: parentReportAction, }); - // This report should not appear in the sidebar until the moderation feature decides if the message should be removed + // Then report should not appear in the sidebar until the moderation feature decides if the message should be removed expect(getOptionRows()).toHaveLength(0); }); From eb1095db931d87b3ae34669c4aa3f4d0072a30ce Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 12 Dec 2024 15:25:37 +0700 Subject: [PATCH 23/27] update comment with when-and-then format --- tests/ui/LHNItemsPresence.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 349d7afa272f..67ad9ff0e816 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -211,7 +211,7 @@ describe('SidebarLinksData', () => { [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); - // The report should appear in the sidebar because it’s pinned. + // Then the report should appear in the sidebar because it’s pinned. expect(getOptionRows()).toHaveLength(1); await waitForBatchedUpdatesWithAct(); @@ -276,7 +276,7 @@ describe('SidebarLinksData', () => { await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.DEFAULT); await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${archivedReport.reportID}`, reportNameValuePairs); - // The report should appear in the sidebar because it's archived + // Then the report should appear in the sidebar because it's archived expect(getOptionRows()).toHaveLength(1); }); @@ -290,7 +290,7 @@ describe('SidebarLinksData', () => { [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); - // The selfDM report should appear in the sidebar by default + // Then the selfDM report should appear in the sidebar by default expect(getOptionRows()).toHaveLength(1); }); @@ -312,7 +312,7 @@ describe('SidebarLinksData', () => { // And the user is in focus mode await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.GSD); - // The report should appear in the sidebar because it's unread + // Then the report should appear in the sidebar because it's unread expect(getOptionRows()).toHaveLength(1); // And the text is bold @@ -412,7 +412,7 @@ describe('SidebarLinksData', () => { // And the defaultRooms beta is removed await Onyx.merge(ONYXKEYS.BETAS, []); - // The default room should not appear in the sidebar. + // Then the default room should not appear in the sidebar. expect(getOptionRows()).toHaveLength(0); }); @@ -439,7 +439,7 @@ describe('SidebarLinksData', () => { const transactionThreadReport = ReportUtils.buildTransactionThread(expenseCreatedAction, expenseReport); expenseCreatedAction.childReportID = transactionThreadReport.reportID; - // A single transaction thread is initialized in Onyx + // And a single transaction thread is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport.reportID}`]: transactionThreadReport, }); From e792e873087bfad0dd10f974a96e17f2706a7706 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 16 Dec 2024 15:19:14 +0700 Subject: [PATCH 24/27] add given word --- tests/ui/LHNItemsPresence.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index 67ad9ff0e816..a4a2bb9be88d 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -228,7 +228,7 @@ describe('SidebarLinksData', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction); await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, [transactionViolation]); - // The RBR icon should be shown + // Then the RBR icon should be shown expect(screen.getByTestId('RBR Icon')).toBeOnTheScreen(); }); @@ -326,7 +326,7 @@ describe('SidebarLinksData', () => { lastReadTime: report.lastVisibleActionCreated, }); - // The report should not disappear in the sidebar because we are in the focus mode + // Then the report should not disappear in the sidebar because we are in the focus mode expect(getOptionRows()).toHaveLength(0); }); }); @@ -519,7 +519,7 @@ describe('SidebarLinksData', () => { // When the user is in focus mode await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.GSD); - // The report should not disappear in the sidebar because it's read + // Then the report should not disappear in the sidebar because it's read expect(getOptionRows()).toHaveLength(0); }); }); From 02d8152f633f507376fb0a0e3499810a58bbdae2 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 18 Dec 2024 12:51:57 +0700 Subject: [PATCH 25/27] add given word --- tests/ui/LHNItemsPresence.tsx | 64 +++++++++++++++++------------------ tests/unit/ReportUtilsTest.ts | 30 +++++++++++----- 2 files changed, 53 insertions(+), 41 deletions(-) diff --git a/tests/ui/LHNItemsPresence.tsx b/tests/ui/LHNItemsPresence.tsx index a4a2bb9be88d..162711b85499 100644 --- a/tests/ui/LHNItemsPresence.tsx +++ b/tests/ui/LHNItemsPresence.tsx @@ -126,11 +126,11 @@ describe('SidebarLinksData', () => { describe('Report that should be included in the LHN', () => { it('should display the current active report', async () => { - // When the SidebarLinks are rendered without a specified report ID. + // Given the SidebarLinks are rendered without a specified report ID. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report = createReport(); - // And the Onyx state is initialized with a report. + // When the Onyx state is initialized with a report. await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); @@ -149,14 +149,14 @@ describe('SidebarLinksData', () => { }); it('should display draft report', async () => { - // When SidebarLinks are rendered initially. + // Given SidebarLinks are rendered initially. LHNTestUtils.getDefaultRenderedSidebarLinks(); const draftReport = { ...createReport(false, [1, 2], 0), writeCapability: CONST.REPORT.WRITE_CAPABILITIES.ALL, }; - // And Onyx state is initialized with a draft report. + // When Onyx state is initialized with a draft report. await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${draftReport.reportID}`]: draftReport, }); @@ -174,11 +174,11 @@ describe('SidebarLinksData', () => { }); it('should display pinned report', async () => { - // When the SidebarLinks are rendered. + // Given the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report = createReport(false); - // And the report is initialized in Onyx. + // When the report is initialized in Onyx. await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); @@ -198,10 +198,10 @@ describe('SidebarLinksData', () => { }); it('should display the report with violations', async () => { - // When the SidebarLinks are rendered. + // Given the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); - // And the report is initialized in Onyx. + // When the report is initialized in Onyx. const report: Report = { ...createReport(true, undefined, undefined, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, TEST_POLICY_ID), ownerAccountID: TEST_USER_ACCOUNT_ID, @@ -233,14 +233,14 @@ describe('SidebarLinksData', () => { }); it('should display the report awaiting user action', async () => { - // When the SidebarLinks are rendered. + // Given the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { ...createReport(false), hasOutstandingChildRequest: true, }; - // And the report is initialized in Onyx. + // When the report is initialized in Onyx. await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); @@ -253,7 +253,7 @@ describe('SidebarLinksData', () => { }); it('should display the archived report in the default mode', async () => { - // When the SidebarLinks are rendered. + // Given the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const archivedReport: Report = { ...createReport(false), @@ -272,7 +272,7 @@ describe('SidebarLinksData', () => { await waitForBatchedUpdatesWithAct(); - // And the user is in the default mode + // When the user is in the default mode await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.DEFAULT); await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${archivedReport.reportID}`, reportNameValuePairs); @@ -281,11 +281,11 @@ describe('SidebarLinksData', () => { }); it('should display the selfDM report by default', async () => { - // When the SidebarLinks are rendered. + // Given the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report = createReport(true, undefined, undefined, undefined, CONST.REPORT.CHAT_TYPE.SELF_DM, undefined); - // And the selfDM is initialized in Onyx + // When the selfDM is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); @@ -295,7 +295,7 @@ describe('SidebarLinksData', () => { }); it('should display the unread report in the focus mode with the bold text', async () => { - // When the SidebarLinks are rendered. + // Given the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { ...createReport(undefined, undefined, undefined, undefined, undefined, true), @@ -309,7 +309,7 @@ describe('SidebarLinksData', () => { await waitForBatchedUpdatesWithAct(); - // And the user is in focus mode + // When the user is in focus mode await Onyx.merge(ONYXKEYS.NVP_PRIORITY_MODE, CONST.PRIORITY_MODE.GSD); // Then the report should appear in the sidebar because it's unread @@ -333,11 +333,11 @@ describe('SidebarLinksData', () => { describe('Report that should NOT be included in the LHN', () => { it('should not display report with no participants', async () => { - // When the SidebarLinks are rendered. + // Given the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report = LHNTestUtils.getFakeReport([]); - // And a report with no participants is initialized in Onyx. + // When a report with no participants is initialized in Onyx. await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); @@ -347,11 +347,11 @@ describe('SidebarLinksData', () => { }); it('should not display empty chat', async () => { - // When the SidebarLinks are rendered. + // Given the SidebarLinks are rendered. LHNTestUtils.getDefaultRenderedSidebarLinks(); const report = LHNTestUtils.getFakeReport([1, 2], 0); - // And a report with no messages is initialized in Onyx + // When a report with no messages is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); @@ -361,7 +361,7 @@ describe('SidebarLinksData', () => { }); it('should not display the report marked as hidden', async () => { - // When the SidebarLinks are rendered + // Given the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { ...createReport(), @@ -372,7 +372,7 @@ describe('SidebarLinksData', () => { }, }; - // And a report with notification preference set as hidden is initialized in Onyx + // When a report with notification preference set as hidden is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); @@ -382,11 +382,11 @@ describe('SidebarLinksData', () => { }); it('should not display the report has empty notification preference', async () => { - // When the SidebarLinks are rendered + // Given the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); const report = createReport(false, [2]); - // And a report with empty notification preference is initialized in Onyx + // When a report with empty notification preference is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); @@ -396,7 +396,7 @@ describe('SidebarLinksData', () => { }); it('should not display the report the user cannot access due to policy restrictions', async () => { - // When the SidebarLinks are rendered + // Given the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { ...createReport(), @@ -404,7 +404,7 @@ describe('SidebarLinksData', () => { lastMessageText: 'fake last message', }; - // And a default room is initialized in Onyx + // When a default room is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); @@ -417,7 +417,7 @@ describe('SidebarLinksData', () => { }); it('should not display the single transaction thread', async () => { - // When the SidebarLinks are rendered + // Given the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); const expenseReport = ReportUtils.buildOptimisticExpenseReport('212', '123', 100, 122, 'USD'); const expenseTransaction = TransactionUtils.buildOptimisticTransaction(100, 'USD', expenseReport.reportID); @@ -439,7 +439,7 @@ describe('SidebarLinksData', () => { const transactionThreadReport = ReportUtils.buildTransactionThread(expenseCreatedAction, expenseReport); expenseCreatedAction.childReportID = transactionThreadReport.reportID; - // And a single transaction thread is initialized in Onyx + // When a single transaction thread is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport.reportID}`]: transactionThreadReport, }); @@ -455,7 +455,7 @@ describe('SidebarLinksData', () => { }); it('should not display the report with parent message is pending removal', async () => { - // When the SidebarLinks are rendered + // Given the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); const parentReport = createReport(); const report = createReport(); @@ -479,7 +479,7 @@ describe('SidebarLinksData', () => { report.parentReportID = parentReport.reportID; report.parentReportActionID = parentReportAction.reportActionID; - // And a report with parent message is pending removal is initialized in Onyx + // When a report with parent message is pending removal is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); @@ -493,7 +493,7 @@ describe('SidebarLinksData', () => { }); it('should not display the read report in the focus mode', async () => { - // When the SidebarLinks are rendered + // Given the SidebarLinks are rendered LHNTestUtils.getDefaultRenderedSidebarLinks(); const report: Report = { ...createReport(), @@ -501,7 +501,7 @@ describe('SidebarLinksData', () => { lastActorAccountID: TEST_USER_ACCOUNT_ID, }; - // And a read report that isn't empty is initialized in Onyx + // When a read report that isn't empty is initialized in Onyx await initializeState({ [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, }); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 9e3b177502cb..46035c0b8c83 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -545,7 +545,10 @@ describe('ReportUtils', () => { parentReportID: '101', policyID: paidPolicy.id, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [ + currentUserAccountID, + participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID, + ]); expect(moneyRequestOptions.length).toBe(0); }); }); @@ -558,7 +561,10 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), chatType, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [ + currentUserAccountID, + participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID, + ]); return moneyRequestOptions.length === 1 && moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT); }); expect(onlyHaveSplitOption).toBe(true); @@ -605,7 +611,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, managerID: currentUserAccountID, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -618,7 +624,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, managerID: currentUserAccountID, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -667,7 +673,10 @@ describe('ReportUtils', () => { outputCurrency: '', isPolicyExpenseChatEnabled: false, } as const; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [ + currentUserAccountID, + participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID, + ]); expect(moneyRequestOptions.length).toBe(2); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); @@ -682,7 +691,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, managerID: currentUserAccountID, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -695,7 +704,7 @@ describe('ReportUtils', () => { statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, managerID: currentUserAccountID, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID]); expect(moneyRequestOptions.length).toBe(1); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); }); @@ -738,7 +747,10 @@ describe('ReportUtils', () => { managerID: currentUserAccountID, ownerAccountID: currentUserAccountID, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [ + currentUserAccountID, + participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID, + ]); expect(moneyRequestOptions.length).toBe(2); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); @@ -752,7 +764,7 @@ describe('ReportUtils', () => { ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.CHAT, }; - const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]); + const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID]); expect(moneyRequestOptions.length).toBe(3); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); From 71d9b233271dc4f9949eea47ea9f008b4e9ff068 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 18 Dec 2024 13:34:38 +0700 Subject: [PATCH 26/27] fix lint --- tests/unit/ReportUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 46035c0b8c83..359beac3929d 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -914,7 +914,7 @@ describe('ReportUtils', () => { const reportActionCollectionDataSet = toCollectionDataSet( ONYXKEYS.COLLECTION.REPORT_ACTIONS, reportActions.map((reportAction) => ({[reportAction.reportActionID]: reportAction})), - (actions) => Object.values(actions).at(0)?.reportActionID ?? '', + (actions) => Object.values(actions).at(0)?.reportActionID ?? `${CONST.DEFAULT_NUMBER_ID}`, ); Onyx.multiSet({ ...reportCollectionDataSet, From ad960d3dbc601f334eda15bd053436c972d8b014 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Mon, 23 Dec 2024 22:22:46 +0700 Subject: [PATCH 27/27] Update tests/unit/ReportUtilsTest.ts Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- tests/unit/ReportUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 359beac3929d..351e9e470f11 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -914,7 +914,7 @@ describe('ReportUtils', () => { const reportActionCollectionDataSet = toCollectionDataSet( ONYXKEYS.COLLECTION.REPORT_ACTIONS, reportActions.map((reportAction) => ({[reportAction.reportActionID]: reportAction})), - (actions) => Object.values(actions).at(0)?.reportActionID ?? `${CONST.DEFAULT_NUMBER_ID}`, + (actions) => Object.values(actions).at(0)?.reportActionID, ); Onyx.multiSet({ ...reportCollectionDataSet,