Skip to content

Commit

Permalink
[Reporting/Download CSV] Get the file name from savedSearch data (#76031
Browse files Browse the repository at this point in the history
)

* [Reporting/Download CSV] provide title even if panel \titles are hidden in the dashboard

* add functional test

* Update embeddable_panel.tsx

* Update download_csv.ts
  • Loading branch information
tsullivan authored Aug 27, 2020
1 parent bf25e16 commit 69a8d06
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export class EmbeddablePanel extends React.Component<Props, State> {
<EuiPanel
className={classes}
data-test-subj="embeddablePanel"
data-test-embeddable-id={this.props.embeddable.id}
paddingSize="none"
role="figure"
aria-labelledby={headerId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class GetCsvReportPanelAction implements ActionDefinition<ActionContext>
const kibanaTimezone = this.core.uiSettings.get('dateFormat:tz');

const id = `search:${embeddable.getSavedSearch().id}`;
const filename = embeddable.getTitle();
const filename = embeddable.getSavedSearch().title;
const timezone = kibanaTimezone === 'Browser' ? moment.tz.guess() : kibanaTimezone;
const fromTime = dateMath.parse(from);
const toTime = dateMath.parse(to);
Expand Down
46 changes: 34 additions & 12 deletions x-pack/test/functional/apps/dashboard/reporting/download_csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,27 @@ import { FtrProviderContext } from '../../../ftr_provider_context';

const csvPath = path.resolve(REPO_ROOT, 'target/functional-tests/downloads/Ecommerce Data.csv');

// checks every 100ms for the file to exist in the download dir
// just wait up to 5 seconds
const getDownload$ = (filePath: string) => {
return Rx.interval(100).pipe(
map(() => fs.existsSync(filePath)),
filter((value) => value === true),
first(),
timeout(5000)
);
};

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const browser = getService('browser');
const dashboardPanelActions = getService('dashboardPanelActions');
const log = getService('log');
const testSubjects = getService('testSubjects');
const find = getService('find');
const PageObjects = getPageObjects(['reporting', 'common', 'dashboard']);

describe('Reporting Download CSV', () => {
describe('Download CSV', () => {
before('initialize tests', async () => {
log.debug('ReportingPage:initTests');
await esArchiver.loadIfNeeded('reporting/ecommerce');
Expand All @@ -33,10 +45,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
after('clean up archives and previous file download', async () => {
await esArchiver.unload('reporting/ecommerce');
await esArchiver.unload('reporting/ecommerce_kibana');
});

afterEach('remove download', () => {
try {
fs.unlinkSync(csvPath);
} catch (e) {
// nothing to worry
// it might not have been there to begin with
}
});

Expand All @@ -50,19 +65,26 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await testSubjects.click('embeddablePanelAction-downloadCsvReport');
await testSubjects.existOrFail('csvDownloadStarted'); // validate toast panel

// check every 100ms for the file to exist in the download dir
// just wait up to 5 seconds
const success$ = Rx.interval(100).pipe(
map(() => fs.existsSync(csvPath)),
filter((value) => value === true),
first(),
timeout(5000)
);

const fileExists = await success$.toPromise();
const fileExists = await getDownload$(csvPath).toPromise();
expect(fileExists).to.be(true);

// no need to validate download contents, API Integration tests do that some different variations
});

it('Gets the correct filename if panel titles are hidden', async () => {
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.loadSavedDashboard('Ecom Dashboard Hidden Panel Titles');
const savedSearchPanel = await find.byCssSelector(
'[data-test-embeddable-id="94eab06f-60ac-4a85-b771-3a8ed475c9bb"]'
); // panel title is hidden
await dashboardPanelActions.toggleContextMenu(savedSearchPanel);

await testSubjects.existOrFail('embeddablePanelAction-downloadCsvReport');
await testSubjects.click('embeddablePanelAction-downloadCsvReport');
await testSubjects.existOrFail('csvDownloadStarted');

const fileExists = await getDownload$(csvPath).toPromise(); // file exists with proper name
expect(fileExists).to.be(true);
});
});
}
Binary file not shown.

0 comments on commit 69a8d06

Please sign in to comment.