diff --git a/spec/pivotal-ui-react/table/plugins/sorting_spec.js b/spec/pivotal-ui-react/table/plugins/sorting_spec.js index 45cd5036b..6bb43c2fb 100644 --- a/spec/pivotal-ui-react/table/plugins/sorting_spec.js +++ b/spec/pivotal-ui-react/table/plugins/sorting_spec.js @@ -13,19 +13,45 @@ describe('withSorting', () => { }); describe('with columns', () => { + let subject; + beforeEach(() => { const columns = [{ - attribute: 'attr1' + attribute: 'attr1', sortable: true }, { attribute: 'attr2', displayName: 'Display2' }]; - ReactDOM.render(, root); + subject = ReactDOM.render(, root); }); it('renders', () => { expect('.sorting-table').toExist(); }); + + describe('when sorted in descending order', () => { + beforeEach(() => { + $('.sortable:eq(0)').click(); + }); + + it('sorts in descending order', () => { + expect('.sortable:eq(0)').toHaveClass('sorted-desc'); + }); + + describe('when new data is added', () => { + beforeEach(() => { + data.push({ + attr1: 'row3-value1', attr2: 'row3-value2' + }); + subject::setProps({data}); + }); + + it('retains the sort order', () => { + expect('.sortable:eq(0)').toHaveClass('sorted-desc'); + expect('tbody tr:eq(0) td:eq(0)').toHaveText('row3-value1'); + }); + }); + }); }); describe('without columns', () => { @@ -37,5 +63,4 @@ describe('withSorting', () => { expect('.sorting-table').toExist(); }); }); - }); \ No newline at end of file diff --git a/src/react/table/plugins/sorting.js b/src/react/table/plugins/sorting.js index f65e96fcf..9e0e361ab 100644 --- a/src/react/table/plugins/sorting.js +++ b/src/react/table/plugins/sorting.js @@ -28,14 +28,6 @@ export function withSorting(Table) { }; } - componentWillReceiveProps({columns, defaultSort}) { - if (!columns) return; - const sortColumn = find(columns, ({sortable, attribute}) => - defaultSort ? attribute === defaultSort : sortable - ); - this.setState({sortColumn, sortOrder: SORT_ORDER.asc}); - } - updateSort(column) { const {sortColumn} = this.state; const isSortColumn = column === sortColumn;