import { changeVisibleColumns } from './basicTableViewState';
describe('basicTableViewState tests', function () {
    describe('changeVisibleColumns behavior', function () {
        it('should set new visible columns value', function () {
            var prevState = {
                visibleColumns: []
            };
            var visibleColumns = ['column1', 'column2'];
            var nextState = {
                visibleColumns: visibleColumns
            };
            expect(changeVisibleColumns(prevState, visibleColumns)).toEqual(nextState);
        });
        it('should update columns size on changing visible columns', function () {
            var prevState = {
                visibleColumns: ['column1', 'column2', 'column3', 'column4'],
                columnsSize: [
                    { id: 'column1', size: 100, manuallyChanged: true },
                    { id: 'column2', size: 200 },
                    { id: 'column3', size: 300, manuallyChanged: true },
                    { id: 'column4', size: 400 }
                ]
            };
            var visibleColumns = ['column1', 'column4'];
            var nextState = {
                visibleColumns: visibleColumns,
                columnsSize: [
                    { id: 'column1', size: 100, manuallyChanged: true },
                    { id: 'column4', size: 0 }
                ]
            };
            expect(changeVisibleColumns(prevState, visibleColumns)).toEqual(nextState);
        });
        it('should remove filters for columns that are no longer visible', function () {
            var prevState = {
                visibleColumns: ['column1', 'column2'],
                filters: {
                    column1: {
                        filter: 'exists'
                    },
                    column2: {
                        filter: 'equals',
                        value: '123'
                    }
                }
            };
            var visibleColumns = ['column1', 'column3'];
            var nextState = {
                visibleColumns: visibleColumns,
                filters: {
                    column1: {
                        filter: 'exists'
                    }
                }
            };
            expect(changeVisibleColumns(prevState, visibleColumns)).toEqual(nextState);
        });
        it('should not modify filters if they do not have columns that are no longer visible', function () {
            var prevState = {
                visibleColumns: ['column1', 'column2'],
                filters: {
                    column1: {
                        filter: 'exists'
                    }
                }
            };
            var visibleColumns = ['column1', 'column3'];
            var nextState = {
                visibleColumns: visibleColumns,
                filters: prevState.filters
            };
            expect(changeVisibleColumns(prevState, visibleColumns)).toEqual(nextState);
        });
        it('should change sorting for columns that are no longer visible', function () {
            var prevState = {
                visibleColumns: ['column1', 'column2'],
                sorting: {
                    field: 'column2',
                    order: 'desc'
                }
            };
            var visibleColumns = ['column1', 'column3'];
            var nextState = {
                visibleColumns: visibleColumns,
                sorting: {
                    field: 'column1',
                    order: 'asc'
                }
            };
            expect(changeVisibleColumns(prevState, visibleColumns)).toEqual(nextState);
        });
    });
});
