diff options
author | crupest <crupest@outlook.com> | 2021-03-06 22:51:53 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-03-06 22:51:53 +0800 |
commit | 890fef4f276ec44312eb936583adbbf47d7cfe9d (patch) | |
tree | 246541d65473634839d5536b1111f7b742f54dab /BackEnd/Timeline.Tests | |
parent | 5c0d0645fd2c1bfb51069d6f9079db32493f2956 (diff) | |
download | timeline-890fef4f276ec44312eb936583adbbf47d7cfe9d.tar.gz timeline-890fef4f276ec44312eb936583adbbf47d7cfe9d.tar.bz2 timeline-890fef4f276ec44312eb936583adbbf47d7cfe9d.zip |
feat: Auto translate url in markdown post.
Diffstat (limited to 'BackEnd/Timeline.Tests')
-rw-r--r-- | BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs | 32 | ||||
-rw-r--r-- | BackEnd/Timeline.Tests/packages.lock.json | 6 |
2 files changed, 38 insertions, 0 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs index b91de6c2..f00d9b13 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs @@ -14,6 +14,7 @@ using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Formats.Jpeg;
using System.Net;
+using System.Text.RegularExpressions;
namespace Timeline.Tests.IntegratedTests
{
@@ -36,6 +37,23 @@ namespace Timeline.Tests.IntegratedTests };
}
+ private static HttpTimelinePostCreateRequest CreateMarkdownPostRequest(string text, DateTime? time = null, string? color = null)
+ {
+ return new HttpTimelinePostCreateRequest()
+ {
+ Time = time,
+ Color = color,
+ DataList = new List<HttpTimelinePostCreateRequestData>()
+ {
+ new HttpTimelinePostCreateRequestData()
+ {
+ ContentType = MimeTypes.TextMarkdown,
+ Data = Convert.ToBase64String(Encoding.UTF8.GetBytes(text))
+ }
+ }
+ };
+ }
+
private readonly ITestOutputHelper _outputHelper;
public TimelinePostTest(ITestOutputHelper outputHelper)
@@ -586,5 +604,19 @@ namespace Timeline.Tests.IntegratedTests post2.Editable.Should().BeFalse();
}
}
+
+ [Theory]
+ [MemberData(nameof(TimelineNameGeneratorTestData))]
+ public async Task Post_Markdown_Url_Map(TimelineNameGenerator generator)
+ {
+ using var client = await CreateClientAsUser();
+ var post = await client.TestPostAsync<HttpTimelinePost>($"timelines/{generator(1)}/posts", CreateMarkdownPostRequest("[aaa](1) "));
+
+ var res = await client.GetAsync($"timelines/{generator(1)}/posts/{post.Id}/data");
+ var markdown = await res.Content.ReadAsStringAsync();
+
+ markdown.Should().MatchRegex(@$"\[aaa\]\(https?://.*/timelines/{generator(1)}/posts/{post.Id}/data/1\)");
+ markdown.Should().MatchRegex(@$"\[bbb\]\(https?://.*/timelines/{generator(1)}/posts/{post.Id}/data/2\)");
+ }
}
}
diff --git a/BackEnd/Timeline.Tests/packages.lock.json b/BackEnd/Timeline.Tests/packages.lock.json index 50b90c3c..bdcfaf35 100644 --- a/BackEnd/Timeline.Tests/packages.lock.json +++ b/BackEnd/Timeline.Tests/packages.lock.json @@ -127,6 +127,11 @@ "System.Xml.XmlDocument": "4.3.0"
}
},
+ "Markdig": {
+ "type": "Transitive",
+ "resolved": "0.23.0",
+ "contentHash": "jPPcnHGSDSedPvwZ6jiMJpvK3iJGA2djU6TFmEr6XK2BiYK1ier2lTHVwDt41XLxDbfGu5Dn42hKDzwqs049PA=="
+ },
"Microsoft.AspNetCore.Authorization": {
"type": "Transitive",
"resolved": "1.0.3",
@@ -1981,6 +1986,7 @@ "dependencies": {
"AutoMapper": "10.1.1",
"AutoMapper.Extensions.Microsoft.DependencyInjection": "8.1.0",
+ "Markdig": "0.23.0",
"Microsoft.AspNetCore.SpaServices.Extensions": "5.0.0",
"Microsoft.EntityFrameworkCore": "5.0.0",
"Microsoft.EntityFrameworkCore.Analyzers": "5.0.0",
|