     waitsFor -> getCenter().getPanes().length is 2
 
     waitsFor "markdown preview to be created", ->
-      preview = atom.workspace.getPanes()[1].getActiveItem()
+      preview = getCenter().getPanes()[1].getActiveItem()
 
     runs ->
       expect(preview).toBeInstanceOf(MarkdownPreviewView)

    it "closes the existing preview when toggle is triggered a second time on the editor", ->
      atom.commands.dispatch workspaceElement, 'markdown-preview:toggle'

      [editorPane, previewPane] = atom.workspace.getPanes()
      expect(editorPane.isActive()).toBe true
      expect(previewPane.getActiveItem()).toBeUndefined()

    it "closes the existing preview when toggle is triggered on it and it has focus", ->
      [editorPane, previewPane] = atom.workspace.getPanes()
      previewPane.activate()

      atom.commands.dispatch workspaceElement, 'markdown-preview:toggle'


    describe "when the original preview is split", ->
      it "renders another preview in the new split pane", ->
        getCenter().getPanes()[1].splitRight({copyActiveItem: true})

        expect(getCenter().getPanes()).toHaveLength 3

        waitsFor "split markdown preview to be created", ->
          preview = getCenter().getPanes()[2].getActiveItem()

        runs ->
          expect(preview).toBeInstanceOf(MarkdownPreviewView)
