diff --git a/DiscordChatExporter.Cli.Tests/Infra/ChannelIds.cs b/DiscordChatExporter.Cli.Tests/Infra/ChannelIds.cs index 9941c36e..e9b2b4ba 100644 --- a/DiscordChatExporter.Cli.Tests/Infra/ChannelIds.cs +++ b/DiscordChatExporter.Cli.Tests/Infra/ChannelIds.cs @@ -22,6 +22,8 @@ public static class ChannelIds public static Snowflake MentionTestCases { get; } = Snowflake.Parse("866458801389174794"); + public static Snowflake PollTestCases { get; } = Snowflake.Parse("1296445312759627786"); + public static Snowflake ReplyTestCases { get; } = Snowflake.Parse("866459871934677052"); public static Snowflake SelfContainedTestCases { get; } = Snowflake.Parse("887441432678379560"); diff --git a/DiscordChatExporter.Cli.Tests/Specs/HtmlPollSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/HtmlPollSpecs.cs new file mode 100644 index 00000000..503c78d7 --- /dev/null +++ b/DiscordChatExporter.Cli.Tests/Specs/HtmlPollSpecs.cs @@ -0,0 +1,65 @@ +using System.Linq; +using System.Threading.Tasks; +using AngleSharp.Dom; +using DiscordChatExporter.Cli.Tests.Infra; +using DiscordChatExporter.Core.Discord; +using FluentAssertions; +using PowerKit.Extensions; +using Xunit; + +namespace DiscordChatExporter.Cli.Tests.Specs; + +public class HtmlPollSpecs +{ + [Fact] + public async Task I_can_export_a_channel_that_contains_a_message_with_a_poll() + { + // Act + var message = await ExportWrapper.GetMessageAsHtmlAsync( + ChannelIds.PollTestCases, + Snowflake.Parse("1298034559048487016") + ); + + // Assert + message + .Text() + .Should() + .ContainAll( + "Poll question", + "No emoji", + "1 vote", + "20%", + "Default emoji", + "3 votes", + "60%", + "Custom emoji", + "1 vote", + "5 votes" + ); + + message + .QuerySelectorAll("img") + .Select(e => e.GetAttribute("title")) + .Should() + .Contain("heart") + .And.Contain("dce"); + } + + [Fact] + public async Task I_can_export_a_channel_that_contains_a_message_with_a_poll_result() + { + // Act + var message = await ExportWrapper.GetMessageAsHtmlAsync( + ChannelIds.PollTestCases, + Snowflake.Parse("1298396967742996641") + ); + + // Assert + message + .Text() + .Should() + .ContainAll("Poll question", "Default emoji", "Winning answer", "60%"); + + message.Text().ReplaceWhiteSpace(' ').Should().Contain("10/22/2024 9:26 PM"); + } +}