|
| 1 | +import Onyx from 'react-native-onyx'; |
1 | 2 | import ModifiedExpenseMessage from '@libs/ModifiedExpenseMessage';
|
2 | 3 | import CONST from '@src/CONST';
|
| 4 | +import {translate} from '@src/libs/Localize'; |
| 5 | +import ONYXKEYS from '@src/ONYXKEYS'; |
3 | 6 | import createRandomReportAction from '../utils/collections/reportActions';
|
4 | 7 | import createRandomReport from '../utils/collections/reports';
|
| 8 | +import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; |
5 | 9 |
|
6 | 10 | describe('ModifiedExpenseMessage', () => {
|
7 | 11 | describe('getForAction', () => {
|
@@ -396,5 +400,109 @@ describe('ModifiedExpenseMessage', () => {
|
396 | 400 | expect(result).toEqual(expectedResult);
|
397 | 401 | });
|
398 | 402 | });
|
| 403 | + |
| 404 | + describe('when moving an expense', () => { |
| 405 | + beforeEach(() => Onyx.clear()); |
| 406 | + it('return the message "moved expense to self DM" when moving an expense from an expense chat or 1:1 DM to selfDM', async () => { |
| 407 | + // Given the selfDM report and report action |
| 408 | + const selfDMReport = { |
| 409 | + ...report, |
| 410 | + chatType: CONST.REPORT.CHAT_TYPE.SELF_DM, |
| 411 | + }; |
| 412 | + const reportAction = { |
| 413 | + ...createRandomReportAction(1), |
| 414 | + actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, |
| 415 | + originalMessage: { |
| 416 | + movedToReportID: selfDMReport.reportID, |
| 417 | + }, |
| 418 | + }; |
| 419 | + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}`, {[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`]: selfDMReport}); |
| 420 | + await waitForBatchedUpdates(); |
| 421 | + |
| 422 | + const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.movedToSelfDM'); |
| 423 | + |
| 424 | + // When the expense is moved from an expense chat or 1:1 DM to selfDM |
| 425 | + const result = ModifiedExpenseMessage.getForReportAction(selfDMReport.reportID, reportAction); |
| 426 | + // Then it should return the 'moved expense to self DM' message |
| 427 | + expect(result).toEqual(expectedResult); |
| 428 | + }); |
| 429 | + |
| 430 | + it('return the message "changed the expense" when reportName and workspace name are empty', async () => { |
| 431 | + // Given the policyExpenseChat with reportName is empty and report action |
| 432 | + const policyExpenseChat = { |
| 433 | + ...report, |
| 434 | + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, |
| 435 | + reportName: '', |
| 436 | + isOwnPolicyExpenseChat: false, |
| 437 | + }; |
| 438 | + const reportAction = { |
| 439 | + ...createRandomReportAction(1), |
| 440 | + actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, |
| 441 | + originalMessage: { |
| 442 | + movedToReportID: policyExpenseChat.reportID, |
| 443 | + }, |
| 444 | + }; |
| 445 | + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}`, {[`${ONYXKEYS.COLLECTION.REPORT}${policyExpenseChat.reportID}`]: policyExpenseChat}); |
| 446 | + await waitForBatchedUpdates(); |
| 447 | + |
| 448 | + const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.changedTheExpense'); |
| 449 | + |
| 450 | + // When the expense is moved to an expense chat with reportName empty |
| 451 | + const result = ModifiedExpenseMessage.getForReportAction(policyExpenseChat.reportID, reportAction); |
| 452 | + // Then it should return the 'changed the expense' message |
| 453 | + expect(result).toEqual(expectedResult); |
| 454 | + }); |
| 455 | + |
| 456 | + it('return the message "moved expense from self DM to policyName" when both reportName and policyName are present', async () => { |
| 457 | + // Given the policyExpenseChat with both reportName and policyName are present and report action |
| 458 | + const policyExpenseChat = { |
| 459 | + ...report, |
| 460 | + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, |
| 461 | + isOwnPolicyExpenseChat: false, |
| 462 | + policyName: 'fake policyName', |
| 463 | + }; |
| 464 | + const reportAction = { |
| 465 | + ...createRandomReportAction(1), |
| 466 | + actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, |
| 467 | + originalMessage: { |
| 468 | + movedToReportID: policyExpenseChat.reportID, |
| 469 | + }, |
| 470 | + }; |
| 471 | + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}`, {[`${ONYXKEYS.COLLECTION.REPORT}${policyExpenseChat.reportID}`]: policyExpenseChat}); |
| 472 | + await waitForBatchedUpdates(); |
| 473 | + |
| 474 | + const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.movedFromSelfDM', {reportName: policyExpenseChat.reportName, workspaceName: policyExpenseChat.policyName}); |
| 475 | + |
| 476 | + // When the expense is moved to an expense chat with both reportName and policyName are present |
| 477 | + const result = ModifiedExpenseMessage.getForReportAction(policyExpenseChat.reportID, reportAction); |
| 478 | + // Then it should return the correct text message |
| 479 | + expect(result).toEqual(expectedResult); |
| 480 | + }); |
| 481 | + |
| 482 | + it('return the message "moved expense from self DM to chat with reportName" when only reportName is present', async () => { |
| 483 | + // Given the policyExpenseChat with only reportName is present and report action |
| 484 | + const policyExpenseChat = { |
| 485 | + ...report, |
| 486 | + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, |
| 487 | + isOwnPolicyExpenseChat: false, |
| 488 | + }; |
| 489 | + const reportAction = { |
| 490 | + ...createRandomReportAction(1), |
| 491 | + actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE, |
| 492 | + originalMessage: { |
| 493 | + movedToReportID: policyExpenseChat.reportID, |
| 494 | + }, |
| 495 | + }; |
| 496 | + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}`, {[`${ONYXKEYS.COLLECTION.REPORT}${policyExpenseChat.reportID}`]: policyExpenseChat}); |
| 497 | + await waitForBatchedUpdates(); |
| 498 | + |
| 499 | + const expectedResult = translate(CONST.LOCALES.EN as 'en', 'iou.movedFromSelfDM', {reportName: policyExpenseChat.reportName}); |
| 500 | + |
| 501 | + // When the expense is moved to an expense chat with only reportName is present |
| 502 | + const result = ModifiedExpenseMessage.getForReportAction(policyExpenseChat.reportID, reportAction); |
| 503 | + // Then it should return the correct text message |
| 504 | + expect(result).toEqual(expectedResult); |
| 505 | + }); |
| 506 | + }); |
399 | 507 | });
|
400 | 508 | });
|
0 commit comments