[MM-45646] Change download notification text to display saved filename instead of original (#2203)

This commit is contained in:
Devin Binnie
2022-07-20 15:46:03 -04:00
committed by GitHub
parent 6b2daba411
commit ad3e1500cc
2 changed files with 28 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ import {app, session} from 'electron';
import Config from 'common/config';
import urlUtils from 'common/utils/url';
import {displayDownloadCompleted} from 'main/notifications';
import parseArgs from 'main/ParseArgs';
import WindowManager from 'main/windows/windowManager';
@@ -142,6 +143,7 @@ jest.mock('main/windows/windowManager', () => ({
getMainWindow: jest.fn(),
showMainWindow: jest.fn(),
sendToMattermostViews: jest.fn(),
getServerNameByWebContentsId: jest.fn(),
}));
describe('main/app/initialize', () => {
@@ -247,6 +249,31 @@ describe('main/app/initialize', () => {
}));
});
it('should use name of saved file instead of original file name', async () => {
const item = {
getFilename: () => 'filename.txt',
on: jest.fn(),
setSaveDialogOptions: jest.fn(),
savePath: '/some/dir/new_filename.txt',
};
Config.downloadLocation = '/some/dir';
path.resolve.mockImplementation((base, p) => `${base}/${p}`);
session.defaultSession.on.mockImplementation((event, cb) => {
if (event === 'will-download') {
cb(null, item, {id: 0, getURL: jest.fn()});
}
});
item.on.mockImplementation((event, cb) => {
if (event === 'done') {
cb(null, 'completed');
}
});
await initialize();
expect(displayDownloadCompleted).toHaveBeenCalledWith('new_filename.txt', '/some/dir/new_filename.txt', expect.anything());
});
it('should allow permission requests for supported types from trusted URLs', async () => {
let callback = jest.fn();
session.defaultSession.setPermissionRequestHandler.mockImplementation((cb) => {

View File

@@ -372,7 +372,7 @@ function initializeAfterAppReady() {
item.on('done', (doneEvent, state) => {
if (state === 'completed') {
displayDownloadCompleted(filename, item.savePath, WindowManager.getServerNameByWebContentsId(webContents.id) || '');
displayDownloadCompleted(path.basename(item.savePath), item.savePath, WindowManager.getServerNameByWebContentsId(webContents.id) || '');
}
});
});