More test stuff

This commit is contained in:
Oleksii Holub
2022-06-30 19:07:11 +03:00
parent 565fb53d3b
commit 057902f919
9 changed files with 173 additions and 62 deletions

View File

@@ -67,6 +67,8 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
[Fact]
public async Task Message_with_a_video_attachment_is_rendered_correctly()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/333
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.AttachmentTestCases,
@@ -77,7 +79,7 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
message.Text().Should().Contain("Video attachment");
var videoUrl = message.QuerySelector("video source")?.GetAttribute("src");
videoUrl.Should().StartWith(
videoUrl.Should().Be(
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
);
}
@@ -85,6 +87,8 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
[Fact]
public async Task Message_with_an_audio_attachment_is_rendered_correctly()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/333
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.AttachmentTestCases,
@@ -95,7 +99,7 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
message.Text().Should().Contain("Audio attachment");
var audioUrl = message.QuerySelector("audio source")?.GetAttribute("src");
audioUrl.Should().StartWith(
audioUrl.Should().Be(
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
);
}

View File

@@ -42,6 +42,8 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
[Fact]
public async Task Message_containing_an_image_link_is_rendered_with_an_image_embed()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/537
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases,
@@ -59,6 +61,8 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
[Fact]
public async Task Message_containing_an_image_link_and_nothing_else_is_rendered_without_text_content()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/682
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases,
@@ -73,6 +77,8 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
[Fact]
public async Task Message_containing_a_Spotify_track_link_is_rendered_with_a_track_embed()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/657
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases,
@@ -81,12 +87,14 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
// Assert
var iframeUrl = message.QuerySelector("iframe")?.GetAttribute("src");
iframeUrl.Should().StartWith("https://open.spotify.com/embed/track/1LHZMWefF9502NPfArRfvP");
iframeUrl.Should().Be("https://open.spotify.com/embed/track/1LHZMWefF9502NPfArRfvP");
}
[Fact]
public async Task Message_containing_a_YouTube_video_link_is_rendered_with_a_video_embed()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/570
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases,
@@ -95,6 +103,32 @@ public class EmbedSpecs : IClassFixture<ExportWrapperFixture>
// Assert
var iframeUrl = message.QuerySelector("iframe")?.GetAttribute("src");
iframeUrl.Should().StartWith("https://www.youtube.com/embed/qOWW4OlgbvE");
iframeUrl.Should().Be("https://www.youtube.com/embed/qOWW4OlgbvE");
}
[Fact(Skip = "Unimplemented")]
public async Task Message_containing_a_Twitter_post_link_with_multiple_images_is_rendered_as_a_single_embed()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/695
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.EmbedTestCases,
Snowflake.Parse("991757444017557665")
);
// Assert
message
.QuerySelectorAll("img")
.Select(e => e.GetAttribute("src"))
.Should()
.ContainInOrder(
"https://images-ext-1.discordapp.net/external/-n--xW3EHH_3jlrheVkMXHCM7T86b5Ty4-MzXCT4m1Q/https/pbs.twimg.com/media/FVYIzYPWAAAMBqZ.png",
"https://images-ext-2.discordapp.net/external/z5nEmGeEldV-kswydGLhqUsFHbb5AWHtdvc9XT6N5rE/https/pbs.twimg.com/media/FVYJBWJWAAMNAx2.png",
"https://images-ext-2.discordapp.net/external/gnip03SawMB6uZLagN5sRDpA_1Ap1CcEhMbJfK1z6WQ/https/pbs.twimg.com/media/FVYJHiRX0AANZcz.png",
"https://images-ext-2.discordapp.net/external/jl1v6cCbLaGmiwmKU-ZkXnF4cFsJ39f9A3-oEdqPdZs/https/pbs.twimg.com/media/FVYJNZNXwAAPnVG.png"
);
message.QuerySelectorAll(".chatlog__embed").Should().ContainSingle();
}
}

View File

@@ -0,0 +1,79 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AngleSharp.Dom;
using CliFx.Infrastructure;
using DiscordChatExporter.Cli.Commands;
using DiscordChatExporter.Cli.Tests.Fixtures;
using DiscordChatExporter.Cli.Tests.Infra;
using DiscordChatExporter.Cli.Tests.TestData;
using DiscordChatExporter.Cli.Tests.Utils;
using DiscordChatExporter.Core.Exporting;
using FluentAssertions;
using Xunit;
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting;
public class GroupingSpecs : IClassFixture<TempOutputFixture>
{
private readonly TempOutputFixture _tempOutput;
public GroupingSpecs(TempOutputFixture tempOutput)
{
_tempOutput = tempOutput;
}
[Fact]
public async Task Messages_are_grouped_correctly()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/152
// Arrange
var filePath = _tempOutput.GetTempFilePath();
// Act
await new ExportChannelsCommand
{
Token = Secrets.DiscordToken,
ChannelIds = new[] { ChannelIds.GroupingTestCases },
ExportFormat = ExportFormat.HtmlDark,
OutputPath = filePath
}.ExecuteAsync(new FakeConsole());
// Assert
var messageGroups = Html
.Parse(await File.ReadAllTextAsync(filePath))
.QuerySelectorAll(".chatlog__message-group");
messageGroups.Should().HaveCount(2);
messageGroups[0]
.QuerySelectorAll(".chatlog__content")
.Select(e => e.Text())
.Should()
.ContainInOrder(
"First",
"Second",
"Third",
"Fourth",
"Fifth",
"Sixth",
"Seventh",
"Eighth",
"Ninth",
"Tenth"
);
messageGroups[1]
.QuerySelectorAll(".chatlog__content")
.Select(e => e.Text())
.Should()
.ContainInOrder(
"Eleventh",
"Twelveth",
"Thirteenth",
"Fourteenth",
"Fifteenth"
);
}
}

View File

@@ -34,6 +34,8 @@ public class ReplySpecs : IClassFixture<ExportWrapperFixture>
[Fact]
public async Task Reply_to_a_deleted_message_is_rendered_correctly()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/645
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.ReplyTestCases,
@@ -50,6 +52,8 @@ public class ReplySpecs : IClassFixture<ExportWrapperFixture>
[Fact]
public async Task Reply_to_an_empty_message_with_attachment_is_rendered_correctly()
{
// https://github.com/Tyrrrz/DiscordChatExporter/issues/634
// Act
var message = await _exportWrapper.GetMessageAsHtmlAsync(
ChannelIds.ReplyTestCases,