Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting/Download CSV] Get the file name from savedSearch data #76031

Merged
merged 4 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading