forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportActionItemSingleTest.ts
More file actions
89 lines (79 loc) · 3.48 KB
/
Copy pathReportActionItemSingleTest.ts
File metadata and controls
89 lines (79 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {screen, waitFor} from '@testing-library/react-native';
import Onyx from 'react-native-onyx';
import CONST from '@src/CONST';
import type {PersonalDetailsList} from '@src/types/onyx';
import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet';
import * as LHNTestUtils from '../utils/LHNTestUtils';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';
const ONYXKEYS = {
PERSONAL_DETAILS_LIST: 'personalDetailsList',
COLLECTION: {
REPORT_ACTIONS: 'reportActions_',
POLICY: 'policy_',
},
NETWORK: 'network',
} as const;
describe('ReportActionItemSingle', () => {
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);
beforeEach(() => {
// Wrap Onyx each onyx action with waitForBatchedUpdates
wrapOnyxWithWaitForBatchedUpdates(Onyx);
// Initialize the network key for OfflineWithFeedback
return Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false});
});
// Clear out Onyx after each test so that each test starts with a clean slate
afterEach(() => {
Onyx.clear();
});
describe('when the Report is a policy expense chat', () => {
describe('and the property "shouldShowSubscriptAvatar" is true', () => {
const shouldShowSubscriptAvatar = true;
const fakeReport = LHNTestUtils.getFakeReportWithPolicy([1, 2]);
const fakeReportAction = LHNTestUtils.getFakeAdvancedReportAction();
const fakePolicy = LHNTestUtils.getFakePolicy(fakeReport.policyID);
const faceAccountId = fakeReportAction.actorAccountID ?? CONST.DEFAULT_NUMBER_ID;
const fakePersonalDetails: PersonalDetailsList = {
[faceAccountId]: {
accountID: faceAccountId,
login: 'email1@test.com',
displayName: 'Email One',
avatar: 'https://example.com/avatar.png',
firstName: 'One',
},
};
function setup() {
const policyCollectionDataSet = toCollectionDataSet(ONYXKEYS.COLLECTION.POLICY, [fakePolicy], (item) => item.id);
return waitForBatchedUpdates()
.then(() =>
Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS_LIST]: fakePersonalDetails,
...policyCollectionDataSet,
}),
)
.then(() => {
LHNTestUtils.getDefaultRenderedReportActionItemSingle(shouldShowSubscriptAvatar, fakeReport, fakeReportAction);
});
}
it('renders secondary Avatar properly', async () => {
const expectedSecondaryIconTestId = 'SvgDefaultAvatar_w Icon';
await setup();
await waitFor(() => {
expect(screen.getByTestId(expectedSecondaryIconTestId)).toBeOnTheScreen();
});
});
it('renders Person information', async () => {
const [expectedPerson] = fakeReportAction.person ?? [];
await setup();
await waitFor(() => {
expect(screen.getByText(expectedPerson.text ?? '')).toBeOnTheScreen();
});
});
});
});
});