feat: Update agent report filename to use generated date (#2934)

This commit is contained in:
Sanju
2021-09-03 11:58:26 +05:30
committed by GitHub
parent ad83d1bb71
commit a03ed4eea0
3 changed files with 21 additions and 4 deletions

View File

@@ -116,7 +116,8 @@ export default {
},
downloadAgentReports() {
const { from, to } = this;
this.$store.dispatch('downloadAgentReports', { from, to });
const fileName = `agent-report-${format(fromUnixTime(to), 'dd-MM-yyyy')}.csv`;
this.$store.dispatch('downloadAgentReports', { from, to, fileName });
},
changeSelection(index) {
this.currentSelection = index;

View File

@@ -73,7 +73,13 @@ export const actions = {
.then(response => {
let csvContent = 'data:text/csv;charset=utf-8,' + response.data;
var encodedUri = encodeURI(csvContent);
window.open(encodedUri);
var downloadLink = document.createElement('a');
downloadLink.href = encodedUri;
downloadLink.download = reportObj.fileName;
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
})
.catch(error => {
console.error(error);

View File

@@ -12,10 +12,20 @@ describe('#actions', () => {
data: `Agent name,Conversations count,Avg first response time (Minutes),Avg resolution time (Minutes)
Pranav,36,114,28411`,
});
await actions.downloadAgentReports(1, 2);
expect(global.open).toBeCalledWith(
const param = {
from: 1630504922510,
to: 1630504922510,
fileName: 'agent-report-01-09-2021.csv',
};
const mockDownloadElement = document.createElement('a');
jest
.spyOn(document, 'createElement')
.mockImplementation(() => mockDownloadElement);
await actions.downloadAgentReports(1, param);
expect(mockDownloadElement.href).toEqual(
'data:text/csv;charset=utf-8,Agent%20name,Conversations%20count,Avg%20first%20response%20time%20(Minutes),Avg%20resolution%20time%20(Minutes)%0A%20%20%20%20%20%20%20%20Pranav,36,114,28411'
);
expect(mockDownloadElement.download).toEqual(param.fileName);
});
});
});