feat: Add Reports for teams (#3116)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
6
app/javascript/dashboard/helper/downloadCsvFile.js
Normal file
6
app/javascript/dashboard/helper/downloadCsvFile.js
Normal file
@@ -0,0 +1,6 @@
|
||||
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();
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
import { downloadCsvFile } from '../downloadCsvFile';
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user