Add tests and fix tests

This commit is contained in:
Yana De Pauw
2021-03-04 17:10:01 +01:00
parent d07f44ac41
commit b18f9c7c9f
47 changed files with 937 additions and 454 deletions

View File

@@ -11,11 +11,18 @@ import { VersionHistoryDataService } from '../../../core/data/version-history-da
import { By } from '@angular/platform-browser';
import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils';
import { createPaginatedList } from '../../testing/utils.test';
import { PaginationComponentOptions } from '../../pagination/pagination-component-options.model';
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
import { of as observableOf } from 'rxjs';
import { PaginationService } from '../../../core/pagination/pagination.service';
describe('ItemVersionsComponent', () => {
let component: ItemVersionsComponent;
let fixture: ComponentFixture<ItemVersionsComponent>;
const pagination = Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 });
const sort = new SortOptions('score', SortDirection.DESC);
const versionHistory = Object.assign(new VersionHistory(), {
id: '1'
});
@@ -52,12 +59,19 @@ describe('ItemVersionsComponent', () => {
getVersions: createSuccessfulRemoteDataObject$(createPaginatedList(versions))
});
const paginationService = jasmine.createSpyObj('PaginationService', {
getCurrentPagination: observableOf(pagination),
getCurrentSort: observableOf(sort),
getRouteParameterValue: observableOf('')
});
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ItemVersionsComponent, VarDirective],
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
providers: [
{ provide: VersionHistoryDataService, useValue: versionHistoryService }
{ provide: VersionHistoryDataService, useValue: versionHistoryService },
{ provide: PaginationService, useValue: paginationService }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
@@ -107,16 +121,4 @@ describe('ItemVersionsComponent', () => {
expect(summary.nativeElement.textContent).toEqual(version.summary);
});
});
describe('switchPage', () => {
const page = 5;
beforeEach(() => {
component.switchPage(page);
});
it('should set the option\'s currentPage to the new page', () => {
expect(component.options.currentPage).toEqual(page);
});
});
});