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 all 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
219 changes: 192 additions & 27 deletions tests/ui/LHNItemsPresence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import type {ValueOf} from 'type-fest';
import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails';
import DateUtils from '@libs/DateUtils';
import * as Localize from '@libs/Localize';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import FontUtils from '@styles/utils/FontUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Report, ViolationName} from '@src/types/onyx';
import type {PersonalDetailsList, Report, ReportAction, ViolationName} 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 @@ -124,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,
});
Expand All @@ -147,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,
});
Expand All @@ -172,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,
});
Expand All @@ -196,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,
Expand All @@ -209,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();

Expand All @@ -226,19 +228,19 @@ 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();
});

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,
});
Expand All @@ -251,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),
Expand All @@ -270,30 +272,30 @@ 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);

// 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);
});

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,
});

// 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);
});

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),
Expand All @@ -307,10 +309,10 @@ 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);

// 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
Expand All @@ -324,18 +326,18 @@ 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);
});
});

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,
});
Expand All @@ -345,17 +347,180 @@ 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,
});

// Then the empty report should not appear in the sidebar.
expect(getOptionRows()).toHaveLength(0);
});

it('should not display the report marked as hidden', async () => {
// Given the SidebarLinks are rendered
LHNTestUtils.getDefaultRenderedSidebarLinks();
const report: Report = {
...createReport(),
participants: {
[TEST_USER_ACCOUNT_ID]: {
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
},
},
};

// When a report with notification preference set 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);
});

it('should not display the report has empty notification preference', async () => {
// Given the SidebarLinks are rendered
LHNTestUtils.getDefaultRenderedSidebarLinks();
const report = createReport(false, [2]);

// When 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 () => {
// Given the SidebarLinks are rendered
LHNTestUtils.getDefaultRenderedSidebarLinks();
const report: Report = {
...createReport(),
chatType: CONST.REPORT.CHAT_TYPE.DOMAIN_ALL,
lastMessageText: 'fake last message',
};

// When a default room is initialized in Onyx
await initializeState({
[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
});

// And the defaultRooms beta is removed
await Onyx.merge(ONYXKEYS.BETAS, []);

// Then the default room should not appear in the sidebar.
expect(getOptionRows()).toHaveLength(0);
});

it('should not display the single transaction thread', async () => {
// Given 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;

// When 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);

// 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);
});

it('should not display the report with parent message is pending removal', async () => {
// Given the SidebarLinks are rendered
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;

// When 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,
});

// Then report should not appear in the sidebar until the moderation feature decides if the message should be removed
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
// Given the SidebarLinks are rendered
LHNTestUtils.getDefaultRenderedSidebarLinks();
const report: Report = {
...createReport(),
lastMessageText: 'fake last message',
lastActorAccountID: TEST_USER_ACCOUNT_ID,
};

// When a read report that isn't empty is initialized in Onyx
await initializeState({
[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
});

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 the report should not disappear in the sidebar because it's read
expect(getOptionRows()).toHaveLength(0);
});
});
});
Loading
Loading