Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/layout/src/steps/resolveBookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const resolveBookmarks = (node: DocumentNode) => {

let parent = element.parent;

if (child.props && 'bookmark' in child.props) {
if (child.props && 'bookmark' in child.props && child.props.bookmark) {
const bookmark = getBookmarkValue(child.props.bookmark);
const ref = refs++;
const newHierarchy = { ref, parent: parent?.ref, ...bookmark };
Expand Down
67 changes: 66 additions & 1 deletion packages/layout/tests/steps/resolveBookmarks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,72 @@ describe('layout resolveBookmarks', () => {

const result = resolveBookmarks(root);

expect(result).toEqual(root);
expect(result).toEqual({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to the fix, but updated this test to test against a new variable instance. The previous test would always pass because the original root variable would get mutated.

type: 'DOCUMENT',
props: {},
children: [
{
type: 'PAGE',
children: [{ type: 'VIEW', props: {} }],
},
],
});
});

test('should keep nodes the same if an undefined bookmark passed', () => {
const root = {
type: 'DOCUMENT',
props: {},
children: [
{
type: 'PAGE',
props: { bookmark: undefined },
children: [{ type: 'VIEW', props: {} }],
},
],
} as DocumentNode;

const result = resolveBookmarks(root);

expect(result).toEqual({
type: 'DOCUMENT',
props: {},
children: [
{
type: 'PAGE',
props: { bookmark: undefined },
children: [{ type: 'VIEW', props: {} }],
},
],
});
});

test('should keep nodes the same if a null bookmark passed', () => {
const root = {
type: 'DOCUMENT',
props: {},
children: [
{
type: 'PAGE',
props: { bookmark: null },
children: [{ type: 'VIEW', props: {} }],
},
],
} as DocumentNode;

const result = resolveBookmarks(root);

expect(result).toEqual({
type: 'DOCUMENT',
props: {},
children: [
{
type: 'PAGE',
props: { bookmark: null },
children: [{ type: 'VIEW', props: {} }],
},
],
});
});

test('should resolve bookmark in page node', () => {
Expand Down