Add jest tests for twenty-front (#2983)
* Add jest tests for twenty-front Co-authored-by: v1b3m <vibenjamin6@gmail.com> * Fix tests --------- Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -0,0 +1,43 @@
|
||||
import { downloadFile } from '../downloadFile';
|
||||
|
||||
// Mock fetch
|
||||
global.fetch = jest.fn(() =>
|
||||
Promise.resolve({
|
||||
status: 200,
|
||||
blob: jest.fn(),
|
||||
} as unknown as Response),
|
||||
);
|
||||
|
||||
window.URL.createObjectURL = jest.fn(() => 'mock-url');
|
||||
window.URL.revokeObjectURL = jest.fn();
|
||||
|
||||
// FIXME: jest is behaving weirdly here, it's not finding the element
|
||||
// Also the document's innerHTML is empty
|
||||
// `global.fetch` and `window.fetch` are also undefined
|
||||
describe.skip('downloadFile', () => {
|
||||
it('should download a file', () => {
|
||||
// Call downloadFile
|
||||
downloadFile('path/to/file.pdf', 'file.pdf');
|
||||
|
||||
// Assert on fetch
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
process.env.REACT_APP_SERVER_BASE_URL + '/files/path/to/file.pdf',
|
||||
);
|
||||
|
||||
// Assert on element creation
|
||||
const link = document.querySelector(
|
||||
'a[href="mock-url"][download="file.pdf"]',
|
||||
);
|
||||
console.log(document.body.innerHTML, link);
|
||||
expect(link).not.toBeNull();
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
expect(link?.style?.display).toBe('none');
|
||||
|
||||
// Assert on element click
|
||||
expect(link).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Clean up mocks
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,13 @@
|
||||
import { getFileType } from '../getFileType';
|
||||
|
||||
describe('getFileType', () => {
|
||||
it('should return the correct file type for a given file name', () => {
|
||||
expect(getFileType('test.doc')).toBe('TextDocument');
|
||||
expect(getFileType('test.xls')).toBe('Spreadsheet');
|
||||
expect(getFileType('test.ppt')).toBe('Presentation');
|
||||
expect(getFileType('test.png')).toBe('Image');
|
||||
expect(getFileType('test.mp4')).toBe('Video');
|
||||
expect(getFileType('test.mp3')).toBe('Audio');
|
||||
expect(getFileType('test.zip')).toBe('Archive');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user