-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: content page tree calculation improvments (#1555)
* prevent infinite loop can occur in the mapping of the content page tree. * remove potentially circular references in content page tree path calculation Co-authored-by: Danilo Hoffmann <dhhyi@aol.com>
- Loading branch information
1 parent
564d5c8
commit 2e84cb7
Showing
3 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
src/app/core/models/content-page-tree-view/content-page-tree-view.model.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { ContentPageTreeHelper } from 'ish-core/models/content-page-tree/content-page-tree.helper'; | ||
import { ContentPageTreeElement } from 'ish-core/models/content-page-tree/content-page-tree.model'; | ||
|
||
import { createContentPageTreeView } from './content-page-tree-view.model'; | ||
|
||
describe('Content Page Tree View Model', () => { | ||
it('should not loop forever with recursive tree', () => { | ||
const rootElement = { contentPageId: 'A', path: ['A'] } as ContentPageTreeElement; | ||
const child1 = { contentPageId: 'A.1', path: ['A', 'A.1'] } as ContentPageTreeElement; | ||
const child2 = { contentPageId: 'A.2', path: ['A', 'A.2'] } as ContentPageTreeElement; | ||
const loopingChild = { contentPageId: 'A.1.1', path: ['A', 'A.1', 'A.1'] } as ContentPageTreeElement; | ||
|
||
const empty = ContentPageTreeHelper.empty(); | ||
const tree0 = ContentPageTreeHelper.add(empty, rootElement); | ||
const tree1 = ContentPageTreeHelper.add(tree0, child1); | ||
const tree2 = ContentPageTreeHelper.add(tree1, child2); | ||
const loopingTree = ContentPageTreeHelper.add(tree2, loopingChild); | ||
|
||
const tree = createContentPageTreeView(loopingTree, 'A', 'A'); | ||
|
||
expect(tree).toEqual({ | ||
children: [ | ||
{ | ||
children: [], | ||
contentPageId: 'A.1', | ||
parent: 'A', | ||
path: ['A', 'A.1'], | ||
pathElements: [ | ||
{ contentPageId: 'A', path: ['A'] }, | ||
{ contentPageId: 'A.1', path: ['A', 'A.1'] }, | ||
], | ||
}, | ||
{ | ||
children: [], | ||
contentPageId: 'A.2', | ||
parent: 'A', | ||
path: ['A', 'A.2'], | ||
pathElements: [ | ||
{ contentPageId: 'A', path: ['A'] }, | ||
{ contentPageId: 'A.2', path: ['A', 'A.2'] }, | ||
], | ||
}, | ||
], | ||
contentPageId: 'A', | ||
parent: undefined, | ||
path: ['A'], | ||
pathElements: [{ contentPageId: 'A', path: ['A'] }], | ||
}); | ||
}); | ||
|
||
it('should not loop forever with recursive tree (subtree case)', () => { | ||
const rootElement = { contentPageId: 'A', path: ['A'] } as ContentPageTreeElement; | ||
const child1 = { contentPageId: 'A.1', path: ['A', 'A.1'] } as ContentPageTreeElement; | ||
const child2 = { contentPageId: 'A.2', path: ['A', 'A.2'] } as ContentPageTreeElement; | ||
const loopingChild = { contentPageId: 'A.1.1', path: ['A', 'A.1', 'A.1'] } as ContentPageTreeElement; | ||
|
||
const empty = ContentPageTreeHelper.empty(); | ||
const tree0 = ContentPageTreeHelper.add(empty, rootElement); | ||
const tree1 = ContentPageTreeHelper.add(tree0, child1); | ||
const tree2 = ContentPageTreeHelper.add(tree1, child2); | ||
const loopingTree = ContentPageTreeHelper.add(tree2, loopingChild); | ||
|
||
const tree = createContentPageTreeView(loopingTree, 'A', 'A.1'); | ||
|
||
expect(tree).toEqual({ | ||
children: [ | ||
{ | ||
children: [], | ||
contentPageId: 'A.1', | ||
parent: 'A', | ||
path: ['A', 'A.1'], | ||
pathElements: [ | ||
{ contentPageId: 'A', path: ['A'] }, | ||
{ contentPageId: 'A.1', path: ['A', 'A.1'] }, | ||
], | ||
}, | ||
{ | ||
children: [], | ||
contentPageId: 'A.2', | ||
parent: 'A', | ||
path: ['A', 'A.2'], | ||
pathElements: [ | ||
{ contentPageId: 'A', path: ['A'] }, | ||
{ contentPageId: 'A.2', path: ['A', 'A.2'] }, | ||
], | ||
}, | ||
], | ||
contentPageId: 'A', | ||
parent: undefined, | ||
path: ['A'], | ||
pathElements: [{ contentPageId: 'A', path: ['A'] }], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters