chore: Add an option to download CSAT Reports (#4694)
This commit is contained in:
parent
361ffbab82
commit
47f04ee3fe
16 changed files with 189 additions and 28 deletions
|
@ -1,6 +1,12 @@
|
|||
import fromUnixTime from 'date-fns/fromUnixTime';
|
||||
import format from 'date-fns/format';
|
||||
|
||||
export const downloadCsvFile = (fileName, fileContent) => {
|
||||
const link = document.createElement('a');
|
||||
link.download = fileName;
|
||||
link.href = `data:text/csv;charset=utf-8,` + encodeURI(fileContent);
|
||||
link.click();
|
||||
};
|
||||
|
||||
export const generateFileName = ({ type, to }) =>
|
||||
`${type}-report-${format(fromUnixTime(to), 'dd-MM-yyyy')}.csv`;
|
|
@ -1,4 +1,4 @@
|
|||
import { downloadCsvFile } from '../downloadCsvFile';
|
||||
import { downloadCsvFile, generateFileName } from '../downloadHelper';
|
||||
|
||||
const fileName = 'test.csv';
|
||||
const fileData = `Agent name,Conversations count,Avg first response time (Minutes),Avg resolution time (Minutes)
|
||||
|
@ -19,3 +19,11 @@ describe('#downloadCsvFile', () => {
|
|||
expect(link.click).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#generateFileName', () => {
|
||||
it('should generate the correct file name', () => {
|
||||
expect(generateFileName({ type: 'csat', to: 1652812199 })).toEqual(
|
||||
'csat-report-17-05-2022.csv'
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue