@@ -6,6 +6,7 @@ os = require 'os'
66{remote , shell } = require ' electron'
77Directory = require ' ../lib/directory'
88eventHelpers = require " ./event-helpers"
9+ spyOnAsyncAndCallThrough = require (' ./async-helper' ).spyOnAsyncAndCallThrough
910
1011isCaseSensitive = null
1112isFilesystemCaseSensitive = ->
@@ -3133,6 +3134,54 @@ describe "TreeView", ->
31333134 runs ->
31343135 expect (atom .notifications .getNotifications ().length ).toBe 0
31353136
3137+ describe " treev-view:remove-permanently" , ->
3138+ beforeEach ->
3139+ jasmine .attachToDOM (workspaceElement)
3140+
3141+ it " won't remove the root directory" , ->
3142+ spyOn (atom, ' confirm' )
3143+ treeView .focus ()
3144+ root1 .dispatchEvent (new MouseEvent (' click' , {bubbles : true , detail : 1 }))
3145+ atom .commands .dispatch (treeView .element , ' tree-view:remove-permanently' )
3146+
3147+ args = atom .confirm .mostRecentCall .args [0 ]
3148+ expect (args .buttons ).toEqual [' OK' ]
3149+
3150+ it " shows the native alert dialog" , ->
3151+ spyOn (atom, ' confirm' )
3152+
3153+ waitForWorkspaceOpenEvent ->
3154+ fileView .dispatchEvent (new MouseEvent (' click' , {bubbles : true , detail : 1 }))
3155+
3156+ runs ->
3157+ atom .commands .dispatch (treeView .element , ' tree-view:remove-permanently' )
3158+ args = atom .confirm .mostRecentCall .args [0 ]
3159+ expect (args .buttons ).toEqual [' Permanently Delete ⚠️' , ' Cancel' ]
3160+
3161+
3162+ it " calls removeSelectedEntries and removeSelectedPathsPermanently" , ->
3163+ spyOn (atom, ' confirm' )
3164+
3165+ removeSelectedPathsPermanentlySpy = spyOnAsyncAndCallThrough (treeView, ' removeSelectedPathsPermanently' )
3166+ removeSelectedEntriesSpy = spyOn (treeView, ' removeSelectedEntries' ).andCallThrough ()
3167+
3168+ filePath = path .join (os .tmpdir (), ' non-project-file.txt' )
3169+ fs .writeFileSync (filePath, ' test' )
3170+
3171+ waitsForPromise ->
3172+ atom .workspace .open (filePath)
3173+
3174+ waitsForPromise ->
3175+ atom .commands .dispatch (treeView .element , ' tree-view:remove-permanently' )
3176+
3177+ waitsFor ->
3178+ removeSelectedPathsPermanentlySpy .calledWith isnt undefined
3179+
3180+ waitsFor ' removeSelectedEntries amd removeSelectedPathsPermanently to be called' , ->
3181+ removeSelectedEntriesSpy .callCount is 1 and
3182+ removeSelectedEntriesSpy .mostRecentCall .args [0 ] is true and
3183+ removeSelectedPathsPermanentlySpy .calledWith [0 ] is [filePath]
3184+
31363185 describe " file system events" , ->
31373186 temporaryFilePath = null
31383187
0 commit comments