Skip to content

Commit 04bc4a5

Browse files
authored
Merge pull request #62271 from callstack-internal/fix/onyx-derived-values-tests
[No QA][Test] OnyxDerivedTest not working as expected
2 parents ee42a76 + c1741f9 commit 04bc4a5

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

tests/unit/OnyxDerivedTest.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('OnyxDerived', () => {
1717
initOnyxDerivedValues();
1818
});
1919

20-
beforeEach(() => {
21-
Onyx.clear();
20+
beforeEach(async () => {
21+
await Onyx.clear();
2222
});
2323

2424
describe('conciergeChatReportID', () => {
@@ -33,55 +33,55 @@ describe('OnyxDerived', () => {
3333

3434
describe('reportAttributes', () => {
3535
const mockReport = {
36-
reportID: '123',
36+
reportID: `test_1`,
3737
reportName: 'Test Report',
3838
type: 'chat',
39-
participants: ['[email protected]', '[email protected]'],
39+
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
40+
lastVisibleActionCreated: '2023-01-01T00:00:00.000Z',
41+
lastMessageText: 'Test message',
42+
lastActorAccountID: 1,
43+
lastMessageHtml: '<p>Test message</p>',
44+
policyID: '123',
45+
ownerAccountID: 1,
46+
stateNum: CONST.REPORT.STATE_NUM.OPEN,
47+
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
4048
};
4149

42-
const mockReports = {
43-
[mockReport.reportID]: mockReport,
44-
};
45-
46-
it('returns empty reports when dependencies are not set', () => {
47-
waitForBatchedUpdates().then(async () => {
48-
const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES);
49-
expect(derivedReportAttributes).toEqual({
50-
reports: {},
51-
locale: null,
52-
});
50+
it('returns empty reports when dependencies are not set', async () => {
51+
await waitForBatchedUpdates();
52+
const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES);
53+
expect(derivedReportAttributes).toMatchObject({
54+
reports: {},
5355
});
5456
});
5557

56-
it('computes report attributes when reports are set', () => {
57-
waitForBatchedUpdates().then(async () => {
58-
await Onyx.set(ONYXKEYS.COLLECTION.REPORT, mockReports);
59-
await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'en');
60-
const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES);
61-
expect(derivedReportAttributes).toEqual({
62-
reports: {
63-
[mockReport.reportID]: {
64-
reportName: expect(String),
65-
},
58+
it('computes report attributes when reports are set', async () => {
59+
await waitForBatchedUpdates();
60+
61+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReport.reportID}`, mockReport);
62+
await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'en');
63+
64+
const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES);
65+
66+
expect(derivedReportAttributes).toMatchObject({
67+
reports: {
68+
[mockReport.reportID]: {
69+
reportName: mockReport.reportName,
6670
},
67-
locale: 'en',
68-
});
71+
},
6972
});
7073
});
7174

72-
it('updates when locale changes', () => {
73-
waitForBatchedUpdates().then(async () => {
74-
await Onyx.set(ONYXKEYS.COLLECTION.REPORT, mockReports);
75-
await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'es');
76-
const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES);
77-
expect(derivedReportAttributes).toEqual({
78-
reports: {
79-
[mockReport.reportID]: {
80-
reportName: expect(String),
81-
},
82-
},
83-
locale: 'es',
84-
});
75+
it('updates when locale changes', async () => {
76+
await waitForBatchedUpdates();
77+
78+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReport.reportID}`, mockReport);
79+
await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'es');
80+
81+
const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES);
82+
83+
expect(derivedReportAttributes).toMatchObject({
84+
locale: 'es',
8585
});
8686
});
8787
});

0 commit comments

Comments
 (0)