Commit 7e94664a authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '197494-provide-meaningful-export-name' into 'master'

Fix csv export file name

Closes #197494

See merge request gitlab-org/gitlab!29404
parents 5564ae35 03cedbc5
......@@ -10,6 +10,7 @@ import {
import { s__ } from '~/locale';
import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils';
import { formatDate } from '~/lib/utils/datetime_utility';
import pollUntilComplete from '~/lib/utils/poll_until_complete';
export const STORAGE_KEY = 'vulnerability_csv_export_popover_dismissed';
......@@ -54,7 +55,7 @@ export default {
.then(({ data }) => pollUntilComplete(data._links.self))
.then(({ data }) => {
const anchor = document.createElement('a');
anchor.download = '';
anchor.download = `csv-export-${formatDate(new Date(), 'isoDateTime')}.csv`;
anchor.href = data._links.download;
anchor.click();
})
......
......@@ -10,6 +10,9 @@ import CsvExportButton, {
import axios from '~/lib/utils/axios_utils';
jest.mock('~/flash');
jest.mock('~/lib/utils/datetime_utility', () => ({
formatDate: () => '2020-04-12-10T14_32_35',
}));
const vulnerabilitiesExportEndpoint = `${TEST_HOST}/vulnerability_findings.csv`;
......@@ -81,7 +84,9 @@ describe('Csv Button Export', () => {
return axios.waitForAll().then(() => {
expect(spy).toHaveBeenCalledWith('a');
expect(downloadAnchor.href).toContain(downloadLink);
expect(downloadAnchor.hasAttribute('download')).toBe(true);
expect(downloadAnchor.getAttribute('download')).toBe(
`csv-export-2020-04-12-10T14_32_35.csv`,
);
expect(downloadAnchor.click).toHaveBeenCalled();
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment