Commits
Tim Donohue authored f3e4fb99014
5 5 | import { SortDirection, SortOptions } from '../cache/models/sort-options.model'; |
6 6 | import { FindListOptions } from '../data/find-list-options.model'; |
7 7 | |
8 8 | |
9 9 | describe('PaginationService', () => { |
10 10 | let service: PaginationService; |
11 11 | let router; |
12 12 | let routeService; |
13 13 | |
14 14 | const defaultPagination = new PaginationComponentOptions(); |
15 - | const defaultSort = new SortOptions('id', SortDirection.DESC); |
15 + | const defaultSort = new SortOptions('dc.title', SortDirection.ASC); |
16 16 | const defaultFindListOptions = new FindListOptions(); |
17 17 | |
18 18 | beforeEach(() => { |
19 19 | router = new RouterStub(); |
20 20 | routeService = { |
21 21 | getQueryParameterValue: (param) => { |
22 22 | let value; |
23 23 | if (param.endsWith('.page')) { |
24 24 | value = 5; |
25 25 | } |
32 32 | if (param.endsWith('.sf')) { |
33 33 | value = 'score'; |
34 34 | } |
35 35 | return observableOf(value); |
36 36 | } |
37 37 | }; |
38 38 | |
39 39 | service = new PaginationService(routeService, router); |
40 40 | }); |
41 41 | |
42 - | |
43 42 | describe('getCurrentPagination', () => { |
44 43 | it('should retrieve the current pagination info from the routerService', () => { |
45 44 | service.getCurrentPagination('test-id', defaultPagination).subscribe((currentPagination) => { |
46 45 | expect(currentPagination).toEqual(Object.assign(new PaginationComponentOptions(), { |
47 46 | currentPage: 5, |
48 47 | pageSize: 10 |
49 48 | })); |
50 49 | }); |
51 50 | }); |
52 51 | }); |
53 52 | describe('getCurrentSort', () => { |
54 53 | it('should retrieve the current sort info from the routerService', () => { |
55 54 | service.getCurrentSort('test-id', defaultSort).subscribe((currentSort) => { |
56 55 | expect(currentSort).toEqual(Object.assign(new SortOptions('score', SortDirection.ASC ))); |
57 56 | }); |
58 57 | }); |
58 + | it('should return default sort when no sort specified', () => { |
59 + | // This is same as routeService (defined above), but returns no sort field or direction |
60 + | routeService = { |
61 + | getQueryParameterValue: (param) => { |
62 + | let value; |
63 + | if (param.endsWith('.page')) { |
64 + | value = 5; |
65 + | } |
66 + | if (param.endsWith('.rpp')) { |
67 + | value = 10; |
68 + | } |
69 + | return observableOf(value); |
70 + | } |
71 + | }; |
72 + | service = new PaginationService(routeService, router); |
73 + | |
74 + | service.getCurrentSort('test-id', defaultSort).subscribe((currentSort) => { |
75 + | expect(currentSort).toEqual(defaultSort); |
76 + | }); |
77 + | }); |
59 78 | }); |
60 79 | describe('getFindListOptions', () => { |
61 80 | it('should retrieve the current findListOptions info from the routerService', () => { |
62 81 | service.getFindListOptions('test-id', defaultFindListOptions).subscribe((findListOptions) => { |
63 82 | expect(findListOptions).toEqual(Object.assign(new FindListOptions(), |
64 83 | { |
65 84 | sort: new SortOptions('score', SortDirection.ASC ), |
66 85 | currentPage: 5, |
67 86 | elementsPerPage: 10 |
68 87 | })); |