fix: Update report method to fix issues with special characters (#4697)
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import fromUnixTime from 'date-fns/fromUnixTime';
|
||||
import format from 'date-fns/format';
|
||||
|
||||
export const downloadCsvFile = (fileName, fileContent) => {
|
||||
export const downloadCsvFile = (fileName, content) => {
|
||||
const contentType = 'data:text/csv;charset=utf-8;';
|
||||
const blob = new Blob([content], { type: contentType });
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const link = document.createElement('a');
|
||||
link.download = fileName;
|
||||
link.href = `data:text/csv;charset=utf-8,` + encodeURI(fileContent);
|
||||
link.setAttribute('download', fileName);
|
||||
link.setAttribute('href', url);
|
||||
link.click();
|
||||
return link;
|
||||
};
|
||||
|
||||
export const generateFileName = ({ type, to }) =>
|
||||
|
||||
@@ -1,24 +1,4 @@
|
||||
import { downloadCsvFile, generateFileName } from '../downloadHelper';
|
||||
|
||||
const fileName = 'test.csv';
|
||||
const fileData = `Agent name,Conversations count,Avg first response time (Minutes),Avg resolution time (Minutes)
|
||||
Pranav,36,114,28411`;
|
||||
|
||||
describe('#downloadCsvFile', () => {
|
||||
it('should download the csv file', () => {
|
||||
const link = {
|
||||
click: jest.fn(),
|
||||
};
|
||||
jest.spyOn(document, 'createElement').mockImplementation(() => link);
|
||||
|
||||
downloadCsvFile(fileName, fileData);
|
||||
expect(link.download).toEqual(fileName);
|
||||
expect(link.href).toEqual(
|
||||
`data:text/csv;charset=utf-8,${encodeURI(fileData)}`
|
||||
);
|
||||
expect(link.click).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
import { generateFileName } from '../downloadHelper';
|
||||
|
||||
describe('#generateFileName', () => {
|
||||
it('should generate the correct file name', () => {
|
||||
|
||||
Reference in New Issue
Block a user