Skip to content

Commit bc87360

Browse files
committed
Fix tests expecting crosslink navigation item
1 parent 5ca4d6e commit bc87360

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

tests/Navigation.Tests/Isolation/ConstructorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void ConstructorCreatesCrossLinkNavigation()
127127
var context = CreateContext(fileSystem);
128128
var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, yaml, fileSystem.NewDirInfo("docs"));
129129

130-
var navigation = new DocumentationSetNavigation<IDocumentationFile>(docSet, context, GenericDocumentationFileFactory.Instance);
130+
var navigation = new DocumentationSetNavigation<IDocumentationFile>(docSet, context, GenericDocumentationFileFactory.Instance, crossLinkResolver: TestCrossLinkResolver.Instance);
131131

132132
navigation.NavigationItems.Should().HaveCount(0);
133133
var crossLink = navigation.Index.Should().BeOfType<CrossLinkNavigationLeaf>().Subject;

tests/Navigation.Tests/Isolation/NavigationStructureTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public async Task ComplexNestedStructureBuildsCorrectly()
151151
var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, yaml, fileSystem.NewDirInfo("docs"));
152152
_ = context.Collector.StartAsync(TestContext.Current.CancellationToken);
153153

154-
var navigation = new DocumentationSetNavigation<TestDocumentationFile>(docSet, context, TestDocumentationFileFactory.Instance);
154+
var navigation = new DocumentationSetNavigation<TestDocumentationFile>(docSet, context, TestDocumentationFileFactory.Instance, crossLinkResolver: TestCrossLinkResolver.Instance);
155155

156156
await context.Collector.StopAsync(TestContext.Current.CancellationToken);
157157

@@ -295,7 +295,7 @@ public void AllNavigationItemsHaveNavigationRootSet()
295295
var context = CreateContext(fileSystem);
296296
var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, yaml, fileSystem.NewDirInfo("docs"));
297297

298-
var navigation = new DocumentationSetNavigation<TestDocumentationFile>(docSet, context, TestDocumentationFileFactory.Instance);
298+
var navigation = new DocumentationSetNavigation<TestDocumentationFile>(docSet, context, TestDocumentationFileFactory.Instance, crossLinkResolver: TestCrossLinkResolver.Instance);
299299

300300
// Helper to recursively visit all navigation items
301301
var allItems = new List<INavigationItem>();

tests/Navigation.Tests/Isolation/PhysicalDocsetTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Elastic.Documentation.Configuration;
77
using Elastic.Documentation.Configuration.DocSet;
88
using Elastic.Documentation.Diagnostics;
9-
using Elastic.Documentation.Navigation.Isolated;
109
using Elastic.Documentation.Navigation.Isolated.Leaf;
1110
using Elastic.Documentation.Navigation.Isolated.Node;
1211
using FluentAssertions;
@@ -30,7 +29,7 @@ public async Task PhysicalDocsetCanBeNavigated()
3029
var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, configPath, fileSystem);
3130
_ = context.Collector.StartAsync(TestContext.Current.CancellationToken);
3231

33-
var navigation = new DocumentationSetNavigation<TestDocumentationFile>(docSet, context, TestDocumentationFileFactory.Instance);
32+
var navigation = new DocumentationSetNavigation<TestDocumentationFile>(docSet, context, TestDocumentationFileFactory.Instance, crossLinkResolver: TestCrossLinkResolver.Instance);
3433

3534
await context.Collector.StopAsync(TestContext.Current.CancellationToken);
3635

@@ -171,7 +170,7 @@ public async Task PhysicalDocsetNavigationHandlesCrossLinks()
171170
var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, configPath);
172171
_ = context.Collector.StartAsync(TestContext.Current.CancellationToken);
173172

174-
var navigation = new DocumentationSetNavigation<TestDocumentationFile>(docSet, context, TestDocumentationFileFactory.Instance);
173+
var navigation = new DocumentationSetNavigation<TestDocumentationFile>(docSet, context, TestDocumentationFileFactory.Instance, crossLinkResolver: TestCrossLinkResolver.Instance);
175174

176175
await context.Collector.StopAsync(TestContext.Current.CancellationToken);
177176

tests/Navigation.Tests/TestDocumentationSetContext.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using System.Diagnostics.CodeAnalysis;
56
using System.IO.Abstractions;
67
using Elastic.Documentation;
78
using Elastic.Documentation.Diagnostics;
89
using Elastic.Documentation.Extensions;
10+
using Elastic.Documentation.Links.CrossLinks;
911
using Elastic.Documentation.Navigation.Isolated;
1012
using Markdig;
1113
using Markdig.Parsers;
@@ -46,6 +48,25 @@ public override void Write(Diagnostic diagnostic)
4648
public override Task StopAsync(Cancel cancellationToken) => Task.CompletedTask;
4749
}
4850

51+
/// <summary>A cross link resolver that always resolves to a fixed URL </summary>
52+
public class TestCrossLinkResolver : ICrossLinkResolver
53+
{
54+
public static TestCrossLinkResolver Instance { get; } = new();
55+
56+
/// <inheritdoc />
57+
public bool TryResolve(Action<string> errorEmitter, Uri crossLinkUri, [NotNullWhen(true)] out Uri? resolvedUri)
58+
{
59+
resolvedUri = new Uri("https://docs-v3-preview.elastic.dev/elastic/docs-builder/tree/main");
60+
return true;
61+
}
62+
63+
/// <inheritdoc />
64+
public IUriEnvironmentResolver UriResolver { get; } = new IsolatedBuildEnvironmentUriResolver();
65+
66+
private TestCrossLinkResolver() { }
67+
68+
}
69+
4970
public class TestDocumentationSetContext : IDocumentationSetContext
5071
{
5172
public TestDocumentationSetContext(IFileSystem fileSystem,

0 commit comments

Comments
 (0)