{"size": 2282, "ext": "js", "max_stars_repo_path": "tests/unit/services/Sort.test.js", "max_stars_repo_name": "rafael-arreola/vue-ads-table-tree", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/unit/services/Sort.test.js", "max_issues_repo_name": "rafael-arreola/vue-ads-table-tree", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/unit/services/Sort.test.js", "max_forks_repo_name": "rafael-arreola/vue-ads-table-tree", "max_forks_repo_forks_event_min_datetime": "2018-10-12T20:20:14.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-12T20:20:14.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 28.8860759494, "max_line_length": 73, "alphanum_fraction": 0.4794040316}
import ColumnCollection from '../../../src/collections/ColumnCollection';
import RowCollection from '../../../src/collections/RowCollection';
import Sort from '../../../src/services/Sort';

describe('Sort service', () => {
    let columnCollection;
    let rowCollection;
    let sort;

    beforeEach(() => {
        columnCollection = new ColumnCollection([
            {
                property: 'firstName',
                sortable: true,
            },
            {
                property: 'lastName',
                sortable: true,
            },
        ]);

        sort = new Sort(columnCollection);

        rowCollection = new RowCollection([
            {
                firstName: 'Bert',
                lastName: 'Desmedt',
            },
            {
                firstName: 'Arne',
                lastName: 'De Smedt',
                children: [
                    {
                        firstName: 'Leen',
                        lastName: 'Casteleyn',
                    },
                    {
                        firstName: 'Bieke',
                        lastName: 'Delft',
                    },
                ],
            },
            {
                firstName: 'Lieve',
                lastName: 'Vandermeer',
            },
            {
                firstName: 'Bert',
                lastName: 'Vanderplatse',
            },
        ]);
    });

    it('sorts the default rowCollection', () => {
        columnCollection.first.direction = true;
        let resultCollection = sort.sort(rowCollection);

        expect(resultCollection.first.firstName).toBe('Arne');
        expect(resultCollection.last.firstName).toBe('Lieve');
    });

    it('sorts the default rowCollection by desc', () => {
        columnCollection.first.direction = false;
        let resultCollection = sort.sort(rowCollection);

        expect(resultCollection.first.firstName).toBe('Lieve');
        expect(resultCollection.last.firstName).toBe('Arne');
    });

    it('checks if it has sorted columns', () => {
        columnCollection.first.direction = true;
        expect(sort.hasSortedColumns()).toBeTruthy();
    });

    it('checks if it has no sorted columns', () => {
        expect(sort.hasSortedColumns()).toBeFalsy();
    });
});
