mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-29 05:55:21 -04:00
More tests
This commit is contained in:
parent
d735d2acd3
commit
ec0494c038
4 changed files with 201 additions and 6 deletions
62
DiscordChatExporter.Cli.Tests/EmbedSpecs.cs
Normal file
62
DiscordChatExporter.Cli.Tests/EmbedSpecs.cs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
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.Discord;
|
||||||
|
using DiscordChatExporter.Core.Exporting;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Cli.Tests
|
||||||
|
{
|
||||||
|
public class EmbedSpecs : IClassFixture<TempOutputFixture>
|
||||||
|
{
|
||||||
|
private readonly ITestOutputHelper _testOutput;
|
||||||
|
private readonly TempOutputFixture _tempOutput;
|
||||||
|
|
||||||
|
public EmbedSpecs(ITestOutputHelper testOutput, TempOutputFixture tempOutput)
|
||||||
|
{
|
||||||
|
_testOutput = testOutput;
|
||||||
|
_tempOutput = tempOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_YouTube_video_is_rendered_with_a_player_in_HTML()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var htmlData = await GlobalCache.WrapAsync("embed-specs-output-html", async () =>
|
||||||
|
{
|
||||||
|
await new ExportChannelsCommand
|
||||||
|
{
|
||||||
|
TokenValue = Secrets.DiscordToken,
|
||||||
|
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||||
|
ChannelIds = new[] {Snowflake.Parse(ChannelIds.EmbedTestCases)},
|
||||||
|
ExportFormat = ExportFormat.HtmlDark,
|
||||||
|
OutputPath = outputFilePath
|
||||||
|
}.ExecuteAsync(new FakeConsole());
|
||||||
|
|
||||||
|
return await File.ReadAllTextAsync(outputFilePath);
|
||||||
|
});
|
||||||
|
|
||||||
|
_testOutput.WriteLine(htmlData);
|
||||||
|
|
||||||
|
var html = Html.Parse(htmlData);
|
||||||
|
|
||||||
|
var messageHtml = html.QuerySelector("#message-866472508588294165");
|
||||||
|
var iframeHtml = messageHtml?.QuerySelector("iframe");
|
||||||
|
var iframeSrc = iframeHtml?.GetAttribute("src");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
iframeHtml.Should().NotBeNull();
|
||||||
|
iframeSrc.Should().StartWithEquivalent("https://www.youtube.com/embed/qOWW4OlgbvE");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -103,7 +103,7 @@ namespace DiscordChatExporter.Cli.Tests
|
||||||
|
|
||||||
var html = Html.Parse(htmlData);
|
var html = Html.Parse(htmlData);
|
||||||
|
|
||||||
var messageHtml = html.GetElementById("message-866458840245076028");
|
var messageHtml = html.QuerySelector("#message-866458840245076028");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
messageHtml.Should().NotBeNull();
|
messageHtml.Should().NotBeNull();
|
||||||
|
@ -178,7 +178,7 @@ namespace DiscordChatExporter.Cli.Tests
|
||||||
|
|
||||||
var html = Html.Parse(htmlData);
|
var html = Html.Parse(htmlData);
|
||||||
|
|
||||||
var messageHtml = html.GetElementById("message-866459040480624680");
|
var messageHtml = html.QuerySelector("#message-866459040480624680");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
messageHtml.Should().NotBeNull();
|
messageHtml.Should().NotBeNull();
|
||||||
|
@ -252,7 +252,7 @@ namespace DiscordChatExporter.Cli.Tests
|
||||||
|
|
||||||
var html = Html.Parse(htmlData);
|
var html = Html.Parse(htmlData);
|
||||||
|
|
||||||
var messageHtml = html.GetElementById("message-866459175462633503");
|
var messageHtml = html.QuerySelector("#message-866459175462633503");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
messageHtml.Should().NotBeNull();
|
messageHtml.Should().NotBeNull();
|
||||||
|
@ -326,7 +326,7 @@ namespace DiscordChatExporter.Cli.Tests
|
||||||
|
|
||||||
var html = Html.Parse(htmlData);
|
var html = Html.Parse(htmlData);
|
||||||
|
|
||||||
var messageHtml = html.GetElementById("message-866459254693429258");
|
var messageHtml = html.QuerySelector("#message-866459254693429258");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
messageHtml.Should().NotBeNull();
|
messageHtml.Should().NotBeNull();
|
||||||
|
|
131
DiscordChatExporter.Cli.Tests/ReplySpecs.cs
Normal file
131
DiscordChatExporter.Cli.Tests/ReplySpecs.cs
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
using System.IO;
|
||||||
|
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.Discord;
|
||||||
|
using DiscordChatExporter.Core.Exporting;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Cli.Tests
|
||||||
|
{
|
||||||
|
public class ReplySpecs : IClassFixture<TempOutputFixture>
|
||||||
|
{
|
||||||
|
private readonly ITestOutputHelper _testOutput;
|
||||||
|
private readonly TempOutputFixture _tempOutput;
|
||||||
|
|
||||||
|
public ReplySpecs(ITestOutputHelper testOutput, TempOutputFixture tempOutput)
|
||||||
|
{
|
||||||
|
_testOutput = testOutput;
|
||||||
|
_tempOutput = tempOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Reply_to_a_normal_message_is_rendered_correctly_in_HTML()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var htmlData = await GlobalCache.WrapAsync("reply-specs-output-html", async () =>
|
||||||
|
{
|
||||||
|
await new ExportChannelsCommand
|
||||||
|
{
|
||||||
|
TokenValue = Secrets.DiscordToken,
|
||||||
|
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||||
|
ChannelIds = new[] {Snowflake.Parse(ChannelIds.ReplyTestCases)},
|
||||||
|
ExportFormat = ExportFormat.HtmlDark,
|
||||||
|
OutputPath = outputFilePath
|
||||||
|
}.ExecuteAsync(new FakeConsole());
|
||||||
|
|
||||||
|
return await File.ReadAllTextAsync(outputFilePath);
|
||||||
|
});
|
||||||
|
|
||||||
|
_testOutput.WriteLine(htmlData);
|
||||||
|
|
||||||
|
var html = Html.Parse(htmlData);
|
||||||
|
|
||||||
|
var messageHtml = html.QuerySelector("#message-866460738239725598");
|
||||||
|
var referenceHtml = messageHtml?.QuerySelector(".chatlog__reference-link");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
messageHtml.Should().NotBeNull();
|
||||||
|
messageHtml?.Text().Trim().Should().Be("reply to original");
|
||||||
|
referenceHtml?.Text().Trim().Should().Be("original");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Reply_to_a_deleted_message_is_rendered_correctly_in_HTML()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var htmlData = await GlobalCache.WrapAsync("reply-specs-output-html", async () =>
|
||||||
|
{
|
||||||
|
await new ExportChannelsCommand
|
||||||
|
{
|
||||||
|
TokenValue = Secrets.DiscordToken,
|
||||||
|
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||||
|
ChannelIds = new[] {Snowflake.Parse(ChannelIds.ReplyTestCases)},
|
||||||
|
ExportFormat = ExportFormat.HtmlDark,
|
||||||
|
OutputPath = outputFilePath
|
||||||
|
}.ExecuteAsync(new FakeConsole());
|
||||||
|
|
||||||
|
return await File.ReadAllTextAsync(outputFilePath);
|
||||||
|
});
|
||||||
|
|
||||||
|
_testOutput.WriteLine(htmlData);
|
||||||
|
|
||||||
|
var html = Html.Parse(htmlData);
|
||||||
|
|
||||||
|
var messageHtml = html.QuerySelector("#message-866460975388819486");
|
||||||
|
var referenceHtml = messageHtml?.QuerySelector(".chatlog__reference-link");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
messageHtml.Should().NotBeNull();
|
||||||
|
messageHtml?.Text().Trim().Should().Be("reply to deleted");
|
||||||
|
referenceHtml?.Text().Trim().Should().Be("Original message was deleted or could not be loaded.");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Reply_to_a_empty_message_with_attachment_is_rendered_correctly_in_HTML()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var outputFilePath = Path.ChangeExtension(_tempOutput.GetTempFilePath(), "html");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var htmlData = await GlobalCache.WrapAsync("reply-specs-output-html", async () =>
|
||||||
|
{
|
||||||
|
await new ExportChannelsCommand
|
||||||
|
{
|
||||||
|
TokenValue = Secrets.DiscordToken,
|
||||||
|
IsBotToken = Secrets.IsDiscordTokenBot,
|
||||||
|
ChannelIds = new[] {Snowflake.Parse(ChannelIds.ReplyTestCases)},
|
||||||
|
ExportFormat = ExportFormat.HtmlDark,
|
||||||
|
OutputPath = outputFilePath
|
||||||
|
}.ExecuteAsync(new FakeConsole());
|
||||||
|
|
||||||
|
return await File.ReadAllTextAsync(outputFilePath);
|
||||||
|
});
|
||||||
|
|
||||||
|
_testOutput.WriteLine(htmlData);
|
||||||
|
|
||||||
|
var html = Html.Parse(htmlData);
|
||||||
|
|
||||||
|
var messageHtml = html.QuerySelector("#message-866462470335627294");
|
||||||
|
var referenceHtml = messageHtml?.QuerySelector(".chatlog__reference-link");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
messageHtml.Should().NotBeNull();
|
||||||
|
messageHtml?.Text().Trim().Should().Be("reply to attachment");
|
||||||
|
referenceHtml?.Text().Trim().Should().Be("Click to see attachment 🖼️");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,8 +2,10 @@
|
||||||
{
|
{
|
||||||
public static class ChannelIds
|
public static class ChannelIds
|
||||||
{
|
{
|
||||||
public static string MentionTestCases { get; } = "866458801389174794";
|
public static string EmbedTestCases => "866472452459462687";
|
||||||
|
|
||||||
public static string ReplyTestCases { get; } = "866459871934677052";
|
public static string MentionTestCases => "866458801389174794";
|
||||||
|
|
||||||
|
public static string ReplyTestCases => "866459871934677052";
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue