mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-28 08:46:44 +00:00
More test stuff
This commit is contained in:
@@ -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"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -31,7 +31,7 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWith(
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("Test.txt");
|
||||
@@ -52,7 +52,7 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWith(
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("bird-thumbnail.png");
|
||||
@@ -73,7 +73,7 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWith(
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP4_640_3MG.mp4");
|
||||
@@ -94,7 +94,7 @@ public class AttachmentSpecs : IClassFixture<ExportWrapperFixture>
|
||||
|
||||
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||
attachments.Should().HaveCount(1);
|
||||
attachments.Single().GetProperty("url").GetString().Should().StartWith(
|
||||
attachments.Single().GetProperty("url").GetString().Should().Be(
|
||||
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
|
||||
);
|
||||
attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP3_1MG.mp3");
|
||||
|
||||
@@ -33,7 +33,8 @@ public class MentionSpecs : IClassFixture<ExportWrapperFixture>
|
||||
.GetProperty("mentions")
|
||||
.EnumerateArray()
|
||||
.Select(j => j.GetProperty("id").GetString())
|
||||
.Should().Contain("128178626683338752");
|
||||
.Should()
|
||||
.Contain("128178626683338752");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -22,7 +22,7 @@ public class PartitioningSpecs : IClassFixture<TempOutputFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_partitioned_by_count_are_split_into_multiple_files_correctly()
|
||||
public async Task Messages_partitioned_by_count_are_split_into_a_corresponding_number_of_files()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
@@ -46,7 +46,7 @@ public class PartitioningSpecs : IClassFixture<TempOutputFixture>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Messages_partitioned_by_file_size_are_split_into_multiple_files_correctly()
|
||||
public async Task Messages_partitioned_by_file_size_are_split_into_a_corresponding_number_of_files()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = _tempOutput.GetTempFilePath();
|
||||
|
||||
Reference in New Issue
Block a user