aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline.Tests
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-03-06 22:51:53 +0800
committercrupest <crupest@outlook.com>2021-03-06 22:51:53 +0800
commit8f09e3172f249a9f5d229040415a0569e9d1c01b (patch)
tree59507331750831118e7caa071a10e1cb8fc1e627 /BackEnd/Timeline.Tests
parent24c272403ba360f27acd68c2702c678a86063964 (diff)
downloadtimeline-8f09e3172f249a9f5d229040415a0569e9d1c01b.tar.gz
timeline-8f09e3172f249a9f5d229040415a0569e9d1c01b.tar.bz2
timeline-8f09e3172f249a9f5d229040415a0569e9d1c01b.zip
feat: Auto translate url in markdown post.
Diffstat (limited to 'BackEnd/Timeline.Tests')
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs32
-rw-r--r--BackEnd/Timeline.Tests/packages.lock.json6
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) ![bbb](2)"));
+
+ 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",