feat: display availability and item data for library items

This commit is contained in:
Jovan Krunić
2022-09-08 13:02:19 +00:00
committed by Thea Schöbl
parent 605aa1b782
commit d571b1dbe5
25 changed files with 695 additions and 145 deletions

View File

@@ -0,0 +1,235 @@
/*
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* eslint-disable @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-explicit-any, unicorn/no-thenable */
import {TestBed} from '@angular/core/testing';
import {DaiaDataProvider} from './daia-data.provider';
import {HebisModule} from './hebis.module';
import {ConfigProvider} from '../config/config.provider';
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
import {StorageProvider} from '../storage/storage.provider';
import {LoggerConfig, LoggerModule, NGXLogger} from 'ngx-logger';
import {MapModule} from '../map/map.module';
import {HttpClientModule} from '@angular/common/http';
import {StorageModule} from '../storage/storage.module';
import {SCDaiaHolding, SCDaiaService} from './protocol/response';
import {Observable, of} from 'rxjs';
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
const translations: any = {data: {detail: {TITLE: 'Foo'}}};
class TranslateFakeLoader implements TranslateLoader {
getTranslation(_lang: string): Observable<any> {
return of(translations);
}
}
describe('DaiaDataProvider', () => {
let daiaDataProvider: DaiaDataProvider;
let configProvider: ConfigProvider;
const proxyUrl = 'https://some-proxy.com?q=';
beforeEach(async () => {
configProvider = jasmine.createSpyObj('ConfigProvider', ['getValue']);
TestBed.configureTestingModule({
imports: [
HebisModule,
MapModule,
HttpClientModule,
StorageModule,
LoggerModule,
TranslateModule.forRoot({
loader: {provide: TranslateLoader, useClass: TranslateFakeLoader},
}),
],
providers: [
{
provide: ConfigProvider,
useValue: configProvider,
},
StAppsWebHttpClient,
StorageProvider,
NGXLogger,
LoggerConfig,
DaiaDataProvider,
],
});
daiaDataProvider = TestBed.inject(DaiaDataProvider);
daiaDataProvider.hebisProxyUrl = proxyUrl;
});
describe('getResourceLink', () => {
it('should return undefined when available not defined', () => {
const holding: SCDaiaHolding = {
id: '',
label: '',
online: false,
signature: '',
};
expect(daiaDataProvider.getHoldingLink(holding)).toEqual(undefined);
});
it('should return the resource link without proxy when service is openaccess', () => {
const available: SCDaiaService = {
delay: '',
expected: '',
href: 'https://some-url.com',
limitations: [],
service: 'openaccess',
};
const holding: SCDaiaHolding = {
id: '',
label: '',
online: false,
signature: '',
available: available,
};
expect(daiaDataProvider.getHoldingLink(holding)).toEqual(available.href);
});
it('should return the resource link with proxy when service is not openaccess', () => {
const available: SCDaiaService = {
delay: '',
expected: '',
href: 'https://some-url.com',
limitations: [],
service: 'other',
};
const holding: SCDaiaHolding = {
id: '',
label: '',
online: false,
signature: '',
available: available,
};
expect(daiaDataProvider.getHoldingLink(holding)).toEqual(
`${proxyUrl}${available.href}`,
);
});
});
describe('getResourceStatus', () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// let available, unavalable: SCDaiaService[];
const checkedOut: SCDaiaService = {
expected: '2022-09-01',
limitations: [],
service: 'loan',
};
const notYetAvailableOnBuy: SCDaiaService = {
limitations: [{id: 'OnBuy', content: ''}],
service: 'loan',
};
const notYetAvailableJustReturned: SCDaiaService = {
limitations: [{id: 'JustReturned', content: ''}],
service: 'loan',
};
const notAvailableCopyIsMissing: SCDaiaService = {
limitations: [{id: 'CopyIsMissing', content: ''}],
service: 'loan',
};
const notAvailableCanceled: SCDaiaService = {
limitations: [{id: 'Canceled', content: ''}],
service: 'loan',
};
const libraryOnlyOnlyInHouse: SCDaiaService = {
limitations: [{id: 'OnlyInHouse', content: ''}],
service: 'loan',
};
const libraryOnlyExternalLoan: SCDaiaService = {
limitations: [{id: 'ExternalLoan', content: ''}],
service: 'loan',
};
const libraryOnlyNoLimitations: SCDaiaService = {
service: 'loan',
};
const availableLimitationsUndefined: SCDaiaService = {
service: 'loan',
};
const availableLimitationsEmpty: SCDaiaService = {
limitations: [],
service: 'loan',
};
it('should return check out', () => {
expect(daiaDataProvider.getHoldingStatus([], [checkedOut])).toEqual(
'checked_out',
);
});
it('should return not yet available', () => {
expect(
daiaDataProvider.getHoldingStatus([], [notYetAvailableOnBuy]),
).toEqual('not_yet_available');
expect(
daiaDataProvider.getHoldingStatus([], [notYetAvailableJustReturned]),
).toEqual('not_yet_available');
});
it('should return not available', () => {
expect(
daiaDataProvider.getHoldingStatus([], [notAvailableCopyIsMissing]),
).toEqual('not_available');
expect(
daiaDataProvider.getHoldingStatus([], [notAvailableCanceled]),
).toEqual('not_available');
});
it('should return library only', () => {
expect(
daiaDataProvider.getHoldingStatus([], [libraryOnlyOnlyInHouse]),
).toEqual('library_only');
expect(
daiaDataProvider.getHoldingStatus([libraryOnlyExternalLoan], []),
).toEqual('library_only');
expect(
daiaDataProvider.getHoldingStatus([], [libraryOnlyNoLimitations]),
).toEqual('library_only');
});
it('should return available', () => {
expect(
daiaDataProvider.getHoldingStatus([availableLimitationsUndefined], []),
).toEqual('available');
expect(
daiaDataProvider.getHoldingStatus([availableLimitationsEmpty], []),
).toEqual('available');
});
it('should return unknown otherwise', () => {
const withoutLoan: SCDaiaService = {
limitations: [],
service: 'anything else',
};
expect(daiaDataProvider.getHoldingStatus([withoutLoan], [])).toEqual(
'unknown',
);
expect(daiaDataProvider.getHoldingStatus([], [withoutLoan])).toEqual(
'unknown',
);
});
});
});