srumboard_frontend/src/app/services/sorting.service.spec.ts

40 lines
1.1 KiB
TypeScript

import { sortByDateAscending, sortByNumberAscending, sortByStringAscending } from './sorting.service';
describe('SortingService', () => {
it('should sort correctly by number', () => {
const items = [7, 3, 2, 6, 4, 8, 0];
sortByNumberAscending(items, x => x);
expect(items).toEqual([0, 2, 3, 4, 6, 7, 8]);
});
it('should sort strings by length correctly', () => {
const items = ['aaaaa', 'a', 'aaa'];
sortByNumberAscending(items, x => x.length);
expect(items).toEqual(['a', 'aaa', 'aaaaa']);
});
it('should sort strings alphanumerically', () => {
const items = ['biz', 'bar', 'foo'];
sortByStringAscending(items, x => x);
expect(items).toEqual(['bar', 'biz', 'foo']);
});
it('should sort dates correctly', () => {
const items = [
new Date(2020, 2, 10, 13, 30),
new Date(2020, 2, 10, 12, 30),
new Date(2019, 4, 4),
new Date(2020, 2, 11, 13, 30),
];
sortByDateAscending(items, x => x);
expect(items).toEqual([
new Date(2019, 4, 4),
new Date(2020, 2, 10, 12, 30),
new Date(2020, 2, 10, 13, 30),
new Date(2020, 2, 11, 13, 30),
]);
});
});