From 5f178b075bcb46daab8564736e0a318c2d21a431 Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Fri, 2 Aug 2019 18:08:25 -0400 Subject: [PATCH] update dialog.showOpenDialog to promisified --- packages/server/lib/gui/dialog.coffee | 9 +++------ packages/server/test/unit/gui/dialog_spec.coffee | 10 ++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/server/lib/gui/dialog.coffee b/packages/server/lib/gui/dialog.coffee index c95cddd2ad8b..2531c09d044c 100644 --- a/packages/server/lib/gui/dialog.coffee +++ b/packages/server/lib/gui/dialog.coffee @@ -15,10 +15,7 @@ module.exports = { properties: ["openDirectory"] } - new Promise (resolve, reject) -> - dialog.showOpenDialog props, (paths = []) -> - process.nextTick -> - ## return the first path since there can only ever - ## be a single directory selection - resolve(paths[0]) + dialog.showOpenDialog(props) + .then ({ filePaths }) -> + return filePaths[0] } diff --git a/packages/server/test/unit/gui/dialog_spec.coffee b/packages/server/test/unit/gui/dialog_spec.coffee index 43a5d3eecdca..89133131770a 100644 --- a/packages/server/test/unit/gui/dialog_spec.coffee +++ b/packages/server/test/unit/gui/dialog_spec.coffee @@ -7,7 +7,9 @@ Windows = require("#{root}../lib/gui/windows") describe "gui/dialog", -> context ".show", -> beforeEach -> - @showOpenDialog = electron.dialog.showOpenDialog = sinon.stub() + @showOpenDialog = electron.dialog.showOpenDialog = sinon.stub().resolves({ + filePaths: [] + }) it "calls dialog.showOpenDialog with args", -> dialog.show() @@ -16,13 +18,13 @@ describe "gui/dialog", -> }) it "resolves with first path", -> - @showOpenDialog.yields(["foo", "bar"]) + @showOpenDialog.resolves({ + filePaths: ["foo", "bar"] + }) dialog.show().then (ret) -> expect(ret).to.eq("foo") it "handles null paths", -> - @showOpenDialog.yields(null) - dialog.show().then (ret) -> expect(ret).to.eq(undefined)