 
     describe 'by updating the content of a row', ->
       it 'update the rows', ->
-        rows = tableView.find('.table-edit-row')
+        rows = tableElement.find('.table-edit-row')
         expect(rows.eq(6).find('.table-edit-cell').first().text()).toEqual('row6')
 
         table.getRow(6).key = 'foo'
 
         nextAnimationFrame()
 
-        rows = tableView.find('.table-edit-row')
+        rows = tableElement.find('.table-edit-row')
         expect(rows.eq(6).find('.table-edit-cell').first().text()).toEqual('foo')
 
   describe 'setting a custom height for a row', ->
     beforeEach ->
-      tableView.setRowHeightAt(2, 100)
+      tableElement.setRowHeightAt(2, 100)
       nextAnimationFrame()
 
     it 'sets the proper height on the table body content', ->
-      bodyContent = tableView.find('.table-edit-content')
+      bodyContent = tableElement.find('.table-edit-content')
 
       expect(bodyContent.outerHeight()).toBeCloseTo(2080)
 
     it "renders the row's cells with the provided height", ->
-      cells = tableView.find('.table-edit-row:nth-child(3) .table-edit-cell')
+      cells = tableElement.find('.table-edit-row:nth-child(3) .table-edit-cell')
 
       expect(cells.first().outerHeight()).toEqual(100)
 
     it 'offsets the cells after the modified one', ->
-      row = tableView.find('.table-edit-row:nth-child(4)')
+      row = tableElement.find('.table-edit-row:nth-child(4)')
 
       expect(row.css('top')).toEqual('140px')
 
     it 'activates the cell under the mouse when pressed', ->
-      cell = tableView.find('.table-edit-row:nth-child(4) .table-edit-cell:nth-child(2)')
+      cell = tableElement.find('.table-edit-row:nth-child(4) .table-edit-cell:nth-child(2)')
       mousedown(cell)
 
-      expect(tableView.getActiveCell().getValue()).toEqual(300)
+      expect(tableElement.getActiveCell().getValue()).toEqual(300)
 
     it 'gives the size of the cell to the editor when starting an edit', ->
-      tableView.activateCellAtPosition(row: 2, column: 0)
+      tableElement.activateCellAtPosition(row: 2, column: 0)
       nextAnimationFrame()
-      tableView.startCellEdit()
-
-      expect(tableView.find('atom-text-editor').outerHeight()).toEqual(100)
+      tableElement.startCellEdit()
+
+      expect(tableElement.find('atom-text-editor').outerHeight()).toEqual(100)
 
     it 'uses the offset to position the editor', ->
-      tableView.activateCellAtPosition(row: 3, column: 0)
+      tableElement.activateCellAtPosition(row: 3, column: 0)
       nextAnimationFrame()
-      tableView.startCellEdit()
-
-      expect(tableView.find('atom-text-editor').offset().top)
-      .toBeCloseTo(tableView.find('.table-edit-cell.active').offset().top, -2)
+      tableElement.startCellEdit()
+
+      expect(tableElement.find('atom-text-editor').offset().top)
+      .toBeCloseTo(tableElement.find('.table-edit-cell.active').offset().top, -2)
 
     describe 'by changing the option on the row itself', ->
       beforeEach ->

  #     ######   #######  ##    ##    ##    ##     ##  #######  ########

  it 'gains focus when mouse is pressed on the table view', ->
    tableView.mousedown()

    expect(tableView.hiddenInput.is(':focus')).toBeTruthy()

  it 'activates the cell under the mouse when pressed', ->
    cell = tableView.find('.table-edit-row:nth-child(4) .table-edit-cell:last-child')
    mousedown(cell)

    expect(tableView.getActiveCell().getValue()).toEqual('no')

  it 'does not focus the hidden input twice when multiple press occurs', ->
    spyOn(tableView.hiddenInput, 'focus').andCallThrough()

    tableView.mousedown()
    tableView.mousedown()

    expect(tableView.hiddenInput.focus).toHaveBeenCalled()
    expect(tableView.hiddenInput.focus.calls.length).toEqual(1)
    expect(tableView.hiddenInput.is(':focus')).toBeTruthy()

  it 'has an active cell', ->
    activeCell = tableView.getActiveCell()
    expect(activeCell).toBeDefined()
    expect(activeCell.getValue()).toEqual('row0')

  it 'renders the active cell using a class', ->
    expect(tableView.find('.table-edit-header-cell.active-column').length).toEqual(1)
    expect(tableView.find('.table-edit-row.active-row').length).toEqual(1)
    expect(tableView.find('.table-edit-cell.active').length).toEqual(1)
    expect(tableView.find('.table-edit-cell.active-column').length)
    .toBeGreaterThan(1)

  describe 'when the absoluteColumnsWidths setting is enabled', ->
    beforeEach ->
      tableView.setAbsoluteColumnsWidths(true)
      nextAnimationFrame()

    it 'activates the cell under the mouse when pressed', ->
      cell = tableView.find('.table-edit-row:nth-child(4) .table-edit-cell:last-child')
      mousedown(cell)

      expect(tableView.getActiveCell().getValue()).toEqual('no')

  describe '::moveRight', ->
    it 'requests an update', ->
      spyOn(tableView, 'requestUpdate')
      tableView.moveRight()

      expect(tableView.requestUpdate).toHaveBeenCalled()

    it 'attempts to make the active row visible', ->
      spyOn(tableView, 'makeRowVisible')
      tableView.moveRight()

      expect(tableView.makeRowVisible).toHaveBeenCalled()

    it 'is triggered on core:move-right', ->
      spyOn(tableView, 'moveRight')

      atom.commands.dispatch(tableView.element, 'core:move-right')

      expect(tableView.moveRight).toHaveBeenCalled()

    it 'moves the active cell cursor to the right', ->
      tableView.moveRight()

      expect(tableView.getActiveCell().getValue()).toEqual(0)

      tableView.moveRight()

      expect(tableView.getActiveCell().getValue()).toEqual('yes')

    it 'moves the active cell to the next row when on last cell of a row', ->
      tableView.moveRight()
      tableView.moveRight()
      tableView.moveRight()
      expect(tableView.getActiveCell().getValue()).toEqual('row1')

    it 'moves the active cell to the first row when on last cell of last row', ->
      tableView.activeCellPosition.row = 99
      tableView.activeCellPosition.column = 2

      tableView.moveRight()
      expect(tableView.getActiveCell().getValue()).toEqual('row0')

  describe '::moveLeft', ->
    it 'requests an update', ->
      spyOn(tableView, 'requestUpdate')
      tableView.moveLeft()

      expect(tableView.requestUpdate).toHaveBeenCalled()

    it 'attempts to make the active row visible', ->
      spyOn(tableView, 'makeRowVisible')
      tableView.moveLeft()

      expect(tableView.makeRowVisible).toHaveBeenCalled()

    it 'is triggered on core:move-left', ->
      spyOn(tableView, 'moveLeft')

      atom.commands.dispatch(tableView.element, 'core:move-left')

      expect(tableView.moveLeft).toHaveBeenCalled()

    it 'moves the active cell to the last cell when on the first cell', ->
      tableView.moveLeft()
      expect(tableView.getActiveCell().getValue()).toEqual('no')

    it 'moves the active cell cursor to the left', ->
      tableView.moveRight()
      tableView.moveLeft()
      expect(tableView.getActiveCell().getValue()).toEqual('row0')

    it 'moves the active cell cursor to the upper row', ->
      tableView.moveRight()
      tableView.moveRight()
      tableView.moveRight()
      tableView.moveLeft()
      expect(tableView.getActiveCell().getValue()).toEqual('yes')

  describe '::moveUp', ->
    it 'requests an update', ->
      spyOn(tableView, 'requestUpdate')
      tableView.moveUp()

      expect(tableView.requestUpdate).toHaveBeenCalled()

    it 'attempts to make the active row visible', ->
      spyOn(tableView, 'makeRowVisible')
      tableView.moveUp()

      expect(tableView.makeRowVisible).toHaveBeenCalled()

    it 'is triggered on core:move-up', ->
      spyOn(tableView, 'moveUp')

      atom.commands.dispatch(tableView.element, 'core:move-up')

      expect(tableView.moveUp).toHaveBeenCalled()

    it 'moves the active cell to the last row when on the first row', ->
      tableView.moveUp()
      expect(tableView.getActiveCell().getValue()).toEqual('row99')

    it 'moves the active cell on the upper row', ->
      tableView.activeCellPosition.row = 10

      tableView.moveUp()
      expect(tableView.getActiveCell().getValue()).toEqual('row9')

  describe '::moveDown', ->
    it 'requests an update', ->
      spyOn(tableView, 'requestUpdate')
      tableView.moveDown()

      expect(tableView.requestUpdate).toHaveBeenCalled()

    it 'attempts to make the active row visible', ->
      spyOn(tableView, 'makeRowVisible')
      tableView.moveDown()

      expect(tableView.makeRowVisible).toHaveBeenCalled()

    it 'is triggered on core:move-down', ->
      spyOn(tableView, 'moveDown')

      atom.commands.dispatch(tableView.element, 'core:move-down')

      expect(tableView.moveDown).toHaveBeenCalled()

    it 'moves the active cell to the row below', ->
      tableView.moveDown()
      expect(tableView.getActiveCell().getValue()).toEqual('row1')

    it 'moves the active cell to the first row when on the last row', ->
      tableView.activeCellPosition.row = 99

      tableView.moveDown()
      expect(tableView.getActiveCell().getValue()).toEqual('row0')

  describe '::makeRowVisible', ->
    it 'scrolls the view until the passed-on row become visible', ->
      tableView.makeRowVisible(50)

      expect(tableView.body.scrollTop()).toEqual(849)

  describe 'core:undo', ->
    it 'triggers an undo on the table', ->
      spyOn(table, 'undo')

      atom.commands.dispatch(tableView.element, 'core:undo')

      expect(table.undo).toHaveBeenCalled()



  describe '::stopEdit', ->
    beforeEach ->
      tableElement.startCellEdit()
      tableElement.stopEdit()

    it 'closes the editor', ->
      expect(tableElement.isEditing()).toBeFalsy()
      expect(tableElement.find('atom-text-editor:visible').length).toEqual(0)

    it 'gives the focus back to the table view', ->
      expect(tableElement.hiddenInput.is(':focus')).toBeTruthy()

    it 'leaves the cell value as is', ->
      expect(tableElement.getActiveCell().getValue()).toEqual('row0')

  describe 'with an editor opened', ->
    [editor] = []

    beforeEach ->
      tableElement.startCellEdit()
      editor = tableElement.find('atom-text-editor').view()

    describe 'core:cancel', ->
      it 'closes the editor', ->
        atom.commands.dispatch(editor.element, 'core:cancel')
        expect(tableElement.isEditing()).toBeFalsy()

    describe 'table-edit:move-right', ->
      it 'confirms the current edit and moves the active cursor to the right', ->
        previousActiveCell = tableElement.getActiveCell()
        spyOn(tableElement, 'moveRight')
        editor.setText('Foo Bar')
        atom.commands.dispatch(editor.element, 'table-edit:move-right')

        expect(tableElement.isEditing()).toBeFalsy()
        expect(previousActiveCell.getValue()).toEqual('Foo Bar')
        expect(tableElement.moveRight).toHaveBeenCalled()

    describe 'table-edit:move-left', ->
      it 'confirms the current edit and moves the active cursor to the left', ->
        previousActiveCell = tableElement.getActiveCell()
        spyOn(tableElement, 'moveLeft')
        editor.setText('Foo Bar')
        atom.commands.dispatch(editor.element, 'table-edit:move-left')

        expect(tableElement.isEditing()).toBeFalsy()
        expect(previousActiveCell.getValue()).toEqual('Foo Bar')
        expect(tableElement.moveLeft).toHaveBeenCalled()

    describe 'core:confirm', ->
      describe 'when the content of the editor has changed', ->
