Skip to content

Commit f80f9b4

Browse files
committed
Write tests for current method
1 parent ad719e2 commit f80f9b4

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

tests/unit/ReportUtilsTest.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
canAddTransaction,
2222
canDeleteReportAction,
2323
canDeleteTransaction,
24+
canEditReportDescription,
2425
canEditWriteCapability,
2526
canHoldUnholdReportAction,
2627
findLastAccessedReport,
@@ -3083,4 +3084,43 @@ describe('ReportUtils', () => {
30833084
expect(result).toBe(null);
30843085
});
30853086
});
3087+
3088+
describe('canEditReportDescription', () => {
3089+
it('should return true for a non-archived policy room', async () => {
3090+
// Given a non-archived policy room
3091+
const report: Report = {
3092+
...createRandomReport(40001),
3093+
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
3094+
participants: buildParticipantsFromAccountIDs([currentUserAccountID, 1]),
3095+
};
3096+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
3097+
3098+
// When it's checked if the description can be edited
3099+
// const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.reportID));
3100+
// const result = canEditReportDescription(report, isReportArchived.current);
3101+
const result = canEditReportDescription(report, policy);
3102+
3103+
// Then it can be edited
3104+
expect(result).toBeTruthy();
3105+
});
3106+
3107+
it('should return false for an archived policy room', async () => {
3108+
// Given an archived policy room
3109+
const report: Report = {
3110+
...createRandomReport(40001),
3111+
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
3112+
participants: buildParticipantsFromAccountIDs([currentUserAccountID, 1]),
3113+
};
3114+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
3115+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`, {private_isArchived: DateUtils.getDBTime()});
3116+
3117+
// When it's checked if the description can be edited
3118+
// const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.reportID));
3119+
// const result = canEditReportDescription(report, isReportArchived.current);
3120+
const result = canEditReportDescription(report, policy);
3121+
3122+
// Then it cannot be edited
3123+
expect(result).toBeFalsy();
3124+
});
3125+
});
30863126
});

0 commit comments

Comments
 (0)