Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Add unit test for report should not be displayed in LHN #53745

Merged
merged 34 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
219090e
add shouldReportBeInOptionList test
mkzie2 Dec 9, 2024
e6002f5
add ui test for hidden report
mkzie2 Dec 9, 2024
18596e8
add ui test for the default room
mkzie2 Dec 9, 2024
303544c
fix default room ui test
mkzie2 Dec 9, 2024
4450fb7
add ui test for single transaction thread
mkzie2 Dec 9, 2024
76ff4a2
add ui test for the report with parent message pending removal
mkzie2 Dec 9, 2024
0dc095e
add ui test for read report in the focus mode
mkzie2 Dec 9, 2024
8087720
fix read report ui test
mkzie2 Dec 9, 2024
2a52f32
merge main
mkzie2 Dec 9, 2024
4dbb367
Merge branch 'main' into mkzie2-issue/52034
mkzie2 Dec 11, 2024
75ef6bf
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
42603f6
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
9f755df
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
bb354fb
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
44423fe
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
6bfd501
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
0f5a9ad
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
1390f97
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
0949558
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
264fe19
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
cdc867c
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
19147a1
add a test case for empty notification
mkzie2 Dec 11, 2024
5446ec9
fix read report test
mkzie2 Dec 11, 2024
8bbf6fe
Update tests/ui/LHNItemsPresence.tsx
mkzie2 Dec 11, 2024
6655108
Merge branch 'main' into mkzie2-issue/52034
mkzie2 Dec 12, 2024
eb1095d
update comment with when-and-then format
mkzie2 Dec 12, 2024
c9dccbd
Merge branch 'main' into mkzie2-issue/52034
mkzie2 Dec 16, 2024
e792e87
add given word
mkzie2 Dec 16, 2024
407c7a4
Merge branch 'main' into mkzie2-issue/52034
mkzie2 Dec 18, 2024
02d8152
add given word
mkzie2 Dec 18, 2024
71d9b23
fix lint
mkzie2 Dec 18, 2024
b3302fc
Merge branch 'main' into mkzie2-issue/52034
mkzie2 Dec 23, 2024
ad960d3
Update tests/unit/ReportUtilsTest.ts
mkzie2 Dec 23, 2024
d6abec5
Merge branch 'main' into mkzie2-issue/52034
mkzie2 Dec 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 138 additions & 1 deletion tests/ui/LHNItemsPresence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ 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} 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';
Expand Down Expand Up @@ -204,5 +206,140 @@ 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.
mkzie2 marked this conversation as resolved.
Show resolved Hide resolved
LHNTestUtils.getDefaultRenderedSidebarLinks();
const report: Report = {
...createReport(),
participants: {
[TEST_USER_ACCOUNT_ID]: {
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
},
},
};

// And a report marked as hidden is initialized in Onyx
mkzie2 marked this conversation as resolved.
Show resolved Hide resolved
await initializeState({
[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
});

// Then hidden report should not appear in the sidebar.
expect(getOptionRows()).toHaveLength(0);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are actually doind some changes to this flow, can you also add a test (if not present) to make sure the report that has empty notification preference is also not rendered?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a case for empty notification.


it('should not display the report the user cannot access due to policy restrictions', async () => {
// When the SidebarLinks are rendered.
mkzie2 marked this conversation as resolved.
Show resolved Hide resolved
LHNTestUtils.getDefaultRenderedSidebarLinks();
const report: Report = {
...createReport(),
chatType: CONST.REPORT.CHAT_TYPE.DOMAIN_ALL,
lastMessageText: 'fake last message',
};

// A default room is initialized in Onyx
mkzie2 marked this conversation as resolved.
Show resolved Hide resolved
await initializeState({
[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
});

// 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.
mkzie2 marked this conversation as resolved.
Show resolved Hide resolved
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.
mkzie2 marked this conversation as resolved.
Show resolved Hide resolved
expect(getOptionRows()).toHaveLength(0);
});

it('should not display the report with parent message is pending removal', async () => {
// When the SidebarLinks are rendered.
mkzie2 marked this conversation as resolved.
Show resolved Hide resolved
LHNTestUtils.getDefaultRenderedSidebarLinks();
const parentReport = createReport();
const report = createReport();
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.
mkzie2 marked this conversation as resolved.
Show resolved Hide resolved
expect(getOptionRows()).toHaveLength(0);
});

it('should not display the read report in the focus mode', async () => {
mountiny marked this conversation as resolved.
Show resolved Hide resolved
// When the SidebarLinks are rendered.
mkzie2 marked this conversation as resolved.
Show resolved Hide resolved
LHNTestUtils.getDefaultRenderedSidebarLinks();
const report = createReport();

// A read report is initialized in Onyx
mkzie2 marked this conversation as resolved.
Show resolved Hide resolved
await initializeState({
[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
});

// 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.
mkzie2 marked this conversation as resolved.
Show resolved Hide resolved
expect(getOptionRows()).toHaveLength(0);
});
});
});
163 changes: 162 additions & 1 deletion tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -1179,5 +1180,165 @@ 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 = 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();
});

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: '[email protected]',
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();
});
});
});
});
Loading