feat: Update agent report filename to use generated date (#2934)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user