mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
83631: Reword & explain theme extension tests
This commit is contained in:
@@ -16,8 +16,8 @@ describe('MetadataRepresentation decorator function', () => {
|
|||||||
const type2 = 'TestType2';
|
const type2 = 'TestType2';
|
||||||
const type3 = 'TestType3';
|
const type3 = 'TestType3';
|
||||||
const type4 = 'RandomType';
|
const type4 = 'RandomType';
|
||||||
const typeHier1 = 'TestTypeHier1';
|
const typeAncestor = 'TestTypeAncestor';
|
||||||
const typeHier2 = 'TestTypeHier2';
|
const typeUnthemed = 'TestTypeUnthemed';
|
||||||
let prefix;
|
let prefix;
|
||||||
|
|
||||||
/* tslint:disable:max-classes-per-file */
|
/* tslint:disable:max-classes-per-file */
|
||||||
@@ -36,10 +36,10 @@ describe('MetadataRepresentation decorator function', () => {
|
|||||||
class Test3ItemSubmission {
|
class Test3ItemSubmission {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestHier1Ancestor {
|
class TestAncestorComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestHier2Unthemed {
|
class TestUnthemedComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tslint:enable:max-classes-per-file */
|
/* tslint:enable:max-classes-per-file */
|
||||||
@@ -58,8 +58,9 @@ describe('MetadataRepresentation decorator function', () => {
|
|||||||
|
|
||||||
metadataRepresentationComponent(key + type3, MetadataRepresentationType.Item, Context.Workspace)(Test3ItemSubmission);
|
metadataRepresentationComponent(key + type3, MetadataRepresentationType.Item, Context.Workspace)(Test3ItemSubmission);
|
||||||
|
|
||||||
metadataRepresentationComponent(key + typeHier1, MetadataRepresentationType.Item, Context.Any, 'ancestor')(TestHier1Ancestor);
|
// Register a metadata representation in the 'ancestor' theme
|
||||||
metadataRepresentationComponent(key + typeHier2, MetadataRepresentationType.Item, Context.Any)(TestHier2Unthemed);
|
metadataRepresentationComponent(key + typeAncestor, MetadataRepresentationType.Item, Context.Any, 'ancestor')(TestAncestorComponent);
|
||||||
|
metadataRepresentationComponent(key + typeUnthemed, MetadataRepresentationType.Item, Context.Any)(TestUnthemedComponent);
|
||||||
|
|
||||||
ogEnvironmentThemes = environment.themes;
|
ogEnvironmentThemes = environment.themes;
|
||||||
}
|
}
|
||||||
@@ -98,22 +99,33 @@ describe('MetadataRepresentation decorator function', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('With theme extensions', () => {
|
describe('With theme extensions', () => {
|
||||||
|
// We're only interested in the cases that the requested theme doesn't match the requested entityType,
|
||||||
|
// as the cases where it does are already covered by the tests above
|
||||||
describe('If requested theme has no match', () => {
|
describe('If requested theme has no match', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
environment.themes = [
|
environment.themes = [
|
||||||
{ name: 'requested', extends: 'intermediate' },
|
{
|
||||||
{ name: 'intermediate', extends: 'ancestor' },
|
name: 'requested', // Doesn't match any entityType
|
||||||
|
extends: 'intermediate',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'intermediate', // Doesn't match any entityType
|
||||||
|
extends: 'ancestor',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ancestor', // Matches typeAncestor, but not typeUnthemed
|
||||||
|
}
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return component from ancestor theme if it has a match', () => {
|
it('should return component from the first ancestor theme that matches its entityType', () => {
|
||||||
const component = getMetadataRepresentationComponent(prefix + typeHier1, MetadataRepresentationType.Item, Context.Any, 'requested');
|
const component = getMetadataRepresentationComponent(prefix + typeAncestor, MetadataRepresentationType.Item, Context.Any, 'requested');
|
||||||
expect(component).toEqual(TestHier1Ancestor);
|
expect(component).toEqual(TestAncestorComponent);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return default component if ancestor theme has no match', () => {
|
it('should return default component if none of the ancestor themes match its entityType', () => {
|
||||||
const component = getMetadataRepresentationComponent(prefix + typeHier2, MetadataRepresentationType.Item, Context.Any, 'requested');
|
const component = getMetadataRepresentationComponent(prefix + typeUnthemed, MetadataRepresentationType.Item, Context.Any, 'requested');
|
||||||
expect(component).toEqual(TestHier2Unthemed);
|
expect(component).toEqual(TestUnthemedComponent);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -129,7 +141,7 @@ describe('MetadataRepresentation decorator function', () => {
|
|||||||
|
|
||||||
it('should throw an error', () => {
|
it('should throw an error', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
getMetadataRepresentationComponent(prefix + typeHier1, MetadataRepresentationType.Item, Context.Any, 'extension-cycle');
|
getMetadataRepresentationComponent(prefix + typeAncestor, MetadataRepresentationType.Item, Context.Any, 'extension-cycle');
|
||||||
}).toThrowError(
|
}).toThrowError(
|
||||||
'Theme extension cycle detected: extension-cycle -> broken1 -> broken2 -> broken3 -> broken1'
|
'Theme extension cycle detected: extension-cycle -> broken1 -> broken2 -> broken3 -> broken1'
|
||||||
);
|
);
|
||||||
|
@@ -10,8 +10,8 @@ describe('ListableObject decorator function', () => {
|
|||||||
const type1 = 'TestType';
|
const type1 = 'TestType';
|
||||||
const type2 = 'TestType2';
|
const type2 = 'TestType2';
|
||||||
const type3 = 'TestType3';
|
const type3 = 'TestType3';
|
||||||
const typeHier1 = 'TestTypeHier1';
|
const typeAncestor = 'TestTypeAncestor';
|
||||||
const typeHier2 = 'TestTypeHier2';
|
const typeUnthemed = 'TestTypeUnthemed';
|
||||||
|
|
||||||
/* tslint:disable:max-classes-per-file */
|
/* tslint:disable:max-classes-per-file */
|
||||||
class Test1List {
|
class Test1List {
|
||||||
@@ -32,10 +32,10 @@ describe('ListableObject decorator function', () => {
|
|||||||
class Test3DetailedSubmission {
|
class Test3DetailedSubmission {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestHier1Ancestor {
|
class TestAncestorComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestHier2Unthemed {
|
class TestUnthemedComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tslint:enable:max-classes-per-file */
|
/* tslint:enable:max-classes-per-file */
|
||||||
@@ -50,8 +50,9 @@ describe('ListableObject decorator function', () => {
|
|||||||
listableObjectComponent(type3, ViewMode.ListElement)(Test3List);
|
listableObjectComponent(type3, ViewMode.ListElement)(Test3List);
|
||||||
listableObjectComponent(type3, ViewMode.DetailedListElement, Context.Workspace)(Test3DetailedSubmission);
|
listableObjectComponent(type3, ViewMode.DetailedListElement, Context.Workspace)(Test3DetailedSubmission);
|
||||||
|
|
||||||
listableObjectComponent(typeHier1, ViewMode.ListElement, Context.Any, 'ancestor')(TestHier1Ancestor);
|
// Register a metadata representation in the 'ancestor' theme
|
||||||
listableObjectComponent(typeHier2, ViewMode.ListElement, Context.Any)(TestHier2Unthemed);
|
listableObjectComponent(typeAncestor, ViewMode.ListElement, Context.Any, 'ancestor')(TestAncestorComponent);
|
||||||
|
listableObjectComponent(typeUnthemed, ViewMode.ListElement, Context.Any)(TestUnthemedComponent);
|
||||||
|
|
||||||
ogEnvironmentThemes = environment.themes;
|
ogEnvironmentThemes = environment.themes;
|
||||||
});
|
});
|
||||||
@@ -102,22 +103,33 @@ describe('ListableObject decorator function', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('With theme extensions', () => {
|
describe('With theme extensions', () => {
|
||||||
|
// We're only interested in the cases that the requested theme doesn't match the requested objectType,
|
||||||
|
// as the cases where it does are already covered by the tests above
|
||||||
describe('If requested theme has no match', () => {
|
describe('If requested theme has no match', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
environment.themes = [
|
environment.themes = [
|
||||||
{ name: 'requested', extends: 'intermediate' },
|
{
|
||||||
{ name: 'intermediate', extends: 'ancestor' },
|
name: 'requested', // Doesn't match any objectType
|
||||||
|
extends: 'intermediate',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'intermediate', // Doesn't match any objectType
|
||||||
|
extends: 'ancestor',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ancestor', // Matches typeAncestor, but not typeUnthemed
|
||||||
|
}
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return component from ancestor theme if it has a match', () => {
|
it('should return component from the first ancestor theme that matches its objectType', () => {
|
||||||
const component = getListableObjectComponent([typeHier1], ViewMode.ListElement, Context.Any, 'requested');
|
const component = getListableObjectComponent([typeAncestor], ViewMode.ListElement, Context.Any, 'requested');
|
||||||
expect(component).toEqual(TestHier1Ancestor);
|
expect(component).toEqual(TestAncestorComponent);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return default component if ancestor theme has no match', () => {
|
it('should return default component if none of the ancestor themes match its objectType', () => {
|
||||||
const component = getListableObjectComponent([typeHier2], ViewMode.ListElement, Context.Any, 'requested');
|
const component = getListableObjectComponent([typeUnthemed], ViewMode.ListElement, Context.Any, 'requested');
|
||||||
expect(component).toEqual(TestHier2Unthemed);
|
expect(component).toEqual(TestUnthemedComponent);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -133,7 +145,7 @@ describe('ListableObject decorator function', () => {
|
|||||||
|
|
||||||
it('should throw an error', () => {
|
it('should throw an error', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
getListableObjectComponent([typeHier1], ViewMode.ListElement, Context.Any, 'extension-cycle');
|
getListableObjectComponent([typeAncestor], ViewMode.ListElement, Context.Any, 'extension-cycle');
|
||||||
}).toThrowError(
|
}).toThrowError(
|
||||||
'Theme extension cycle detected: extension-cycle -> broken1 -> broken2 -> broken3 -> broken1'
|
'Theme extension cycle detected: extension-cycle -> broken1 -> broken2 -> broken3 -> broken1'
|
||||||
);
|
);
|
||||||
|
@@ -265,6 +265,19 @@ export const environment: GlobalConfig = {
|
|||||||
// uuid: '0958c910-2037-42a9-81c7-dca80e3892b4'
|
// uuid: '0958c910-2037-42a9-81c7-dca80e3892b4'
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
|
// // The extends property specifies an ancestor theme (by name). Whenever a themed component is not found
|
||||||
|
// // in the current theme, its ancestor theme(s) will be checked recursively before falling back to default.
|
||||||
|
// name: 'custom-A',
|
||||||
|
// extends: 'custom-B',
|
||||||
|
// // Any of the matching properties above can be used
|
||||||
|
// handle: '10673/34',
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// name: 'custom-B',
|
||||||
|
// extends: 'custom',
|
||||||
|
// handle: '10673/12',
|
||||||
|
// },
|
||||||
|
// {
|
||||||
// // A theme with only a name will match every route
|
// // A theme with only a name will match every route
|
||||||
// name: 'custom'
|
// name: 'custom'
|
||||||
// },
|
// },
|
||||||
|
Reference in New Issue
Block a user