Skip to content

Commit 964913f

Browse files
Add a Current view card-group export test to pin both export paths to one scope
Co-authored-by: Yauheni Horbach <ZhenjaHorbach@users.noreply.github.com>
1 parent 230b034 commit 964913f

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎tests/unit/hooks/useSearchBulkActionsExportTest.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,39 @@ describe('useSearchBulkActions - export options', () => {
13671367
expect(parameters?.transactionIDList).toEqual(['tx2']);
13681368
expect(parameters?.jsonQuery).toContain(CONST.SEARCH.SYNTAX_FILTER_KEYS.CARD_ID);
13691369
});
1370+
1371+
// The template export and Current view both scope a group selection through `getGroupExportScope`. Pinning
1372+
// Current view to the same expectation is what stops the two paths drifting apart again: the gate that shows
1373+
// the Reconciliation option and the gate that scopes it have to agree, or a card group exports incompletely.
1374+
it('scopes the Current view export of a card group the same way as the Reconciliation template', async () => {
1375+
mockTemplatesIncludingReconciliation();
1376+
selectCardGroup();
1377+
// An expense ticked on its own, alongside the card group, so it is not covered by the group's filter.
1378+
mockSelectedTransactions.tx2 = makeSelectedTransaction();
1379+
const searchResults = makeSearchResults([]);
1380+
Object.assign(searchResults.data, {[CARD_GROUP_KEY]: {cardID: 1234}});
1381+
mockCurrentSearchResults = searchResults;
1382+
jest.mocked(getSelectedGroupFilterEntry).mockReturnValue({key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CARD_ID, value: 1234});
1383+
1384+
const {result} = renderHook(() => useSearchBulkActions({queryJSON: cardGroupedExpenseQueryJSON}), {wrapper: OnyxListItemProvider});
1385+
1386+
await waitFor(() => {
1387+
expect(getExportOptionByText(result.current.headerButtonsOptions, 'export.currentView')).toBeDefined();
1388+
});
1389+
1390+
getExportOptionByText(result.current.headerButtonsOptions, 'export.currentView')?.onSelected?.();
1391+
1392+
await waitFor(() => {
1393+
expect(exportSearchItemsToCSV).toHaveBeenCalled();
1394+
});
1395+
1396+
const {isGroupExport, reportIDList, transactionIDList, query} = getLastCSVExportParameters();
1397+
expect(isGroupExport).toBe(true);
1398+
expect(reportIDList).toEqual([]);
1399+
expect(transactionIDList).toEqual(['tx2']);
1400+
// The selected card groups reach the backend as a `cardID:` filter on the query rather than as IDs.
1401+
expect(JSON.stringify(query)).toContain(CONST.SEARCH.SYNTAX_FILTER_KEYS.CARD_ID);
1402+
});
13701403
});
13711404

13721405
it('offers Current view as the only plain-CSV export on a grouped search', async () => {

0 commit comments

Comments
 (0)