From 890fef4f276ec44312eb936583adbbf47d7cfe9d Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 6 Mar 2021 22:51:53 +0800 Subject: feat: Auto translate url in markdown post. --- .../IntegratedTests/TimelinePostTest.cs | 32 ++++++++++++++++++++++ BackEnd/Timeline.Tests/packages.lock.json | 6 ++++ 2 files changed, 38 insertions(+) (limited to 'BackEnd/Timeline.Tests') 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() + { + 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($"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", -- cgit v1.2.3