 
         nextAnimationFrame()
 
-        rows = tableView.find('.table-edit-row')
+        rows = tableElement.find('.table-edit-row')
         expect(rows.length).toEqual(18)
         expect(rows.first().data('row-id')).toEqual(1)
         expect(rows.last().data('row-id')).toEqual(18)
 
     describe 'by adding one at the begining', ->
       it 'updates the rows', ->
-        rows = tableView.find('.table-edit-row')
+        rows = tableElement.find('.table-edit-row')
         expect(rows.first().find('.table-edit-cell').first().text()).toEqual('row0')
 
         table.addRowAt 0, ['foo', 'bar', 'baz']
 
         nextAnimationFrame()
 
-        rows = tableView.find('.table-edit-row')
+        rows = tableElement.find('.table-edit-row')
         expect(rows.length).toEqual(18)
         expect(rows.first().data('row-id')).toEqual(1)
         expect(rows.first().find('.table-edit-cell').first().text()).toEqual('foo')

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

  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()


            expect(@clientWidth).toBeCloseTo(widths[i], -1)

        it 'sets the proper widths on the header cells', ->
          cells = tableElement.find('.table-edit-header-cell')
          widths = [100,200,300]
          cells.each (i) ->
            expect(@clientWidth).toBeCloseTo(widths[i], -1)

        describe 'when the content is scroll horizontally', ->
          beforeEach ->
            tableElement.getRowsContainer().scrollLeft(100)
            mousewheel(tableElement.getRowsContainer())
            nextAnimationFrame()

          it 'scrolls the header by the same amount', ->
            expect(tableElement.getColumnsContainer().scrollLeft()).toEqual(100)

    describe 'with the absolute widths setting disabled', ->
      beforeEach ->
        tableElement.setAbsoluteColumnsWidths(false)
        nextAnimationFrame()

      describe 'without any columns layout data', ->
        it 'has cells that all have the same width', ->
          cells.each ->
            expect(@clientWidth).toBeCloseTo(tableElement.width() / 3, -2)

      describe 'with a columns layout defined', ->
        describe 'with an array with enough values', ->
          it 'modifies the columns widths', ->
            tableElement.setColumnsWidths([0.2, 0.3, 0.5])
            nextAnimationFrame()

            expect(cells.first().width()).toBeCloseTo(tableElement.width() * 0.2, -2)
            expect(cells.eq(1).width()).toBeCloseTo(tableElement.width() * 0.3, -2)
            expect(cells.last().width()).toBeCloseTo(tableElement.width() * 0.5, -2)

        describe 'with an array with sparse values', ->
          it 'computes the other columns width', ->
            tableElement.setColumnsWidths([0.2, null, 0.5])
            nextAnimationFrame()

            expect(cells.first().width()).toBeCloseTo(tableElement.width() * 0.2, -2)
            expect(cells.eq(1).width()).toBeCloseTo(tableElement.width() * 0.3, -2)
            expect(cells.last().width()).toBeCloseTo(tableElement.width() * 0.5, -2)

        describe 'with an array with more than one missing value', ->
          it 'divides the rest width between the missing columns', ->
            tableElement.setColumnsWidths([0.2])
            nextAnimationFrame()

            expect(cells.first().width()).toBeCloseTo(tableElement.width() * 0.2, -2)
            expect(cells.eq(1).width()).toBeCloseTo(tableElement.width() * 0.4, -2)
            expect(cells.last().width()).toBeCloseTo(tableElement.width() * 0.4, -2)

        describe 'with an array whose sum is greater than 1', ->
          it 'divides the rest width between the missing columns', ->
            tableElement.setColumnsWidths([0.5, 0.5, 1])
            nextAnimationFrame()

            expect(cells.first().width()).toBeCloseTo(tableElement.width() * 0.25, -2)
            expect(cells.eq(1).width()).toBeCloseTo(tableElement.width() * 0.25, -2)
            expect(cells.last().width()).toBeCloseTo(tableElement.width() * 0.5, -2)

        describe 'with a sparse array whose sum is greater or equal than 1', ->
          it 'divides the rest width between the missing columns', ->
            tableElement.setColumnsWidths([0.5, 0.5])
            nextAnimationFrame()

            expect(cells.first().width()).toBeCloseTo(tableElement.width() * 0.25, -2)
            expect(cells.eq(1).width()).toBeCloseTo(tableElement.width() * 0.25, -2)
            expect(cells.last().width()).toBeCloseTo(tableElement.width() * 0.5, -2)

        describe "by setting the width on model's columns", ->
          it 'uses the columns data', ->
