|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using System.IO.Abstractions; |
| 6 | +using AwesomeAssertions; |
| 7 | +using Elastic.Documentation.Configuration.Products; |
| 8 | +using Elastic.Documentation.Configuration.Versions; |
| 9 | +using Microsoft.Extensions.Logging.Abstractions; |
| 10 | + |
| 11 | +namespace Elastic.Documentation.Configuration.Tests; |
| 12 | + |
| 13 | +public class ProductFeaturesTests |
| 14 | +{ |
| 15 | + [Fact] |
| 16 | + public void ProductWithNoFeaturesKey_GetsAllFeaturesEnabled() |
| 17 | + { |
| 18 | + var config = LoadActualProductsConfiguration(); |
| 19 | + var elasticsearch = config.Products["elasticsearch"]; |
| 20 | + |
| 21 | + elasticsearch.Features.PublicReference.Should().BeTrue(); |
| 22 | + elasticsearch.Features.ReleaseNotes.Should().BeTrue(); |
| 23 | + } |
| 24 | + |
| 25 | + [Fact] |
| 26 | + public void ProductWithReleaseNotesOnly_ExcludedFromPublicReference() |
| 27 | + { |
| 28 | + var config = LoadActualProductsConfiguration(); |
| 29 | + var docsBuilder = config.Products["docs-builder"]; |
| 30 | + |
| 31 | + docsBuilder.Features.PublicReference.Should().BeFalse(); |
| 32 | + docsBuilder.Features.ReleaseNotes.Should().BeTrue(); |
| 33 | + } |
| 34 | + |
| 35 | + [Fact] |
| 36 | + public void PublicReferenceProducts_ExcludesReleaseNotesOnlyProducts() |
| 37 | + { |
| 38 | + var config = LoadActualProductsConfiguration(); |
| 39 | + |
| 40 | + config.Products.Should().ContainKey("docs-builder"); |
| 41 | + config.PublicReferenceProducts.Should().NotContainKey("docs-builder"); |
| 42 | + } |
| 43 | + |
| 44 | + [Fact] |
| 45 | + public void PublicReferenceProducts_IncludesStandardProducts() |
| 46 | + { |
| 47 | + var config = LoadActualProductsConfiguration(); |
| 48 | + |
| 49 | + config.PublicReferenceProducts.Should().ContainKey("elasticsearch"); |
| 50 | + config.PublicReferenceProducts.Should().ContainKey("kibana"); |
| 51 | + } |
| 52 | + |
| 53 | + [Fact] |
| 54 | + public void AllProducts_ContainsBothStandardAndReleaseNotesOnly() |
| 55 | + { |
| 56 | + var config = LoadActualProductsConfiguration(); |
| 57 | + |
| 58 | + config.Products.Should().ContainKey("elasticsearch"); |
| 59 | + config.Products.Should().ContainKey("docs-builder"); |
| 60 | + } |
| 61 | + |
| 62 | + [Fact] |
| 63 | + public void ProductFeatures_All_HasBothFeaturesEnabled() |
| 64 | + { |
| 65 | + var all = ProductFeatures.All; |
| 66 | + |
| 67 | + all.PublicReference.Should().BeTrue(); |
| 68 | + all.ReleaseNotes.Should().BeTrue(); |
| 69 | + } |
| 70 | + |
| 71 | + [Fact] |
| 72 | + public void ProductFeatures_KnownKeys_ContainsExpectedEntries() |
| 73 | + { |
| 74 | + ProductFeatures.KnownKeys.Should().Contain("public-reference"); |
| 75 | + ProductFeatures.KnownKeys.Should().Contain("release-notes"); |
| 76 | + ProductFeatures.KnownKeys.Should().HaveCount(2); |
| 77 | + } |
| 78 | + |
| 79 | + [Fact] |
| 80 | + public void GetDisplayName_WorksForReleaseNotesOnlyProducts() |
| 81 | + { |
| 82 | + var config = LoadActualProductsConfiguration(); |
| 83 | + |
| 84 | + config.GetDisplayName("docs-builder").Should().Be("Elastic Docs Builder"); |
| 85 | + } |
| 86 | + |
| 87 | + [Fact] |
| 88 | + public void GetProductByRepositoryName_WorksForReleaseNotesOnlyProducts() |
| 89 | + { |
| 90 | + var config = LoadActualProductsConfiguration(); |
| 91 | + var product = config.GetProductByRepositoryName("docs-builder"); |
| 92 | + |
| 93 | + product.Should().NotBeNull(); |
| 94 | + product.Id.Should().Be("docs-builder"); |
| 95 | + } |
| 96 | + |
| 97 | + private static ProductsConfiguration LoadActualProductsConfiguration() |
| 98 | + { |
| 99 | + var fileSystem = new FileSystem(); |
| 100 | + var provider = new ConfigurationFileProvider(new NullLoggerFactory(), fileSystem); |
| 101 | + var versionsConfig = provider.CreateVersionConfiguration(); |
| 102 | + return provider.CreateProducts(versionsConfig); |
| 103 | + } |
| 104 | +} |
0 commit comments