|
| 1 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 2 | +import { SearchService } from 'src/app/core/shared/search/search.service'; |
| 3 | +import { createSuccessfulRemoteDataObject } from 'src/app/shared/remote-data.utils'; |
| 4 | +import { SearchServiceStub } from 'src/app/shared/testing/search-service.stub'; |
| 5 | +import { createPaginatedList } from 'src/app/shared/testing/utils.test'; |
| 6 | +import { PaginationService } from '../../core/pagination/pagination.service'; |
| 7 | +import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub'; |
| 8 | +import { RecentItemListComponent } from './recent-item-list.component'; |
| 9 | +import { SearchConfigurationService } from '../../core/shared/search/search-configuration.service'; |
| 10 | +import { PaginatedSearchOptions } from '../../shared/search/models/paginated-search-options.model'; |
| 11 | +import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; |
| 12 | +import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; |
| 13 | +import { ViewMode } from 'src/app/core/shared/view-mode.model'; |
| 14 | +import { of as observableOf } from 'rxjs'; |
| 15 | +describe('RecentItemListComponent', () => { |
| 16 | + let component: RecentItemListComponent; |
| 17 | + let fixture: ComponentFixture<RecentItemListComponent>; |
| 18 | + const emptyList = createSuccessfulRemoteDataObject(createPaginatedList([])); |
| 19 | + let paginationService; |
| 20 | + const searchServiceStub = Object.assign(new SearchServiceStub(), { |
| 21 | + search: () => observableOf(emptyList), |
| 22 | + /* eslint-disable no-empty,@typescript-eslint/no-empty-function */ |
| 23 | + clearDiscoveryRequests: () => {} |
| 24 | + /* eslint-enable no-empty,@typescript-eslint/no-empty-function */ |
| 25 | + }); |
| 26 | + paginationService = new PaginationServiceStub(); |
| 27 | + const mockSearchOptions = observableOf(new PaginatedSearchOptions({ |
| 28 | + pagination: Object.assign(new PaginationComponentOptions(), { |
| 29 | + id: 'search-page-configuration', |
| 30 | + pageSize: 10, |
| 31 | + currentPage: 1 |
| 32 | + }), |
| 33 | + sort: new SortOptions('dc.date.accessioned', SortDirection.DESC), |
| 34 | + })); |
| 35 | + const searchConfigServiceStub = { |
| 36 | + paginatedSearchOptions: mockSearchOptions |
| 37 | + }; |
| 38 | + beforeEach(async () => { |
| 39 | + await TestBed.configureTestingModule({ |
| 40 | + declarations: [ RecentItemListComponent], |
| 41 | + providers: [ |
| 42 | + { provide: SearchService, useValue: searchServiceStub }, |
| 43 | + { provide: PaginationService, useValue: paginationService }, |
| 44 | + { provide: SearchConfigurationService, useValue: searchConfigServiceStub }, |
| 45 | + ], |
| 46 | + }) |
| 47 | + .compileComponents(); |
| 48 | + }); |
| 49 | + |
| 50 | + beforeEach(() => { |
| 51 | + fixture = TestBed.createComponent(RecentItemListComponent); |
| 52 | + component = fixture.componentInstance; |
| 53 | + fixture.detectChanges(); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should create', () => { |
| 57 | + expect(component).toBeTruthy(); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should call the navigate method on the Router with view mode list parameter as a parameter when setViewMode is called', () => { |
| 61 | + component.onLoadMore(); |
| 62 | + expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith(undefined, ['search'], Object({ sortField: 'dc.date.accessioned', sortDirection: 'DESC', page: 1 })); |
| 63 | + }); |
| 64 | +}); |
| 65 | + |
| 66 | + |
0 commit comments