|
11 | 11 | namespace Elastic.Markdown.Tests.Inline; |
12 | 12 |
|
13 | 13 | public abstract class LinkTestBase(ITestOutputHelper output, [LanguageInjection("markdown")] string content) |
14 | | - : InlineTest<LinkInline>(output, content) |
| 14 | + : InlineTest<LinkInline>( |
| 15 | + output, |
| 16 | + content, |
| 17 | + new Dictionary<string, string> |
| 18 | + { |
| 19 | + { "some-url-with-a-version", "https://github.com/elastic/fake-repo/tree/v1.17.0" }, |
| 20 | + { "some-url-path-prefix", "/something" }, |
| 21 | + } |
| 22 | + ) |
15 | 23 | { |
16 | 24 | [Fact] |
17 | 25 | public void ParsesBlock() => Block.Should().NotBeNull(); |
@@ -161,28 +169,59 @@ public void EmitsCrossLink() |
161 | 169 | } |
162 | 170 | } |
163 | 171 |
|
164 | | -public class LinksWithInterpolationWarning(ITestOutputHelper output) : LinkTestBase(output, |
| 172 | +public class LinkWithUnresolvedInterpolationError(ITestOutputHelper output) : LinkTestBase(output, |
165 | 173 | """ |
166 | | - [global search field]({{kibana-ref}}/introduction.html#kibana-navigation-search) |
| 174 | + [global search field]({{this-variable-does-not-exist}}/introduction.html#kibana-navigation-search) |
| 175 | + """ |
| 176 | +) |
| 177 | +{ |
| 178 | + [Fact] |
| 179 | + public void HasErrors() |
| 180 | + { |
| 181 | + Collector.Diagnostics.Should().HaveCount(1); |
| 182 | + Collector.Diagnostics.First().Severity.Should().Be(Severity.Error); |
| 183 | + Collector.Diagnostics.First().Message.Should().Contain("he url contains unresolved template expressions: '{{this-variable-does-not-exist}}/introduction.html#kibana-navigation-search'. Please check if there is an appropriate global or frontmatter subs variable."); |
| 184 | + } |
| 185 | +} |
| 186 | + |
| 187 | +public class ExternalLinksWithInterpolationSuccess(ITestOutputHelper output) : LinkTestBase(output, |
| 188 | + """ |
| 189 | + [link to app]({{some-url-with-a-version}}) |
167 | 190 | """ |
168 | 191 | ) |
169 | 192 | { |
170 | 193 | [Fact] |
171 | 194 | public void GeneratesHtml() => |
172 | 195 | // language=html |
173 | 196 | Html.Should().Contain( |
174 | | - """<p><a href="%7B%7Bkibana-ref%7D%7D/introduction.html#kibana-navigation-search">global search field</a></p>""" |
| 197 | + """<p><a href="https://github.com/elastic/fake-repo/tree/v1.17.0">link to app</a></p>""" |
175 | 198 | ); |
176 | 199 |
|
| 200 | + [Fact] |
| 201 | + public void HasNoWarningsOrErrors() |
| 202 | + { |
| 203 | + Collector.Diagnostics.Should().HaveCount(0); |
| 204 | + } |
| 205 | +} |
| 206 | + |
| 207 | +public class InternalLinksWithInterpolationWarning(ITestOutputHelper output) : LinkTestBase(output, |
| 208 | + """ |
| 209 | + [link to app]({{some-url-path-prefix}}/hello-world) |
| 210 | + """ |
| 211 | +) |
| 212 | +{ |
177 | 213 | [Fact] |
178 | 214 | public void HasWarnings() |
179 | 215 | { |
180 | 216 | Collector.Diagnostics.Should().HaveCount(1); |
181 | | - Collector.Diagnostics.First().Severity.Should().Be(Severity.Warning); |
182 | | - Collector.Diagnostics.First().Message.Should().Contain("The url contains a template expression. Please do not use template expressions in links. See https://github.com/elastic/docs-builder/issues/182 for further information."); |
| 217 | + Collector.Diagnostics.First().Severity.Should().Be(Severity.Error); |
| 218 | + Collector.Diagnostics.First().Message.Should().Contain("Link is resolved to '/something/hello-world'. Only external links are allowed to be resolved from template expressions."); |
183 | 219 | } |
184 | 220 | } |
185 | 221 |
|
| 222 | + |
| 223 | + |
| 224 | + |
186 | 225 | public class NonExistingLinks(ITestOutputHelper output) : LinkTestBase(output, |
187 | 226 | """ |
188 | 227 | [Non Existing Link](/non-existing.md) |
|
0 commit comments