Skip to content

Commit 916bb58

Browse files
author
Dobromir Hristov
authored
Fix toggling off sibling items removes everything but groupMarkers (#430)
closes rdar://99747732
1 parent 0ae2fbc commit 916bb58

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/components/Navigator/NavigatorCard.vue

Lines changed: 3 additions & 2 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

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,56 @@ describe('NavigatorCard', () => {
860860
expect(allItems.at(3).props('item')).toEqual(root1WithChildren);
861861
expect(allItems.at(4).props('item')).toEqual(root1Child0);
862862
});
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+
});
863913
});
864914

865915
describe('on @focus-parent', () => {

0 commit comments

Comments
 (0)