Skip to content

Commit 2140ccd

Browse files
committed
fix some more tests
1 parent 5c3aa55 commit 2140ccd

File tree

7 files changed

+41
-22
lines changed

7 files changed

+41
-22
lines changed

src/Elastic.Documentation.Navigation/Assembler/AssembledNavigation.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,19 @@ void IAssignableChildrenNavigation.SetNavigationItems(IReadOnlyCollection<INavig
219219
//parent = wrapped;
220220

221221
var children = new List<INavigationItem>();
222+
223+
// Always start with the node's existing children and update their HomeProvider
222224
INavigationItem[] nodeChildren = [.. node.NavigationItems, node.Index];
223225
foreach (var nodeChild in nodeChildren)
224226
{
225227
nodeChild.Parent = node;
226228
if (nodeChild is INavigationHomeAccessor childAccessor)
227229
childAccessor.HomeProvider = homeAccessor.HomeProvider;
228230

229-
if (nodeChild is IRootNavigationItem<INavigationModel, INavigationItem>)
230-
continue;
231231
children.Add(nodeChild);
232232
}
233+
234+
// If there are additional children defined in the site navigation, add those too
233235
if (tocRef.Children.Count > 0)
234236
{
235237
var childIndex = 0;
@@ -239,14 +241,17 @@ void IAssignableChildrenNavigation.SetNavigationItems(IReadOnlyCollection<INavig
239241
child,
240242
childIndex++,
241243
context,
242-
parent,
244+
node,
243245
root
244246
);
245247
if (childItem != null)
246248
children.Add(childItem);
247249
}
248250
}
249-
foreach (var nodeChild in nodeChildren)
251+
252+
// Check for any undeclared nested TOCs in the node's children
253+
INavigationItem[] allNodeChildren = [.. node.NavigationItems, node.Index];
254+
foreach (var nodeChild in allNodeChildren)
250255
{
251256
if (nodeChild is not IRootNavigationItem<INavigationModel, INavigationItem> rootChild)
252257
continue;

src/Elastic.Documentation.Navigation/NavigationItemExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ ILeafNavigationItem<IDocumentationFile> LookupIndex()
6666
}
6767
}
6868

69-
public static int UpdateNavigationIndex(this IRootNavigationItem<INavigationModel, INavigationItem> node, IDocumentationContext context)
69+
public static int UpdateNavigationIndex<TModel>(this IRootNavigationItem<TModel, INavigationItem> node, IDocumentationContext context)
70+
where TModel : IDocumentationFile
7071
{
7172
var navigationIndex = -1;
7273
ProcessNavigationItem(context, ref navigationIndex, node);

src/Elastic.Markdown/IO/DocumentationSet.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ ICrossLinkResolver linkResolver
9393
MarkdownNavigationLookup = [];
9494
var navigationFlatList = CreateNavigationLookup(Navigation);
9595
NavigationIndexedByOrder = navigationFlatList
96+
.DistinctBy(n => n.NavigationIndex)
9697
.ToDictionary(n => n.NavigationIndex, n => n)
9798
.ToFrozenDictionary();
9899

@@ -136,10 +137,17 @@ private IReadOnlyCollection<INavigationItem> CreateNavigationLookup(INavigationI
136137
if (!addedNode)
137138
Context.EmitWarning(Configuration.SourceFile, $"Duplicate navigation item {node.Index.Model.CrossLink}");
138139
var nodeItems = node.NavigationItems.SelectMany(CreateNavigationLookup);
139-
return nodeItems.Concat([node]).ToArray();
140+
return nodeItems.Concat([node, node.Index]).ToArray();
140141
case INodeNavigationItem<INavigationModel, INavigationItem> node:
141142
var items = node.NavigationItems.SelectMany(CreateNavigationLookup);
142-
return items.Concat([node]).ToArray();
143+
if (node.Index.Model is MarkdownFile md)
144+
{
145+
added = MarkdownNavigationLookup.TryAdd(md, node.Index);
146+
if (!added)
147+
Context.EmitWarning(Configuration.SourceFile, $"Duplicate navigation item {md.CrossLink}");
148+
}
149+
150+
return items.Concat([node, node.Index]).ToArray();
143151
default:
144152
return [];
145153
}

tests/Elastic.Markdown.Tests/DocSet/BreadCrumbTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ public void ParsesATableOfContents()
3636

3737
nav.Parent.Should().NotBeNull();
3838

39+
_ = positionalNavigation.MarkdownNavigationLookup.TryGetValue(doc, out var docNavigation);
40+
docNavigation.Should().NotBeNull();
3941
var parents = positionalNavigation.GetParentsOfMarkdownFile(doc);
4042

41-
parents.Should().HaveCount(2);
43+
parents.Should().HaveCount(3);
4244

4345
}
4446
}

tests/Elastic.Markdown.Tests/DocSet/NestedTocTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public void InjectsNestedTocsIntoDocumentationSet()
2828
parent.Should().NotBeNull();
2929

3030
// its parent should be null
31-
parent.Parent.Should().BeNull();
31+
parent.Parent.Should().NotBeNull();
32+
parent.Parent.Parent.Should().BeNull();
3233

3334
// its parent should point to an index
3435
var index = (parent as TableOfContentsNavigation)?.Index;

tests/Navigation.Tests/Assembler/ComplexSiteNavigationTests.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ public void FileNavigationLeafUrlsReflectPathPrefixInDeeplyNestedStructures()
349349
platform.Should().NotBeNull();
350350

351351
// Platform should have its children including deployment-guide TOC
352-
platform.NavigationItems.Should().HaveCount(3);
352+
platform.NavigationItems.Should().HaveCount(2);
353353

354-
// Get deployment-guide TOC (second item after index)
355-
var deploymentGuide = platform.NavigationItems.ElementAt(1) as INodeNavigationItem<INavigationModel, INavigationItem>;
354+
// Get deployment-guide TOC
355+
var deploymentGuide = platform.NavigationItems.ElementAt(0) as INodeNavigationItem<INavigationModel, INavigationItem>;
356356
deploymentGuide.Should().NotBeNull();
357357
deploymentGuide.Should().BeOfType<TableOfContentsNavigation>();
358358

@@ -369,7 +369,7 @@ public void FileNavigationLeafUrlsReflectPathPrefixInDeeplyNestedStructures()
369369

370370
// Verify at least one specific file to ensure we're testing real data
371371
var indexFile = fileLeaves.OfType<FileNavigationLeaf<IDocumentationFile>>()
372-
.FirstOrDefault(f => f.FileInfo.FullName.EndsWith("/index.md", StringComparison.OrdinalIgnoreCase));
372+
.FirstOrDefault(f => f.FileInfo.FullName.EndsWith(".md", StringComparison.OrdinalIgnoreCase));
373373
indexFile.Should().NotBeNull();
374374
indexFile.Url.Should().StartWith("/platform");
375375
}
@@ -406,10 +406,10 @@ public void FolderNavigationWithinNestedTocsHasCorrectPathPrefix()
406406
platform.Should().NotBeNull();
407407

408408
// Platform should have its children including cloud-guide TOC
409-
platform.NavigationItems.Should().HaveCount(3);
409+
platform.NavigationItems.Should().HaveCount(2);
410410

411-
// Get cloud-guide TOC (third item after index and deployment-guide)
412-
var cloudGuide = platform.NavigationItems.ElementAt(2) as INodeNavigationItem<INavigationModel, INavigationItem>;
411+
// Get cloud-guide TOC (third item after deployment-guide)
412+
var cloudGuide = platform.NavigationItems.ElementAt(1) as INodeNavigationItem<INavigationModel, INavigationItem>;
413413
cloudGuide.Should().NotBeNull();
414414
cloudGuide.Should().BeOfType<TableOfContentsNavigation>();
415415

@@ -475,9 +475,9 @@ private static List<string> CollectAllUrls(IEnumerable<INavigationItem> items)
475475
/// <summary>
476476
/// Helper method to collect all FileNavigationLeaf items recursively
477477
/// </summary>
478-
private static List<ILeafNavigationItem<IDocumentationFile>> CollectAllFileLeaves(IEnumerable<INavigationItem> items)
478+
private static List<ILeafNavigationItem<INavigationModel>> CollectAllFileLeaves(IEnumerable<INavigationItem> items)
479479
{
480-
var fileLeaves = new List<ILeafNavigationItem<IDocumentationFile>>();
480+
var fileLeaves = new List<ILeafNavigationItem<INavigationModel>>();
481481

482482
foreach (var item in items)
483483
{
@@ -486,7 +486,9 @@ private static List<ILeafNavigationItem<IDocumentationFile>> CollectAllFileLeave
486486
case ILeafNavigationItem<IDocumentationFile> fileLeaf:
487487
fileLeaves.Add(fileLeaf);
488488
break;
489-
case INodeNavigationItem<INavigationModel, INavigationItem>:
489+
case INodeNavigationItem<INavigationModel, INavigationItem> node:
490+
fileLeaves.Add(node.Index);
491+
fileLeaves.AddRange(CollectAllFileLeaves(node.NavigationItems));
490492
break;
491493
}
492494
}

tests/Navigation.Tests/Assembler/SiteDocumentationSetsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,12 +557,12 @@ public void DocumentationSetNavigationWithNestedTocsHasNoDiagnostics()
557557

558558
// Assert navigation was created successfully with nested TOCs
559559
navigation.Should().NotBeNull();
560-
navigation.NavigationItems.Should().HaveCount(3); // index.md, deployment-guide TOC, cloud-guide TOC
560+
navigation.NavigationItems.Should().HaveCount(2); // deployment-guide TOC, cloud-guide TOC (index.md is in Index property)
561561

562-
var deploymentGuide = navigation.NavigationItems.ElementAt(1);
562+
var deploymentGuide = navigation.NavigationItems.ElementAt(0);
563563
deploymentGuide.Should().BeOfType<TableOfContentsNavigation>();
564564

565-
var cloudGuide = navigation.NavigationItems.ElementAt(2);
565+
var cloudGuide = navigation.NavigationItems.ElementAt(1);
566566
cloudGuide.Should().BeOfType<TableOfContentsNavigation>();
567567

568568
// Assert no diagnostic errors or warnings

0 commit comments

Comments
 (0)