Skip to content

Commit 9d87153

Browse files
committed
test the logic to sort the fields
1 parent c7694f6 commit 9d87153

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

x-pack/plugins/reporting/server/export_types/csv_searchsource/generate_csv/__snapshots__/generate_csv.test.ts.snap

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/reporting/server/export_types/csv_searchsource/generate_csv/generate_csv.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,70 @@ describe('fields', () => {
431431
expect(csvResult.content).toMatchSnapshot();
432432
expect(csvResult.csv_contains_formulas).toBe(false);
433433
});
434+
435+
it('sorts the fields when they are to be used as table column names', async () => {
436+
searchSourceMock.getField = jest.fn().mockImplementation((key: string) => {
437+
if (key === 'fields') {
438+
return ['*'];
439+
}
440+
return mockSearchSourceGetFieldDefault(key);
441+
});
442+
mockDataClient.search = jest.fn().mockImplementation(() =>
443+
Rx.of({
444+
rawResponse: {
445+
hits: {
446+
hits: [
447+
{
448+
_id: 'my-cool-id',
449+
_index: 'my-cool-index',
450+
_version: 4,
451+
fields: {
452+
date: ['2020-12-31T00:14:28.000Z'],
453+
message_z: [`test field Z`],
454+
message_y: [`test field Y`],
455+
message_x: [`test field X`],
456+
message_w: [`test field W`],
457+
message_v: [`test field V`],
458+
message_u: [`test field U`],
459+
message_t: [`test field T`],
460+
},
461+
},
462+
],
463+
total: 1,
464+
},
465+
},
466+
})
467+
);
468+
469+
const generateCsv = new CsvGenerator(
470+
createMockJob({
471+
searchSource: {
472+
query: { query: '', language: 'kuery' },
473+
sort: [{ '@date': 'desc' }],
474+
index: '93f4bc50-6662-11eb-98bc-f550e2308366',
475+
fields: ['*'],
476+
filter: [],
477+
},
478+
}),
479+
mockConfig,
480+
{
481+
es: mockEsClient,
482+
data: mockDataClient,
483+
uiSettings: uiSettingsClient,
484+
},
485+
{
486+
searchSourceStart: mockSearchSourceService,
487+
fieldFormatsRegistry: mockFieldFormatsRegistry,
488+
},
489+
new CancellationToken(),
490+
logger
491+
);
492+
493+
const csvResult = await generateCsv.generateData();
494+
495+
expect(csvResult.content).toMatchSnapshot();
496+
expect(csvResult.csv_contains_formulas).toBe(false);
497+
});
434498
});
435499

436500
describe('formulas', () => {

0 commit comments

Comments
 (0)