|
4 | 4 |
|
5 | 5 | using System.IO.Abstractions.TestingHelpers; |
6 | 6 | using Elastic.Documentation.Configuration.DocSet; |
| 7 | +using Elastic.Documentation.Diagnostics; |
7 | 8 | using Elastic.Documentation.Extensions; |
8 | 9 | using Elastic.Documentation.Navigation.Isolated; |
9 | 10 | using FluentAssertions; |
@@ -169,4 +170,119 @@ public async Task ValidationEmitsErrorWhenTocYmlFileNotFound() |
169 | 170 | d.Message.Contains("Table of contents file not found") && |
170 | 171 | d.Message.Contains("api/toc.yml")); |
171 | 172 | } |
| 173 | + |
| 174 | + [Fact] |
| 175 | + public async Task ValidationEmitsHintForDeepLinkingVirtualFiles() |
| 176 | + { |
| 177 | + // language=yaml |
| 178 | + var yaml = """ |
| 179 | + project: 'test-project' |
| 180 | + toc: |
| 181 | + - file: a/b/c/getting-started.md |
| 182 | + children: |
| 183 | + - file: a/b/c/setup.md |
| 184 | + - file: a/b/c/install.md |
| 185 | + """; |
| 186 | + |
| 187 | + var fileSystem = new MockFileSystem(); |
| 188 | + fileSystem.AddDirectory("/docs"); |
| 189 | + var context = CreateContext(fileSystem); |
| 190 | + var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, yaml, fileSystem.NewDirInfo("docs")); |
| 191 | + _ = context.Collector.StartAsync(TestContext.Current.CancellationToken); |
| 192 | + |
| 193 | + _ = new DocumentationSetNavigation<IDocumentationFile>(docSet, context, GenericDocumentationFileFactory.Instance); |
| 194 | + |
| 195 | + await context.Collector.StopAsync(TestContext.Current.CancellationToken); |
| 196 | + |
| 197 | + context.Collector.Hints.Should().BeGreaterThan(0, "should have emitted a hint for deep-linking virtual file"); |
| 198 | + var diagnostics = context.Diagnostics; |
| 199 | + diagnostics.Should().Contain(d => |
| 200 | + d.Severity == Severity.Hint && |
| 201 | + d.Message.Contains("a/b/c/getting-started.md") && |
| 202 | + d.Message.Contains("deep-linking") && |
| 203 | + d.Message.Contains("folder")); |
| 204 | + } |
| 205 | + |
| 206 | + [Fact] |
| 207 | + public async Task ValidationEmitsHintForNestedPathVirtualFiles() |
| 208 | + { |
| 209 | + // language=yaml |
| 210 | + var yaml = """ |
| 211 | + project: 'test-project' |
| 212 | + toc: |
| 213 | + - file: guides/api/overview.md |
| 214 | + children: |
| 215 | + - file: guides/api/authentication.md |
| 216 | + - file: guides/api/endpoints.md |
| 217 | + """; |
| 218 | + |
| 219 | + var fileSystem = new MockFileSystem(); |
| 220 | + fileSystem.AddDirectory("/docs"); |
| 221 | + var context = CreateContext(fileSystem); |
| 222 | + var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, yaml, fileSystem.NewDirInfo("docs")); |
| 223 | + _ = context.Collector.StartAsync(TestContext.Current.CancellationToken); |
| 224 | + |
| 225 | + _ = new DocumentationSetNavigation<IDocumentationFile>(docSet, context, GenericDocumentationFileFactory.Instance); |
| 226 | + |
| 227 | + await context.Collector.StopAsync(TestContext.Current.CancellationToken); |
| 228 | + |
| 229 | + context.Collector.Hints.Should().BeGreaterThan(0); |
| 230 | + var diagnostics = context.Diagnostics; |
| 231 | + diagnostics.Should().Contain(d => |
| 232 | + d.Severity == Severity.Hint && |
| 233 | + d.Message.Contains("guides/api/overview.md") && |
| 234 | + d.Message.Contains("Virtual files are primarily intended to group sibling files together")); |
| 235 | + } |
| 236 | + |
| 237 | + [Fact] |
| 238 | + public async Task ValidationDoesNotEmitHintForSimpleVirtualFiles() |
| 239 | + { |
| 240 | + // language=yaml |
| 241 | + var yaml = """ |
| 242 | + project: 'test-project' |
| 243 | + toc: |
| 244 | + - file: guide.md |
| 245 | + children: |
| 246 | + - file: chapter1.md |
| 247 | + - file: chapter2.md |
| 248 | + """; |
| 249 | + |
| 250 | + var fileSystem = new MockFileSystem(); |
| 251 | + fileSystem.AddDirectory("/docs"); |
| 252 | + var context = CreateContext(fileSystem); |
| 253 | + var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, yaml, fileSystem.NewDirInfo("docs")); |
| 254 | + _ = context.Collector.StartAsync(TestContext.Current.CancellationToken); |
| 255 | + |
| 256 | + _ = new DocumentationSetNavigation<IDocumentationFile>(docSet, context, GenericDocumentationFileFactory.Instance); |
| 257 | + |
| 258 | + await context.Collector.StopAsync(TestContext.Current.CancellationToken); |
| 259 | + |
| 260 | + context.Collector.Hints.Should().Be(0, "simple virtual files without deep-linking should not trigger hints"); |
| 261 | + context.Diagnostics.Should().BeEmpty(); |
| 262 | + } |
| 263 | + |
| 264 | + [Fact] |
| 265 | + public async Task ValidationDoesNotEmitHintForFilesWithoutChildren() |
| 266 | + { |
| 267 | + // language=yaml |
| 268 | + var yaml = """ |
| 269 | + project: 'test-project' |
| 270 | + toc: |
| 271 | + - file: a/b/c/getting-started.md |
| 272 | + - file: guides/setup.md |
| 273 | + """; |
| 274 | + |
| 275 | + var fileSystem = new MockFileSystem(); |
| 276 | + fileSystem.AddDirectory("/docs"); |
| 277 | + var context = CreateContext(fileSystem); |
| 278 | + var docSet = DocumentationSetFile.LoadAndResolve(context.Collector, yaml, fileSystem.NewDirInfo("docs")); |
| 279 | + _ = context.Collector.StartAsync(TestContext.Current.CancellationToken); |
| 280 | + |
| 281 | + _ = new DocumentationSetNavigation<IDocumentationFile>(docSet, context, GenericDocumentationFileFactory.Instance); |
| 282 | + |
| 283 | + await context.Collector.StopAsync(TestContext.Current.CancellationToken); |
| 284 | + |
| 285 | + context.Collector.Hints.Should().Be(0, "files without children should not trigger hints, even with deep paths"); |
| 286 | + context.Diagnostics.Should().BeEmpty(); |
| 287 | + } |
172 | 288 | } |
0 commit comments