 
   describe "when core:cancel is triggered", ->
     it "detaches from the DOM and focuses the the previously focused element", ->
-      atom.workspaceView.attachToDom()
-      atom.workspaceView.trigger("package-generator:generate-package")
-
-      waitsForPromise ->
-        activationPromise
-
-      runs ->
-        packageGeneratorView = atom.workspaceView.find(".package-generator").view()
-        expect(packageGeneratorView.miniEditor.isFocused).toBeTruthy()
-        expect(atom.workspaceView.getActiveView().isFocused).toBeFalsy()
-
-        packageGeneratorView.trigger("core:cancel")
-        expect(packageGeneratorView.hasParent()).toBeFalsy()
-        expect(atom.workspaceView.getActiveView().isFocused).toBeTruthy()
+      jasmine.attachToDOM(getWorkspaceView())
+      atom.commands.dispatch(getWorkspaceView(), "package-generator:generate-package")
+
+      waitsForPromise ->
+        activationPromise
+
+      runs ->
+        packageGeneratorView = $(getWorkspaceView()).find(".package-generator").view()
+        expect(packageGeneratorView.miniEditor.element).toBe document.activeElement
+
+        atom.commands.dispatch(packageGeneratorView.element, "core:cancel")
+        expect(packageGeneratorView.panel.isVisible()).toBeFalsy()
+        expect(getEditorView()).toBe document.activeElement
 
   describe "when a package is generated", ->
     [packageName, packagePath, packageRoot] = []


  describe "when package-generator:generate-theme is triggered", ->
    it "displays a miniEditor with correct text and selection", ->
      atom.workspaceView.trigger("package-generator:generate-syntax-theme")

      waitsForPromise ->
        activationPromise

      runs ->
        packageGeneratorView = atom.workspaceView.find(".package-generator").view()
        themeName = packageGeneratorView.miniEditor.getModel().getSelectedText()
        expect(themeName).toEqual 'my-theme'



    describe 'when creating a theme', ->
      beforeEach ->
        atom.commands.dispatch(getWorkspaceView(), "package-generator:generate-syntax-theme")

        waitsForPromise ->
          activationPromise

      describe "when the theme is created outside of the packages directory", ->
        it "calls `apm init` and `apm link`", ->
          packageGeneratorView = $(getWorkspaceView()).find(".package-generator").view()
          expect(packageGeneratorView.hasParent()).toBeTruthy()
          packageGeneratorView.miniEditor.setText(packagePath)
          apmExecute = spyOn(packageGeneratorView, 'runCommand').andCallFake (command, args, exit) ->
            process.nextTick -> exit()
          atom.commands.dispatch(packageGeneratorView.element, "core:confirm")

          waitsFor ->
            atom.open.callCount is 1
