92 lines
5.1 KiB
TypeScript
92 lines
5.1 KiB
TypeScript
import {
|
|
buildCurrentNavigationItems, getLocalProperty, normalizeRootWebPath, parseBoolean, resolveTermUrl,
|
|
selectCurrentNavigationRoot
|
|
} from '../src/services/CurrentNavigationCore';
|
|
import { ICurrentNavigationTerm } from '../src/services/CurrentNavigationTypes';
|
|
import { isInitiallyExpanded } from '../src/extensions/currentNavigation/CurrentNavigationRenderer';
|
|
|
|
let passed: number = 0;
|
|
function assert(name: string, condition: boolean): void {
|
|
if (!condition) { throw new Error('FAILED: ' + name); }
|
|
passed++; console.log('OK:', name);
|
|
}
|
|
function term(value: any): ICurrentNavigationTerm { return value as ICurrentNavigationTerm; } // tslint:disable-line:no-any
|
|
|
|
const terms: ICurrentNavigationTerm[] = [
|
|
term({ Id: 'root', Name: 'HR', PathOfTerm: 'HR', LocalCustomProperties: {
|
|
'CurrentNavigation.Root': 'true', '_Sys_Nav_SimpleLinkUrl': '/sites/portal/hr/SitePages/Home.aspx'
|
|
}}),
|
|
term({ Id: 'docs', Name: 'Dokumente', PathOfTerm: 'HR;Dokumente', LocalCustomProperties: {
|
|
'_Sys_Nav_SimpleLinkUrl': '/sites/portal/hr/Dokumente'
|
|
}}),
|
|
term({ Id: 'admin', Name: 'Administration', PathOfTerm: 'HR;Administration', LocalCustomProperties: {
|
|
'CurrentNavigation.Hidden': 'true'
|
|
}}),
|
|
term({ Id: 'secret', Name: 'Intern', PathOfTerm: 'HR;Administration;Intern', LocalCustomProperties: {} }),
|
|
term({ Id: 'forms', Name: 'Formulare', PathOfTerm: 'HR;Dokumente;Formulare', LocalCustomProperties: {} })
|
|
];
|
|
|
|
assert('German boolean is accepted', parseBoolean('ja'));
|
|
assert('local property is read', getLocalProperty(terms[0], 'CurrentNavigation.Root') === 'true');
|
|
assert('expanded opens every branch', isInitiallyExpanded('expanded', false));
|
|
assert('collapsed closes even the active branch', !isInitiallyExpanded('collapsed', true));
|
|
assert('activePath keeps the previous active branch behavior', isInitiallyExpanded('activePath', true));
|
|
assert('activePath keeps inactive branches closed', !isInitiallyExpanded('activePath', false));
|
|
assert('site collection token resolves', resolveTermUrl(term({
|
|
LocalCustomProperties: { '_Sys_Nav_SimpleLinkUrl': '~sitecollection/start' }
|
|
}), 'https://portal/sites/a') === 'https://portal/sites/a/start');
|
|
const root: ICurrentNavigationTerm = selectCurrentNavigationRoot(
|
|
terms, 'https://portal/sites/portal/hr', 'https://portal/sites/portal'
|
|
);
|
|
assert('root is selected through its site home URL', !!root && root.Id === 'root');
|
|
assert('site home URL is normalized to its web',
|
|
normalizeRootWebPath('/sites/portal/hr/SitePages/Home.aspx') === '/sites/portal/hr');
|
|
const items = buildCurrentNavigationItems(terms, root, 'https://portal/sites/portal', 1031, 3, false);
|
|
assert('root is not rendered by default', items.length === 1 && items[0].id === 'docs');
|
|
assert('descendants are nested', items[0].items.length === 1 && items[0].items[0].id === 'forms');
|
|
assert('hidden branch is removed', items.every(item => item.id !== 'admin'));
|
|
const withRoot = buildCurrentNavigationItems(terms, root, 'https://portal/sites/portal', 1031, 3, true);
|
|
assert('root can be rendered', withRoot.length === 1 && withRoot[0].id === 'root');
|
|
const unordered = buildCurrentNavigationItems(
|
|
[terms[4], terms[1], terms[0]], root, 'https://portal/sites/portal', 1031, 3, false
|
|
);
|
|
assert('hierarchy is independent of taxonomy response order',
|
|
unordered.length === 1 && unordered[0].id === 'docs' && unordered[0].items[0].id === 'forms');
|
|
|
|
const inheritedTerms: ICurrentNavigationTerm[] = [
|
|
term({ Id: 'kits', Name: 'KITS', PathOfTerm: 'Organisation;CIR;KITS', LocalCustomProperties: {
|
|
'CurrentNavigation.Root': 'true',
|
|
'_Sys_Nav_SimpleLinkUrl': 'http://dhs.contoso.local/organisation/cir/CIR_3/'
|
|
}}),
|
|
term({ Id: 'team', Name: 'Team SharePoint', PathOfTerm: 'Organisation;CIR;KITS;Team SharePoint',
|
|
LocalCustomProperties: {
|
|
'TopNavigation.Hidden': 'true',
|
|
'_Sys_Nav_SimpleLinkUrl': 'http://dhs.contoso.local/organisation/cir/CIR_13/'
|
|
}}),
|
|
term({ Id: 'games', Name: 'Spielewiese', PathOfTerm: 'Organisation;CIR;KITS;Team SharePoint;Spielewiese',
|
|
LocalCustomProperties: {
|
|
'_Sys_Nav_SimpleLinkUrl': 'http://dhs.contoso.local/organisation/cir/CIR_21/'
|
|
}})
|
|
];
|
|
const inheritedRoot: ICurrentNavigationTerm = selectCurrentNavigationRoot(
|
|
inheritedTerms,
|
|
'http://dhs.contoso.local/organisation/cir/CIR_21/',
|
|
'http://dhs.contoso.local/organisation/cir'
|
|
);
|
|
assert('nearest taxonomy ancestor root applies to a web with a generic URL',
|
|
!!inheritedRoot && inheritedRoot.Id === 'kits');
|
|
const teamRoot: ICurrentNavigationTerm = selectCurrentNavigationRoot(
|
|
inheritedTerms,
|
|
'http://dhs.contoso.local/organisation/cir/CIR_13/',
|
|
'http://dhs.contoso.local/organisation/cir'
|
|
);
|
|
assert('taxonomy ancestor root also applies to the direct child web',
|
|
!!teamRoot && teamRoot.Id === 'kits');
|
|
const inheritedItems = buildCurrentNavigationItems(
|
|
inheritedTerms, inheritedRoot, 'http://dhs.contoso.local/organisation/cir', 1031, 3, false
|
|
);
|
|
assert('top-navigation hidden does not hide current navigation terms',
|
|
inheritedItems.length === 1 && inheritedItems[0].id === 'team' &&
|
|
inheritedItems[0].items.length === 1 && inheritedItems[0].items[0].id === 'games');
|
|
console.log('CurrentNavigation core tests passed:', passed);
|