diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f2135ccc..e05fa97e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased -## v4.11.0 - 2021 - 3 - 03 +## v4.12.0 - 2021 - 3 - 03 - [client/main] Added UI to open bot dialog that allows the user to set transcript testing properties `randomSeed` and `randomValue` in PR [2209](https://github.com/microsoft/BotFramework-Emulator/pull/2209) - [client] Added a dialog to the "Conversation -> Send System Activity" menu that allows the user to send custom activity payloads to their bot in PR [2213](https://github.com/microsoft/BotFramework-Emulator/pull/2213) - [main] Bumped `electron` from `4.1.1` to `11.0.1` in PR [2226](https://github.com/microsoft/BotFramework-Emulator/pull/2226) - [main] Bumped `electron-builder` to `22.9.1` and `electron-updater` to `4.3.5` to fix the Mac build in PR [2230](https://github.com/microsoft/BotFramework-Emulator/pull/2230) - [client] Re-enabled the `` tag in the client so that the inspectors show again in PR [2233](https://github.com/microsoft/BotFramework-Emulator/pull/2233) - [client] Bumped `botframework-webchat` to v4.12.0 and fixed various Web Chat-related bugs in PR [2236](https://github.com/microsoft/BotFramework-Emulator/pull/2236) +- [main] Fixed a bug where we were expecting the incorrect shape from Electron's updated `dialog.showOpenDialog()` API in PR [2237](https://github.com/microsoft/BotFramework-Emulator/pull/2237) ## v4.11.0 - 2020 - 11 - 05 - [client] Moved from master to main as the default branch. [2194](https://github.com/microsoft/BotFramework-Emulator/pull/2194) diff --git a/packages/app/main/src/commands/electronCommands.spec.ts b/packages/app/main/src/commands/electronCommands.spec.ts index 860113c0f..75a44b652 100644 --- a/packages/app/main/src/commands/electronCommands.spec.ts +++ b/packages/app/main/src/commands/electronCommands.spec.ts @@ -66,7 +66,7 @@ jest.mock('electron', () => ({ dialog: { showMessageBox: (mainBrowserWindow: any, p: { buttons: string[]; type: string; title: string; message: string }) => void 0, - showOpenDialog: () => void 0, + showOpenDialog: () => ({ filePaths: [] }), showSaveDialogSync: () => void 0, }, shell: { diff --git a/packages/app/main/src/commands/electronCommands.ts b/packages/app/main/src/commands/electronCommands.ts index aed1f0b09..5911b20fd 100644 --- a/packages/app/main/src/commands/electronCommands.ts +++ b/packages/app/main/src/commands/electronCommands.ts @@ -68,7 +68,7 @@ export class ElectronCommands { // --------------------------------------------------------------------------- // Shows an open dialog and returns a path @Command(Commands.ShowOpenDialog) - protected showOpenDialog(dialogOptions: Electron.OpenDialogOptions = {}): false | string { + protected showOpenDialog(dialogOptions: Electron.OpenDialogOptions = {}): Promise { return showOpenDialog(emulatorApplication.mainWindow.browserWindow, dialogOptions); } diff --git a/packages/app/main/src/utils/showOpenDialog.spec.ts b/packages/app/main/src/utils/showOpenDialog.spec.ts new file mode 100644 index 000000000..e7e2307a1 --- /dev/null +++ b/packages/app/main/src/utils/showOpenDialog.spec.ts @@ -0,0 +1,56 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. +// +// Microsoft Bot Framework: http://botframework.com +// +// Bot Framework Emulator Github: +// https://github.com/Microsoft/BotFramwork-Emulator +// +// Copyright (c) Microsoft Corporation +// All rights reserved. +// +// MIT License: +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import { showOpenDialog } from './showOpenDialog'; + +const mockShowOpenDialog = jest.fn().mockResolvedValue({ filePaths: [] }); +jest.mock('electron', () => ({ + dialog: { + showOpenDialog: async (...args) => mockShowOpenDialog(...args), + }, +})); + +describe('showOpenDialog', () => { + it('should return an empty string if nothing was selected', async () => { + const filePath = await showOpenDialog(undefined, undefined); + + expect(filePath).toBe(''); + }); + + it('should return the selected file path', async () => { + mockShowOpenDialog.mockResolvedValueOnce({ filePaths: ['someFile'] }); + const filePath = await showOpenDialog(undefined, undefined); + + expect(filePath).toBe('someFile'); + }); +}); diff --git a/packages/app/main/src/utils/showOpenDialog.ts b/packages/app/main/src/utils/showOpenDialog.ts index 308510f9d..4666a1aa9 100644 --- a/packages/app/main/src/utils/showOpenDialog.ts +++ b/packages/app/main/src/utils/showOpenDialog.ts @@ -34,7 +34,7 @@ import { BrowserWindow, dialog, OpenDialogOptions } from 'electron'; /** Shows a native open file / directory dialog */ -export const showOpenDialog = (window: BrowserWindow, options: OpenDialogOptions): false | string => { - const filePaths = dialog.showOpenDialog(window, options); - return filePaths && filePaths[0]; +export const showOpenDialog = async (window: BrowserWindow, options: OpenDialogOptions): Promise => { + const { filePaths = [] } = await dialog.showOpenDialog(window, options); + return filePaths[0] || ''; };