Commits
Tim Donohue authored and GitHub committed 749e1a7ad34 Merge
1 1 | import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; |
2 - | import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; |
3 2 | import { ConfigurationDataService } from '../../core/data/configuration-data.service'; |
4 3 | import { RemoteData } from '../../core/data/remote-data'; |
5 4 | import { GroupDataService } from '../../core/eperson/group-data.service'; |
6 5 | import { PaginationService } from '../../core/pagination/pagination.service'; |
7 6 | import { LinkHeadService } from '../../core/services/link-head.service'; |
8 7 | import { Collection } from '../../core/shared/collection.model'; |
9 8 | import { ConfigurationProperty } from '../../core/shared/configuration-property.model'; |
10 9 | import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service'; |
11 10 | import { PaginationComponentOptions } from '../pagination/pagination-component-options.model'; |
12 11 | import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../remote-data.utils'; |
16 15 | import { of as observableOf } from 'rxjs'; |
17 16 | import { SearchConfigurationServiceStub } from '../testing/search-configuration-service.stub'; |
18 17 | import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model'; |
19 18 | import { Router } from '@angular/router'; |
20 19 | import { RouterMock } from '../mocks/router.mock'; |
21 20 | |
22 21 | |
23 22 | |
24 23 | describe('RssComponent', () => { |
25 24 | let comp: RSSComponent; |
26 - | let options: SortOptions; |
27 25 | let fixture: ComponentFixture<RSSComponent>; |
28 26 | let uuid: string; |
29 27 | let query: string; |
30 28 | let groupDataService: GroupDataService; |
31 29 | let linkHeadService: LinkHeadService; |
32 30 | let configurationDataService: ConfigurationDataService; |
33 31 | let paginationService; |
34 32 | |
35 33 | beforeEach(waitForAsync(() => { |
36 34 | const mockCollection: Collection = Object.assign(new Collection(), { |
56 54 | linkHeadService = jasmine.createSpyObj('linkHeadService', { |
57 55 | addTag: '' |
58 56 | }); |
59 57 | const mockCollectionRD: RemoteData<Collection> = createSuccessfulRemoteDataObject(mockCollection); |
60 58 | const mockSearchOptions = observableOf(new PaginatedSearchOptions({ |
61 59 | pagination: Object.assign(new PaginationComponentOptions(), { |
62 60 | id: 'search-page-configuration', |
63 61 | pageSize: 10, |
64 62 | currentPage: 1 |
65 63 | }), |
66 - | sort: new SortOptions('dc.title', SortDirection.ASC), |
67 64 | })); |
68 65 | groupDataService = jasmine.createSpyObj('groupsDataService', { |
69 66 | findListByHref: createSuccessfulRemoteDataObject$(createPaginatedList([])), |
70 67 | getGroupRegistryRouterLink: '', |
71 68 | getUUIDFromString: '', |
72 69 | }); |
73 70 | paginationService = new PaginationServiceStub(); |
74 71 | const searchConfigService = { |
75 72 | paginatedSearchOptions: mockSearchOptions |
76 73 | }; |
81 78 | { provide: ConfigurationDataService, useValue: configurationDataService }, |
82 79 | { provide: SearchConfigurationService, useValue: new SearchConfigurationServiceStub() }, |
83 80 | { provide: PaginationService, useValue: paginationService }, |
84 81 | { provide: Router, useValue: new RouterMock() } |
85 82 | ], |
86 83 | declarations: [RSSComponent] |
87 84 | }).compileComponents(); |
88 85 | })); |
89 86 | |
90 87 | beforeEach(() => { |
91 - | options = new SortOptions('dc.title', SortDirection.DESC); |
92 88 | uuid = '2cfcf65e-0a51-4bcb-8592-b8db7b064790'; |
93 89 | query = 'test'; |
94 90 | fixture = TestBed.createComponent(RSSComponent); |
95 91 | comp = fixture.componentInstance; |
96 92 | }); |
97 93 | |
98 94 | it('should formulate the correct url given params in url', () => { |
99 - | const route = comp.formulateRoute(uuid, 'opensearch', options, query); |
100 - | expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test'); |
95 + | const route = comp.formulateRoute(uuid, 'opensearch/search', query); |
96 + | expect(route).toBe('/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&query=test'); |
101 97 | }); |
102 98 | |
103 99 | it('should skip uuid if its null', () => { |
104 - | const route = comp.formulateRoute(null, 'opensearch', options, query); |
105 - | expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=test'); |
100 + | const route = comp.formulateRoute(null, 'opensearch/search', query); |
101 + | expect(route).toBe('/opensearch/search?format=atom&query=test'); |
106 102 | }); |
107 103 | |
108 104 | it('should default to query * if none provided', () => { |
109 - | const route = comp.formulateRoute(null, 'opensearch', options, null); |
110 - | expect(route).toBe('/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=*'); |
105 + | const route = comp.formulateRoute(null, 'opensearch/search', null); |
106 + | expect(route).toBe('/opensearch/search?format=atom&query=*'); |
111 107 | }); |
112 108 | }); |
113 109 | |