@@ -3,9 +3,17 @@ import {
33 TestBed ,
44 waitForAsync ,
55} from '@angular/core/testing' ;
6- import { Router } from '@angular/router' ;
6+ import {
7+ ActivatedRoute ,
8+ Router ,
9+ } from '@angular/router' ;
10+ import { TranslateService } from '@ngx-translate/core' ;
711import { of as observableOf } from 'rxjs' ;
812
13+ import {
14+ SortDirection ,
15+ SortOptions ,
16+ } from '../../core/cache/models/sort-options.model' ;
917import { ConfigurationDataService } from '../../core/data/configuration-data.service' ;
1018import { RemoteData } from '../../core/data/remote-data' ;
1119import { GroupDataService } from '../../core/eperson/group-data.service' ;
@@ -14,22 +22,24 @@ import { LinkHeadService } from '../../core/services/link-head.service';
1422import { Collection } from '../../core/shared/collection.model' ;
1523import { ConfigurationProperty } from '../../core/shared/configuration-property.model' ;
1624import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service' ;
25+ import { MockActivatedRoute } from '../mocks/active-router.mock' ;
1726import { RouterMock } from '../mocks/router.mock' ;
27+ import { getMockTranslateService } from '../mocks/translate.service.mock' ;
1828import { PaginationComponentOptions } from '../pagination/pagination-component-options.model' ;
1929import {
2030 createSuccessfulRemoteDataObject ,
2131 createSuccessfulRemoteDataObject$ ,
2232} from '../remote-data.utils' ;
2333import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model' ;
34+ import { SearchFilter } from '../search/models/search-filter.model' ;
2435import { PaginationServiceStub } from '../testing/pagination-service.stub' ;
2536import { SearchConfigurationServiceStub } from '../testing/search-configuration-service.stub' ;
2637import { createPaginatedList } from '../testing/utils.test' ;
2738import { RSSComponent } from './rss.component' ;
2839
29-
30-
3140describe ( 'RssComponent' , ( ) => {
3241 let comp : RSSComponent ;
42+ let options : SortOptions ;
3343 let fixture : ComponentFixture < RSSComponent > ;
3444 let uuid : string ;
3545 let query : string ;
@@ -69,6 +79,7 @@ describe('RssComponent', () => {
6979 pageSize : 10 ,
7080 currentPage : 1 ,
7181 } ) ,
82+ sort : new SortOptions ( 'dc.title' , SortDirection . ASC ) ,
7283 } ) ) ;
7384 groupDataService = jasmine . createSpyObj ( 'groupsDataService' , {
7485 findListByHref : createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ ] ) ) ,
@@ -80,38 +91,60 @@ describe('RssComponent', () => {
8091 paginatedSearchOptions : mockSearchOptions ,
8192 } ;
8293 TestBed . configureTestingModule ( {
83- imports : [ RSSComponent ] ,
8494 providers : [
8595 { provide : GroupDataService , useValue : groupDataService } ,
8696 { provide : LinkHeadService , useValue : linkHeadService } ,
8797 { provide : ConfigurationDataService , useValue : configurationDataService } ,
8898 { provide : SearchConfigurationService , useValue : new SearchConfigurationServiceStub ( ) } ,
8999 { provide : PaginationService , useValue : paginationService } ,
90100 { provide : Router , useValue : new RouterMock ( ) } ,
101+ { provide : ActivatedRoute , useValue : new MockActivatedRoute } ,
102+ { provide : TranslateService , useValue : getMockTranslateService ( ) } ,
91103 ] ,
104+ declarations : [ ] ,
92105 } ) . compileComponents ( ) ;
93106 } ) ) ;
94107
95108 beforeEach ( ( ) => {
109+ options = new SortOptions ( 'dc.title' , SortDirection . DESC ) ;
96110 uuid = '2cfcf65e-0a51-4bcb-8592-b8db7b064790' ;
97111 query = 'test' ;
98112 fixture = TestBed . createComponent ( RSSComponent ) ;
99113 comp = fixture . componentInstance ;
100114 } ) ;
101115
102116 it ( 'should formulate the correct url given params in url' , ( ) => {
103- const route = comp . formulateRoute ( uuid , 'opensearch/search' , query ) ;
104- expect ( route ) . toBe ( '/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&query=test' ) ;
117+ const route = comp . formulateRoute ( uuid , 'opensearch/search' , options , query ) ;
118+ expect ( route ) . toBe ( '/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC& query=test' ) ;
105119 } ) ;
106120
107121 it ( 'should skip uuid if its null' , ( ) => {
108- const route = comp . formulateRoute ( null , 'opensearch/search' , query ) ;
109- expect ( route ) . toBe ( '/opensearch/search?format=atom&query=test' ) ;
122+ const route = comp . formulateRoute ( null , 'opensearch/search' , options , query ) ;
123+ expect ( route ) . toBe ( '/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC& query=test' ) ;
110124 } ) ;
111125
112126 it ( 'should default to query * if none provided' , ( ) => {
113- const route = comp . formulateRoute ( null , 'opensearch/search' , null ) ;
114- expect ( route ) . toBe ( '/opensearch/search?format=atom&query=*' ) ;
127+ const route = comp . formulateRoute ( null , 'opensearch/search' , options , null ) ;
128+ expect ( route ) . toBe ( '/opensearch/search?format=atom&sort=dc.title&sort_direction=DESC&query=*' ) ;
129+ } ) ;
130+
131+ it ( 'should include filters in opensearch url if provided' , ( ) => {
132+ const filters = [
133+ new SearchFilter ( 'f.test' , [ 'value' , 'another value' ] , 'contains' ) , // should be split into two arguments, spaces should be URI-encoded
134+ new SearchFilter ( 'f.range' , [ '[1987 TO 1988]' ] , 'equals' ) , // value should be URI-encoded, ',equals' should not
135+ ] ;
136+ const route = comp . formulateRoute ( uuid , 'opensearch/search' , options , query , filters ) ;
137+ expect ( route ) . toBe ( '/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&f.test=value,contains&f.test=another%20value,contains&f.range=%5B1987%20TO%201988%5D,equals' ) ;
138+ } ) ;
139+
140+ it ( 'should include configuration in opensearch url if provided' , ( ) => {
141+ const route = comp . formulateRoute ( uuid , 'opensearch/search' , options , query , null , 'adminConfiguration' ) ;
142+ expect ( route ) . toBe ( '/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&configuration=adminConfiguration' ) ;
143+ } ) ;
144+
145+ it ( 'should include rpp in opensearch url if provided' , ( ) => {
146+ const route = comp . formulateRoute ( uuid , 'opensearch/search' , options , query , null , null , 50 ) ;
147+ expect ( route ) . toBe ( '/opensearch/search?format=atom&scope=2cfcf65e-0a51-4bcb-8592-b8db7b064790&sort=dc.title&sort_direction=DESC&query=test&rpp=50' ) ;
115148 } ) ;
116149} ) ;
117150
0 commit comments