|
| 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 | +module ``AuthoringTests``.``frontmatter``.``products frontmatter`` |
| 6 | + |
| 7 | +open Swensen.Unquote |
| 8 | +open Xunit |
| 9 | +open authoring |
| 10 | +open JetBrains.Annotations |
| 11 | + |
| 12 | +let frontMatter ([<LanguageInjection("yaml")>]m: string) = |
| 13 | + Setup.Document $"""--- |
| 14 | +{m} |
| 15 | +--- |
| 16 | +# Test Page |
| 17 | +
|
| 18 | +This is a test page with products frontmatter. |
| 19 | +""" |
| 20 | + |
| 21 | +type ``products frontmatter in HTML`` () = |
| 22 | + static let markdownWithProducts = frontMatter """ |
| 23 | +products: |
| 24 | + - id: elasticsearch |
| 25 | + - id: ecctl |
| 26 | +""" |
| 27 | + |
| 28 | + [<Fact>] |
| 29 | + let ``includes products meta tags when products are specified`` () = |
| 30 | + markdownWithProducts |> converts "index.md" |> containsHtml """ |
| 31 | +<meta class="elastic" name="product_name" content="Elasticsearch,Elastic Cloud Control ECCTL"/> |
| 32 | +<meta name="DC.subject" content="Elasticsearch,Elastic Cloud Control ECCTL"/> |
| 33 | +""" |
| 34 | + |
| 35 | + [<Fact>] |
| 36 | + let ``does not include products meta tags when no products are specified`` () = |
| 37 | + let markdownWithoutProducts = Setup.Document """ |
| 38 | +# Test Page |
| 39 | +
|
| 40 | +This is a test page without products frontmatter. |
| 41 | +""" |
| 42 | + // When there are no products, no product-related meta tags should be rendered at all |
| 43 | + let results = markdownWithoutProducts.Value |
| 44 | + let defaultFile = results.MarkdownResults |> Seq.find (fun r -> r.File.RelativePath = "index.md") |
| 45 | + let html = defaultFile.Html |
| 46 | + |
| 47 | + // Verify that product meta tags are NOT present in the HTML |
| 48 | + test <@ not (html.Contains("product_name")) @> |
| 49 | + test <@ not (html.Contains("DC.subject")) @> |
| 50 | + |
| 51 | +type ``products frontmatter in LLM Markdown`` () = |
| 52 | + static let markdownWithProducts = frontMatter """ |
| 53 | +products: |
| 54 | + - id: elasticsearch |
| 55 | + - id: ecctl |
| 56 | +""" |
| 57 | + |
| 58 | + static let markdownWithoutProducts = Setup.Document """ |
| 59 | +# Test Page |
| 60 | +
|
| 61 | +This is a test page without products frontmatter. |
| 62 | +""" |
| 63 | + |
| 64 | + [<Fact>] |
| 65 | + let ``includes products in frontmatter when products are specified`` () = |
| 66 | + // Test that the products frontmatter is correctly processed by checking the file |
| 67 | + let results = markdownWithProducts.Value |
| 68 | + let defaultFile = results.MarkdownResults |> Seq.find (fun r -> r.File.RelativePath = "index.md") |
| 69 | + |
| 70 | + // Test that the file has the correct products |
| 71 | + test <@ defaultFile.File.YamlFrontMatter <> null @> |
| 72 | + test <@ defaultFile.File.YamlFrontMatter.Products <> null @> |
| 73 | + test <@ defaultFile.File.YamlFrontMatter.Products.Count = 2 @> |
| 74 | + |
| 75 | + // Test that the products are correctly identified |
| 76 | + let productIds = defaultFile.File.YamlFrontMatter.Products |> Seq.map (fun p -> p.Id) |> Set.ofSeq |
| 77 | + test <@ productIds.Contains("elasticsearch") @> |
| 78 | + test <@ productIds.Contains("ecctl") @> |
| 79 | + |
| 80 | + [<Fact>] |
| 81 | + let ``does not include products in frontmatter when no products are specified`` () = |
| 82 | + // Test that pages without products frontmatter don't have products |
| 83 | + let results = markdownWithoutProducts.Value |
| 84 | + let defaultFile = results.MarkdownResults |> Seq.find (fun r -> r.File.RelativePath = "index.md") |
| 85 | + |
| 86 | + // Test that the file has no products |
| 87 | + test <@ defaultFile.File.YamlFrontMatter = null || defaultFile.File.YamlFrontMatter.Products = null || defaultFile.File.YamlFrontMatter.Products.Count = 0 @> |
0 commit comments