Skip to content

Commit

Permalink
Rewrite as API Integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Jan 26, 2024
1 parent 1c07c24 commit 956bf8b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 40 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-generate-csv/src/generate_csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class CsvGenerator {
// apply timezone from the job to all date field formatters
try {
index.fields.getByType('date').forEach(({ name }) => {
logger.debug(`Setting timezone on ${name}`);
logger.debug(`Setting ${timezone} timezone on ${name}`);
const format: FieldFormatConfig = {
...index.fieldFormatMap[name],
id: index.fieldFormatMap[name]?.id || 'date', // allow id: date_nanos
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -171,38 +171,5 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expectSnapshot(csvFile).toMatch();
});
});

describe('Field Formatters and Scripted Fields', () => {
const dashboardWithScriptedFieldsSearch = 'names dashboard';

before(async () => {
await reporting.initLogs();
await esArchiver.load('x-pack/test/functional/es_archives/reporting/hugedata');

await navigateToDashboardApp();
await PageObjects.dashboard.loadSavedDashboard(dashboardWithScriptedFieldsSearch);
await PageObjects.timePicker.setAbsoluteRange(
'Nov 26, 1981 @ 21:54:15.526',
'Mar 5, 1982 @ 18:17:44.821'
);

await PageObjects.common.sleep(1000);
await filterBar.addFilter({ field: 'name.keyword', operation: 'is', value: 'Fethany' });
await PageObjects.common.sleep(1000);
});

after(async () => {
await reporting.teardownLogs();
await esArchiver.unload('x-pack/test/functional/es_archives/reporting/hugedata');
});

it('Download CSV export of a saved search panel', async () => {
await clickActionsMenu('namessearch');
await clickDownloadCsv();

const csvFile = await getDownload(getCsvPath('namessearch'));
expectSnapshot(csvFile).toMatch();
});
});
});
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,64 @@ export default function ({ getService }: FtrProviderContext) {
});
});

describe('scripted fields', () => {
before(async () => {
await reportingAPI.initLogs();
await esArchiver.load('x-pack/test/functional/es_archives/reporting/hugedata');
});

after(async () => {
await reportingAPI.teardownLogs();
await esArchiver.unload('x-pack/test/functional/es_archives/reporting/hugedata');
});

it('years_ago field calculates the number of years to 2019', async () => {
const res = (await generateAPI.getCSVFromSearchSource(
getMockJobParams({
browserTimezone: 'UTC',
version: '8.13.0',
searchSource: {
query: { query: '', language: 'kuery' },
fields: [{ field: '*', include_unmapped: 'true' }],
index: '89655130-5013-11e9-bce7-4dabcb8bef24',
sort: [{ date: { order: 'desc', format: 'strict_date_optional_time' } }],
filter: [
{
query: { match_phrase: { 'name.keyword': 'Fethany' } },
},
],
parent: {
query: { query: '', language: 'kuery' },
filter: [],
parent: {
filter: [
{
query: {
range: {
date: {
format: 'strict_date_optional_time',
gte: '1979-09-01T05:31:57.572Z',
lte: '1980-04-18T10:47:57.709Z',
},
},
},
},
],
},
},
},
columns: [],
title: 'years_ago',
})
)) as supertest.Response;
const { status: resStatus, text: resText, type: resType } = res;

expect(resStatus).to.eql(200);
expect(resType).to.eql('text/csv');
expectSnapshot(resText).toMatch();
});
});

describe('nanosecond formatting', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/reporting/nanos');
Expand Down

0 comments on commit 956bf8b

Please sign in to comment.