update dialog.showOpenDialog to promisified

This commit is contained in:
Zach Bloomquist
2019-08-02 18:08:25 -04:00
parent 8b6460d015
commit 5f178b075b
2 changed files with 9 additions and 10 deletions
+3 -6
View File
@@ -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]
}
@@ -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)