 {generateFakeFetchResponses, generateException} = require './helper'
 
 describe "Notifications Log", ->
-  [workspaceElement, activationPromise] = []
+  workspaceElement = null
 
   beforeEach ->
     workspaceElement = atom.views.getView(atom.workspace)
     atom.notifications.clear()
-    activationPromise = atom.packages.activatePackage('notifications')
 
     waitsForPromise ->
-      activationPromise
+      atom.packages.activatePackage('notifications')
 
     waitsForPromise ->
       atom.workspace.open(NotificationsLog::getURI())


  describe "when notifications are added to atom.notifications", ->
    notificationsLogContainer = null
    beforeEach ->
      enableInitNotification = atom.notifications.addSuccess('A message to trigger initialization', dismissable: true)
      enableInitNotification.dismiss()

            expect(didDismiss).toBe true
            expect(notification.dismissed).toBe true
            expect(notificationView.element).not.toBeVisible()

  describe "the dock pane", ->
    notificationsLogPane = null

    beforeEach ->
      notificationsLogPane = atom.workspace.paneForURI(NotificationsLog::getURI())

    describe "when notifications:toggle-log is dispatched", ->
      it "toggles the pane URI", ->
        spyOn(atom.workspace, "toggle")

        atom.commands.dispatch(workspaceElement, "notifications:toggle-log")
        expect(atom.workspace.toggle).toHaveBeenCalledWith(NotificationsLog::getURI())

      describe "when the pane is destroyed", ->

        beforeEach ->
          notificationsLogPane.destroyItems()

        it "opens the pane", ->
          [notificationsLog] = []

          waitsForPromise ->
            atom.workspace.toggle(NotificationsLog::getURI()).then (paneItem) ->
              notificationsLog = paneItem

          runs ->
            expect(notificationsLog).toBeDefined()

        describe "when notifications are displayed", ->

          beforeEach ->
            atom.notifications.addSuccess("success")

          it "lists all notifications", ->
            waitsForPromise ->
              atom.workspace.toggle(NotificationsLog::getURI())

            runs ->
              notificationsLogContainer = workspaceElement.querySelector('.notifications-log-items')
              expect(notificationsLogContainer.childNodes).toHaveLength 1

      describe "when the pane is hidden", ->

        beforeEach ->
          atom.workspace.hide(NotificationsLog::getURI())

        it "opens the pane", ->
          [notificationsLog] = []

          waitsForPromise ->
            atom.workspace.toggle(NotificationsLog::getURI()).then (paneItem) ->
              notificationsLog = paneItem

          runs ->
            expect(notificationsLog).toBeDefined()

      describe "when the pane is open", ->

        beforeEach ->
          waitsForPromise ->
            atom.workspace.open(NotificationsLog::getURI())

        it "closes the pane", ->
          notificationsLog = null

          waitsForPromise ->
            atom.workspace.toggle(NotificationsLog::getURI()).then (paneItem) ->
              notificationsLog = paneItem

          runs ->
            expect(notificationsLog).not.toBeDefined()
