mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 05:53:03 +00:00
fix: add unit test for rename property case
This commit is contained in:
42
src/app/core/cache/builders/link.service.spec.ts
vendored
42
src/app/core/cache/builders/link.service.spec.ts
vendored
@@ -31,10 +31,12 @@ class TestModel implements HALResource {
|
|||||||
self: HALLink;
|
self: HALLink;
|
||||||
predecessor: HALLink;
|
predecessor: HALLink;
|
||||||
successor: HALLink;
|
successor: HALLink;
|
||||||
|
standardLinkName: HALLink;
|
||||||
};
|
};
|
||||||
|
|
||||||
predecessor?: TestModel;
|
predecessor?: TestModel;
|
||||||
successor?: TestModel;
|
successor?: TestModel;
|
||||||
|
renamedProperty?: TestModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mockDataServiceMap: any = new Map([
|
const mockDataServiceMap: any = new Map([
|
||||||
@@ -66,6 +68,24 @@ describe('LinkService', () => {
|
|||||||
testDataService = new TestDataService();
|
testDataService = new TestDataService();
|
||||||
spyOn(testDataService, 'findListByHref').and.callThrough();
|
spyOn(testDataService, 'findListByHref').and.callThrough();
|
||||||
spyOn(testDataService, 'findByHref').and.callThrough();
|
spyOn(testDataService, 'findByHref').and.callThrough();
|
||||||
|
|
||||||
|
const linksDefinitions = new Map();
|
||||||
|
linksDefinitions.set('predecessor', {
|
||||||
|
resourceType: TEST_MODEL,
|
||||||
|
linkName: 'predecessor',
|
||||||
|
propertyName: 'predecessor',
|
||||||
|
});
|
||||||
|
linksDefinitions.set('successor', {
|
||||||
|
resourceType: TEST_MODEL,
|
||||||
|
linkName: 'successor',
|
||||||
|
propertyName: 'successor',
|
||||||
|
});
|
||||||
|
linksDefinitions.set('standardLinkName', {
|
||||||
|
resourceType: TEST_MODEL,
|
||||||
|
linkName: 'standardLinkName',
|
||||||
|
propertyName: 'renamedProperty',
|
||||||
|
});
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
LinkService,
|
LinkService,
|
||||||
@@ -87,18 +107,7 @@ describe('LinkService', () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: LINK_DEFINITION_MAP_FACTORY,
|
provide: LINK_DEFINITION_MAP_FACTORY,
|
||||||
useValue: jasmine.createSpy('getLinkDefinitions').and.returnValue([
|
useValue: jasmine.createSpy('getLinkDefinitions').and.returnValue(linksDefinitions),
|
||||||
{
|
|
||||||
resourceType: TEST_MODEL,
|
|
||||||
linkName: 'predecessor',
|
|
||||||
propertyName: 'predecessor',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
resourceType: TEST_MODEL,
|
|
||||||
linkName: 'successor',
|
|
||||||
propertyName: 'successor',
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@@ -117,6 +126,15 @@ describe('LinkService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe(`when the propertyName is different than linkName`, () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
result = service.resolveLink(testModel, followLink('standardLinkName', {}));
|
||||||
|
});
|
||||||
|
it('link should be assign to custom property', () => {
|
||||||
|
expect(result.renamedProperty).toBeDefined();
|
||||||
|
expect(result.standardLinkName).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
describe(`when the linkdefinition concerns a list`, () => {
|
describe(`when the linkdefinition concerns a list`, () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
((service as any).getLinkDefinition as jasmine.Spy).and.returnValue({
|
((service as any).getLinkDefinition as jasmine.Spy).and.returnValue({
|
||||||
|
Reference in New Issue
Block a user