forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Expensify#54868 from bernhardoj/fix/54211-hidden-s…
…hows-when-creating-invoice Fix hidden shows when sending invoice to new user
- Loading branch information
Showing
5 changed files
with
181 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {render, screen} from '@testing-library/react-native'; | ||
import React from 'react'; | ||
import Onyx from 'react-native-onyx'; | ||
import type Navigation from '@libs/Navigation/Navigation'; | ||
import HeaderView from '@pages/home/HeaderView'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import createRandomReportAction from '../../utils/collections/reportActions'; | ||
import createRandomReport from '../../utils/collections/reports'; | ||
import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; | ||
|
||
jest.mock('@react-navigation/native', () => { | ||
const actualNav = jest.requireActual<typeof Navigation>('@react-navigation/native'); | ||
return { | ||
...actualNav, | ||
useRoute: () => jest.fn(), | ||
}; | ||
}); | ||
|
||
describe('HeaderView', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
beforeAll(() => { | ||
Onyx.init({keys: ONYXKEYS}); | ||
}); | ||
|
||
it('should update invoice room title when the invoice receiver detail is updated', async () => { | ||
// Given an invoice room header | ||
const chatReportID = '1'; | ||
const accountID = 2; | ||
let displayName = 'test'; | ||
const report = { | ||
...createRandomReport(Number(chatReportID)), | ||
chatType: CONST.REPORT.CHAT_TYPE.INVOICE, | ||
invoiceReceiver: { | ||
accountID, | ||
type: CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL, | ||
}, | ||
}; | ||
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { | ||
[accountID]: { | ||
displayName, | ||
}, | ||
}); | ||
|
||
render( | ||
<HeaderView | ||
report={report} | ||
onNavigationMenuButtonClicked={() => {}} | ||
parentReportAction={createRandomReportAction(0)} | ||
reportID={report.reportID} | ||
/>, | ||
); | ||
|
||
await waitForBatchedUpdates(); | ||
|
||
expect(screen.getByTestId('DisplayNames')).toHaveTextContent(displayName); | ||
|
||
// When the invoice receiver display name is updated | ||
displayName = 'test edit'; | ||
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { | ||
[accountID]: { | ||
displayName, | ||
}, | ||
}); | ||
|
||
// Then the header title should be updated using the new display name | ||
expect(screen.getByTestId('DisplayNames')).toHaveTextContent(displayName); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import {render, screen} from '@testing-library/react-native'; | ||
import React from 'react'; | ||
import Onyx from 'react-native-onyx'; | ||
import {LocaleContextProvider} from '@components/LocaleContextProvider'; | ||
import OnyxProvider from '@components/OnyxProvider'; | ||
import ReportPreview from '@components/ReportActionItem/ReportPreview'; | ||
import {translateLocal} from '@libs/Localize'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import createRandomReportAction from '../../utils/collections/reportActions'; | ||
import createRandomReport from '../../utils/collections/reports'; | ||
import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; | ||
|
||
jest.mock('@rnmapbox/maps', () => { | ||
return { | ||
default: jest.fn(), | ||
MarkerView: jest.fn(), | ||
setAccessToken: jest.fn(), | ||
}; | ||
}); | ||
|
||
jest.mock('@react-native-community/geolocation', () => ({ | ||
setRNConfiguration: jest.fn(), | ||
})); | ||
|
||
describe('ReportPreview', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
beforeAll(() => { | ||
Onyx.init({keys: ONYXKEYS}); | ||
}); | ||
|
||
it('should update preview message when the invoice receiver detail is updated', async () => { | ||
// Given an invoice report preview | ||
const chatReportID = '1'; | ||
const iouReportID = '2'; | ||
const accountID = 3; | ||
let displayName = 'test'; | ||
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`, { | ||
...createRandomReport(Number(chatReportID)), | ||
chatType: CONST.REPORT.CHAT_TYPE.INVOICE, | ||
invoiceReceiver: { | ||
accountID, | ||
type: CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL, | ||
}, | ||
}); | ||
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`, { | ||
...createRandomReport(Number(chatReportID)), | ||
type: CONST.REPORT.TYPE.INVOICE, | ||
isWaitingOnBankAccount: false, | ||
stateNum: CONST.REPORT.STATE_NUM.OPEN, | ||
statusNum: CONST.REPORT.STATUS_NUM.OPEN, | ||
}); | ||
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { | ||
[accountID]: { | ||
displayName, | ||
}, | ||
}); | ||
|
||
render( | ||
<OnyxProvider> | ||
<LocaleContextProvider> | ||
<ReportPreview | ||
iouReportID={iouReportID} | ||
chatReportID={chatReportID} | ||
action={createRandomReportAction(0)} | ||
policyID="" | ||
checkIfContextMenuActive={() => {}} | ||
/> | ||
</LocaleContextProvider> | ||
</OnyxProvider>, | ||
); | ||
|
||
await waitForBatchedUpdates(); | ||
|
||
expect(screen.getByTestId('reportPreview-previewMessage')).toHaveTextContent(translateLocal('iou.payerOwes', {payer: displayName})); | ||
|
||
// When the invoice receiver display name is updated | ||
displayName = 'test edit'; | ||
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { | ||
[accountID]: { | ||
displayName, | ||
}, | ||
}); | ||
|
||
// Then the report preview's preview message should be updated using the new display name | ||
expect(screen.getByTestId('reportPreview-previewMessage')).toHaveTextContent(translateLocal('iou.payerOwes', {payer: displayName})); | ||
}); | ||
}); |