DiscordChatExporter/DiscordChatExporter.Cli.Tests/Specs/HtmlAttachmentSpecs.cs

96 lines
2.9 KiB
C#
Raw Permalink Normal View History

2023-09-28 12:18:52 -04:00
using System;
using System.Linq;
using System.Threading.Tasks;
2021-09-09 18:55:28 -04:00
using AngleSharp.Dom;
2023-02-11 16:12:15 -05:00
using DiscordChatExporter.Cli.Tests.Infra;
2021-09-09 18:55:28 -04:00
using DiscordChatExporter.Core.Discord;
using FluentAssertions;
using Xunit;
2023-02-06 08:57:08 -05:00
namespace DiscordChatExporter.Cli.Tests.Specs;
2021-12-08 16:50:21 -05:00
public class HtmlAttachmentSpecs
2021-09-09 18:55:28 -04:00
{
2021-12-08 16:50:21 -05:00
[Fact]
2023-05-20 00:09:19 -04:00
public async Task I_can_export_a_channel_that_contains_a_message_with_a_generic_attachment()
2021-12-08 16:50:21 -05:00
{
// Act
2023-02-11 16:12:15 -05:00
var message = await ExportWrapper.GetMessageAsHtmlAsync(
2021-12-08 16:50:21 -05:00
ChannelIds.AttachmentTestCases,
Snowflake.Parse("885587844989612074")
);
// Assert
2023-08-22 14:17:19 -04:00
message.Text().Should().ContainAll("Generic file attachment", "Test.txt", "11 bytes");
2021-12-08 16:50:21 -05:00
message
.QuerySelectorAll("a")
.Select(e => e.GetAttribute("href"))
.Should()
.Contain(u => u.Contains("Test.txt", StringComparison.Ordinal));
2021-12-08 16:50:21 -05:00
}
[Fact]
2023-05-20 00:09:19 -04:00
public async Task I_can_export_a_channel_that_contains_a_message_with_an_image_attachment()
2021-12-08 16:50:21 -05:00
{
// Act
2023-02-11 16:12:15 -05:00
var message = await ExportWrapper.GetMessageAsHtmlAsync(
2021-12-08 16:50:21 -05:00
ChannelIds.AttachmentTestCases,
Snowflake.Parse("885654862656843786")
);
// Assert
message.Text().Should().Contain("Image attachment");
message
.QuerySelectorAll("img")
.Select(e => e.GetAttribute("src"))
.Should()
.Contain(u => u.Contains("bird-thumbnail.png", StringComparison.Ordinal));
2021-12-08 16:50:21 -05:00
}
[Fact]
2023-05-20 00:09:19 -04:00
public async Task I_can_export_a_channel_that_contains_a_message_with_a_video_attachment()
2021-09-09 18:55:28 -04:00
{
2022-06-30 12:07:11 -04:00
// https://github.com/Tyrrrz/DiscordChatExporter/issues/333
2021-12-08 16:50:21 -05:00
// Act
2023-02-11 16:12:15 -05:00
var message = await ExportWrapper.GetMessageAsHtmlAsync(
2021-12-08 16:50:21 -05:00
ChannelIds.AttachmentTestCases,
Snowflake.Parse("885655761919836171")
);
// Assert
message.Text().Should().Contain("Video attachment");
var videoUrl = message.QuerySelector("video source")?.GetAttribute("src");
2023-08-22 14:17:19 -04:00
videoUrl
.Should()
2023-09-28 12:18:52 -04:00
.StartWith(
2023-08-22 14:17:19 -04:00
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
);
2021-12-08 16:50:21 -05:00
}
[Fact]
2023-05-20 00:09:19 -04:00
public async Task I_can_export_a_channel_that_contains_a_message_with_an_audio_attachment()
2021-12-08 16:50:21 -05:00
{
2022-06-30 12:07:11 -04:00
// https://github.com/Tyrrrz/DiscordChatExporter/issues/333
2021-12-08 16:50:21 -05:00
// Act
2023-02-11 16:12:15 -05:00
var message = await ExportWrapper.GetMessageAsHtmlAsync(
2021-12-08 16:50:21 -05:00
ChannelIds.AttachmentTestCases,
Snowflake.Parse("885656175620808734")
);
// Assert
message.Text().Should().Contain("Audio attachment");
var audioUrl = message.QuerySelector("audio source")?.GetAttribute("src");
2023-08-22 14:17:19 -04:00
audioUrl
.Should()
2023-09-28 12:18:52 -04:00
.StartWith(
2023-08-22 14:17:19 -04:00
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
);
2021-09-09 18:55:28 -04:00
}
2023-08-22 14:17:19 -04:00
}