What options do I have to write specs for code that involves interacting with an atom editor confirmation dialog?
I'm working on a package for atom, and have a command to delete a file that then pushes changes to the server. I'd like to write a test to validate the behavior of the command, but am having trouble coming up with a good way to simulate clicking the cancel/okay button on the confirmation dialog
The command code looks like this
atom.workspaceView.command "mavensmate:delete-file-from-server", =>
# do setup stuff (build the params object)
atom.confirm
message: "You sure?"
buttons:
Cancel: => # nothing to do here, just let the window close
Delete: => # run the delete handler
@mm.run(params).then (result) =>
@mmResponseHandler(params, result)
What I can't seem to figure out is how to get the cancel or delete callbacks to run in a spec. I've been digging through all the atom specs and scouring google, but nothing seems to come up. I'd hoped that setting the return to the index of the callback I want to fire would work, but my delete button callback is never getting called.
# Delete the metadata in the active pane from the server
describe 'Delete File from Server', ->
filePath = ''
beforeEach ->
# set up the workspace with a fake apex class
directory = temp.mkdirSync()
atom.project.setPath(directory)
filePath = path.join(directory, 'MyClass.cls')
spyOn(mm, 'run').andCallThrough()
waitsForPromise ->
atom.workspace.open(filePath)
it 'should invoke mavensmate:delete-file-from-server if confirmed', ->
spyOn(atom, 'confirm').andReturn(1)
atom.workspaceView.trigger 'mavensmate:delete-file-from-server'
expect(mm.run).toHaveBeenCalled()
Is there a better way to mimic the user clicking a button on the confirmation dialog? Are there any workarounds to getting this tested?
There doesn't appear to be a good way to simulate interaction with a confirmation dialog if you're passing in callbacks with your buttons, but if you just pass an array, and have the command trigger respond to that, then you can write a spec as desired.
The command code would then look like this
atom.workspaceView.command "mavensmate:delete-file-from-server", =>
# do setup stuff (build the params object)
atom.confirm
message: "You sure?"
buttons: ["Cancel", "Delete"]
if answer == 1
@mm.run(params).then (result) =>
@mmResponseHandler(params, result)
And the spec would work in it's current version
# Delete the metadata in the active pane from the server
describe 'Delete File from Server', ->
filePath = ''
beforeEach ->
# set up the workspace with a fake apex class
directory = temp.mkdirSync()
atom.project.setPath(directory)
filePath = path.join(directory, 'MyClass.cls')
spyOn(mm, 'run').andCallThrough()
waitsForPromise ->
atom.workspace.open(filePath)
it 'should invoke mavensmate:delete-file-from-server if confirmed', ->
spyOn(atom, 'confirm').andReturn(1)
atom.workspaceView.trigger 'mavensmate:delete-file-from-server'
expect(mm.run).toHaveBeenCalled()