Skip to content

Commit 95cabaf

Browse files
author
Dobromir Hristov
committed
Merge branch 'dhristov/r97715316-add-inline-video-support' of https://github.com/dobromir-hristov/swift-docc-render into dhristov/r97715316-add-inline-video-support
2 parents 65e7dbd + 0ef180c commit 95cabaf

File tree

2 files changed

+110
-40
lines changed

2 files changed

+110
-40
lines changed

src/components/Navigator/NavigatorCard.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,9 @@ export default {
619619
const isOpen = this.openNodes[node.uid];
620620
const openNodes = clone(this.openNodes);
621621
const siblings = this.getSiblings(node.uid);
622-
siblings.forEach(({ uid, childUIDs }) => {
623-
if (!childUIDs.length) return;
622+
siblings.forEach(({ uid, childUIDs, type }) => {
623+
// if the item has no children or is a groupMarker, exit early
624+
if (!childUIDs.length || type === TopicTypes.groupMarker) return;
624625
if (isOpen) {
625626
const children = this.getAllChildren(uid);
626627
// remove all children
@@ -650,7 +651,7 @@ export default {
650651
* @return {NavigatorFlatItem[]}
651652
*/
652653
getAllChildren(uid) {
653-
const arr = [];
654+
const collection = new Set([]);
654655
const stack = [uid];
655656
let current = null;
656657
@@ -660,13 +661,13 @@ export default {
660661
current = stack.shift();
661662
// find the object
662663
const obj = this.childrenMap[current];
663-
// add it's uid
664-
arr.push(obj);
664+
// add it to the collection
665+
collection.add(obj);
665666
// add all if it's children to the front of the stack
666667
stack.unshift(...obj.childUIDs);
667668
}
668669
669-
return arr;
670+
return [...collection];
670671
},
671672
/**
672673
* Get all the parents of a node, up to the root.

tests/unit/components/Navigator/NavigatorCard.spec.js

Lines changed: 103 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ const root1 = {
113113
childUIDs: [],
114114
};
115115

116+
const groupMarker = {
117+
type: TopicTypes.groupMarker,
118+
title: 'First Child Group Marker',
119+
uid: 22,
120+
parent: root0.uid,
121+
depth: 1,
122+
index: 4,
123+
childUIDs: [root0Child0.uid, root0Child1.uid],
124+
deprecatedChildrenCount: 0,
125+
};
126+
127+
const root0WithGroupMarker = {
128+
...root0,
129+
childUIDs: [groupMarker.uid].concat(root0.childUIDs),
130+
};
131+
116132
const children = [
117133
root0,
118134
root0Child0,
@@ -121,6 +137,15 @@ const children = [
121137
root1,
122138
];
123139

140+
const childrenWithGroupMarker = [
141+
root0WithGroupMarker,
142+
groupMarker,
143+
root0Child0,
144+
root0Child1,
145+
root0Child1GrandChild0,
146+
root1,
147+
];
148+
124149
const activePath = [root0.path, root0Child0.path];
125150

126151
const defaultProps = {
@@ -550,6 +575,23 @@ describe('NavigatorCard', () => {
550575
expect(all.at(1).props('item')).toEqual(root0Child1);
551576
expect(all.at(2).props('item')).toEqual(root0Child1GrandChild0);
552577
});
578+
579+
it('keeps groupMarkers in mind, when `@toggle-full` is handled', async () => {
580+
const wrapper = createWrapper({
581+
propsData: {
582+
// make sure no items are open
583+
activePath: [],
584+
children: childrenWithGroupMarker,
585+
},
586+
});
587+
await flushPromises();
588+
wrapper.find(NavigatorCardItem).vm.$emit('toggle-full', root0);
589+
await flushPromises();
590+
expect(wrapper.findAll(NavigatorCardItem)).toHaveLength(6);
591+
wrapper.find(NavigatorCardItem).vm.$emit('toggle-full', root0);
592+
await flushPromises();
593+
expect(wrapper.findAll(NavigatorCardItem)).toHaveLength(2);
594+
});
553595
});
554596

555597
describe('toggles all siblings on @toggle-siblings', () => {
@@ -818,6 +860,56 @@ describe('NavigatorCard', () => {
818860
expect(allItems.at(3).props('item')).toEqual(root1WithChildren);
819861
expect(allItems.at(4).props('item')).toEqual(root1Child0);
820862
});
863+
864+
it('toggles siblings properly, even when there are groupMarkers', async () => {
865+
const wrapper = createWrapper({
866+
propsData: {
867+
children: [
868+
root0WithGroupMarker,
869+
groupMarker,
870+
root0Child0WithChildren,
871+
root0Child0WithChildrenGrandChild0,
872+
root0Child1,
873+
root0Child1GrandChild0,
874+
root1WithChildren,
875+
root1Child0,
876+
],
877+
activePath: [root0WithGroupMarker.path],
878+
},
879+
});
880+
await flushPromises();
881+
// assert we have 3 items rendered
882+
expect(wrapper.findAll(NavigatorCardItem)).toHaveLength(5);
883+
// open the item and it's siblings
884+
wrapper.find(NavigatorCardItem).vm.$emit('toggle-siblings', root0Child1);
885+
await flushPromises();
886+
// assert we have one extra item visible
887+
let allItems = wrapper.findAll(NavigatorCardItem);
888+
// assert all items are as we expect them to be
889+
expect(allItems).toHaveLength(7);
890+
expect(allItems.at(0).props('item')).toEqual(root0WithGroupMarker);
891+
expect(allItems.at(1).props('item')).toEqual(groupMarker);
892+
expect(allItems.at(2).props('item')).toEqual(root0Child0WithChildren);
893+
expect(allItems.at(3).props('item')).toEqual(root0Child0WithChildrenGrandChild0);
894+
expect(allItems.at(4).props('item')).toEqual(root0Child1);
895+
expect(allItems.at(5).props('item')).toEqual(root0Child1GrandChild0);
896+
expect(allItems.at(6).props('item')).toEqual(root1WithChildren);
897+
898+
// toggle the items
899+
allItems.at(0).vm.$emit('toggle-siblings', root0Child1);
900+
await flushPromises();
901+
allItems = wrapper.findAll(NavigatorCardItem);
902+
expect(allItems).toHaveLength(5);
903+
expect(allItems.at(0).props()).toMatchObject({
904+
item: root0WithGroupMarker,
905+
expanded: true,
906+
});
907+
expect(allItems.at(1).props('item')).toEqual(groupMarker);
908+
expect(allItems.at(2).props())
909+
.toMatchObject({ item: root0Child0WithChildren, expanded: false });
910+
expect(allItems.at(3).props()).toMatchObject({ item: root0Child1, expanded: false });
911+
expect(allItems.at(4).props()).toMatchObject({ item: root1WithChildren, expanded: false });
912+
});
821913
});
822914

823915
describe('on @focus-parent', () => {
@@ -1534,22 +1626,6 @@ describe('NavigatorCard', () => {
15341626
});
15351627

15361628
describe('with groupMarker', () => {
1537-
const groupMarker = {
1538-
type: TopicTypes.groupMarker,
1539-
title: 'First Child Group Marker',
1540-
uid: 22,
1541-
parent: root0.uid,
1542-
depth: 1,
1543-
index: 4,
1544-
childUIDs: [root0Child0.uid, root0Child1.uid],
1545-
deprecatedChildrenCount: 0,
1546-
};
1547-
1548-
const root0Updated = {
1549-
...root0,
1550-
childUIDs: [groupMarker.uid].concat(root0.childUIDs),
1551-
};
1552-
15531629
it('shows "Hide Deprecated" tag, if there are deprecated items', async () => {
15541630
const updatedChild = {
15551631
...root0Child0,
@@ -1559,7 +1635,8 @@ describe('NavigatorCard', () => {
15591635
const wrapper = createWrapper({
15601636
propsData: {
15611637
children: [
1562-
root0Updated, groupMarker, updatedChild, root0Child1, root0Child1GrandChild0, root1,
1638+
root0WithGroupMarker, groupMarker, updatedChild, root0Child1, root0Child1GrandChild0,
1639+
root1,
15631640
],
15641641
activePath: [root0.path],
15651642
},
@@ -1577,7 +1654,7 @@ describe('NavigatorCard', () => {
15771654
// assert the deprecated item is filtered out
15781655
expect(allItems).toHaveLength(4);
15791656
// assert root is rendered
1580-
expect(allItems.at(0).props('item')).toEqual(root0Updated);
1657+
expect(allItems.at(0).props('item')).toEqual(root0WithGroupMarker);
15811658
// assert the group marker is rendered
15821659
expect(allItems.at(1).props('item')).toEqual(groupMarker);
15831660
// assert the none-deprecated child is rendered, but its not expanded
@@ -1592,7 +1669,7 @@ describe('NavigatorCard', () => {
15921669
allItems = wrapper.findAll(NavigatorCardItem);
15931670
// assert that filtering opens everything as usual, showing groupMarkers as well
15941671
expect(allItems).toHaveLength(4);
1595-
expect(allItems.at(0).props('item')).toEqual(root0Updated);
1672+
expect(allItems.at(0).props('item')).toEqual(root0WithGroupMarker);
15961673
expect(allItems.at(1).props('item')).toEqual(groupMarker);
15971674
expect(allItems.at(2).props('item')).toEqual(root0Child1);
15981675
expect(allItems.at(3).props('item')).toEqual(root0Child1GrandChild0);
@@ -1602,7 +1679,8 @@ describe('NavigatorCard', () => {
16021679
const wrapper = createWrapper({
16031680
propsData: {
16041681
children: [
1605-
root0Updated, groupMarker, root0Child0, root0Child1, root0Child1GrandChild0, root1,
1682+
root0WithGroupMarker, groupMarker, root0Child0, root0Child1, root0Child1GrandChild0,
1683+
root1,
16061684
],
16071685
activePath: [root0.path],
16081686
},
@@ -1614,7 +1692,7 @@ describe('NavigatorCard', () => {
16141692
let items = wrapper.findAll(NavigatorCardItem);
16151693
// parent + group and 2 siblings
16161694
expect(items).toHaveLength(4);
1617-
expect(items.at(0).props('item')).toEqual(root0Updated);
1695+
expect(items.at(0).props('item')).toEqual(root0WithGroupMarker);
16181696
expect(items.at(1).props('item')).toEqual(groupMarker);
16191697
expect(items.at(2).props('item')).toEqual(root0Child0);
16201698
expect(items.at(3).props('item')).toEqual(root0Child1);
@@ -1629,7 +1707,7 @@ describe('NavigatorCard', () => {
16291707
await flushPromises();
16301708
items = wrapper.findAll(NavigatorCardItem);
16311709
expect(items).toHaveLength(5);
1632-
expect(items.at(0).props('item')).toEqual(root0Updated);
1710+
expect(items.at(0).props('item')).toEqual(root0WithGroupMarker);
16331711
expect(items.at(1).props('item')).toEqual(groupMarker);
16341712
expect(items.at(2).props('item')).toEqual(root0Child0);
16351713
expect(items.at(3).props('item')).toEqual(root0Child1);
@@ -1642,7 +1720,7 @@ describe('NavigatorCard', () => {
16421720
const wrapper = createWrapper({
16431721
propsData: {
16441722
children: [
1645-
root0Updated, groupMarker, root0Child0Clone,
1723+
root0WithGroupMarker, groupMarker, root0Child0Clone,
16461724
root0Child1Clone, root0Child1GrandChild0, root1,
16471725
],
16481726
activePath: [root0.path],
@@ -1656,7 +1734,7 @@ describe('NavigatorCard', () => {
16561734
const items = wrapper.findAll(NavigatorCardItem);
16571735
// parent + group and 1 item
16581736
expect(items).toHaveLength(3);
1659-
expect(items.at(0).props('item')).toEqual(root0Updated);
1737+
expect(items.at(0).props('item')).toEqual(root0WithGroupMarker);
16601738
expect(items.at(1).props('item')).toEqual(groupMarker);
16611739
expect(items.at(2).props('item')).toEqual(root0Child1Clone);
16621740
});
@@ -1674,7 +1752,7 @@ describe('NavigatorCard', () => {
16741752
childUIDs: [],
16751753
};
16761754
const groupMarkerClone = { ...groupMarker, deprecatedChildrenCount: 2 };
1677-
const root0Clone = { ...root0Updated, deprecated: true };
1755+
const root0Clone = { ...root0WithGroupMarker, deprecated: true };
16781756
const wrapper = createWrapper({
16791757
propsData: {
16801758
children: [
@@ -1713,15 +1791,6 @@ describe('NavigatorCard', () => {
17131791
...root0Child0,
17141792
deprecated: true,
17151793
};
1716-
const groupMarker = {
1717-
type: TopicTypes.groupMarker,
1718-
title: 'First Child Group Marker',
1719-
uid: 22,
1720-
parent: root0.uid,
1721-
depth: 1,
1722-
index: 4,
1723-
childUIDs: [],
1724-
};
17251794
const root0Updated = {
17261795
...root0,
17271796
childUIDs: root0.childUIDs.concat(groupMarker.uid),

0 commit comments

Comments
 (0)