mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-25 03:20:23 +01:00
90827c54a1
* Add improved downloading logic when exporting state logs * Make test for state logs download only apply to firefox * Remove eslint override * Add file extension to test * Move make jest global.Blob accessible to window
69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
import { exportAsFile, ExportableContentType } from './export-utils';
|
|
|
|
describe('exportAsFile', () => {
|
|
let windowSpy;
|
|
|
|
beforeEach(() => {
|
|
windowSpy = jest.spyOn(window, 'window', 'get');
|
|
});
|
|
|
|
afterEach(() => {
|
|
windowSpy.mockRestore();
|
|
});
|
|
|
|
describe('when showSaveFilePicker is supported', () => {
|
|
it('uses .json file extension when content type is JSON', async () => {
|
|
const showSaveFilePicker = mockShowSaveFilePicker();
|
|
const filename = 'test.json';
|
|
const data = '{file: "content"}';
|
|
windowSpy.mockImplementation(() => ({
|
|
showSaveFilePicker,
|
|
Blob: global.Blob,
|
|
}));
|
|
|
|
await exportAsFile(filename, data, ExportableContentType.JSON);
|
|
|
|
expect(showSaveFilePicker).toHaveBeenCalledWith({
|
|
suggestedName: filename,
|
|
types: [
|
|
{
|
|
description: filename,
|
|
accept: { 'application/json': ['.json'] },
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it('uses .txt file extension when content type is TXT', async () => {
|
|
const showSaveFilePicker = mockShowSaveFilePicker();
|
|
const filename = 'test.txt';
|
|
const data = 'file content';
|
|
|
|
windowSpy.mockImplementation(() => ({
|
|
showSaveFilePicker,
|
|
Blob: global.Blob,
|
|
}));
|
|
|
|
await exportAsFile(filename, data, ExportableContentType.TXT);
|
|
|
|
expect(showSaveFilePicker).toHaveBeenCalledWith({
|
|
suggestedName: filename,
|
|
types: [
|
|
{
|
|
description: filename,
|
|
accept: { 'text/plain': ['.txt'] },
|
|
},
|
|
],
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
function mockShowSaveFilePicker() {
|
|
return jest.fn().mockResolvedValueOnce({
|
|
createWritable: jest
|
|
.fn()
|
|
.mockResolvedValueOnce({ write: jest.fn(), close: jest.fn() }),
|
|
});
|
|
}
|