A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

147 lines
4.3 KiB

using System.Linq;
using Avalonia.Controls.Notifications;
using Avalonia.UnitTests;
using Xunit;
using Notification = Avalonia.Controls.Notifications.Notification;
namespace Avalonia.Controls.UnitTests
{
public class WindowNotificationManagerTests : ScopedTestBase
{
[Fact]
public void Show_Notifications_With_Same_String()
{
WindowNotificationManager manager = new();
manager.Show("Notification text");
manager.Show("Notification text");
manager.Show("Notification text");
Assert.Equal(3, manager.Notifications.Count());
}
[Fact]
public void Show_And_Close_Notification()
{
WindowNotificationManager manager = new();
manager.Show("Notification text");
Assert.Equal(1, manager.Notifications.Count());
manager.Close("Notification text");
Assert.True(!manager.Notifications.Any(x => !x.IsClosing));
}
[Fact]
public void Show_And_Close_All_Notifications()
{
WindowNotificationManager manager = new();
manager.Show("Notification 1");
manager.Show("Notification 2");
Assert.Equal(2, manager.Notifications.Count());
manager.CloseAll();
Assert.True(!manager.Notifications.Any(x => !x.IsClosing));
}
}
public class INotificationManagerTests : ScopedTestBase
{
[Fact]
public void Show_Notifications_With_Same_Content()
{
INotificationManager manager = new WindowNotificationManager();
Notification notification = new()
{
Message = "Notification text"
};
manager.Show(notification);
manager.Show(notification);
manager.Show(notification);
Assert.Equal(3, ((WindowNotificationManager)manager).Notifications.Count());
}
[Fact]
public void Show_And_Close_Notification()
{
INotificationManager manager = new WindowNotificationManager();
Notification notification = new()
{
Message = "Notification text"
};
manager.Show(notification);
Assert.Equal(1, ((WindowNotificationManager)manager).Notifications.Count());
manager.Close(notification);
Assert.True(!((WindowNotificationManager)manager).Notifications.Any(x => !x.IsClosing));
}
[Fact]
public void Show_And_Close_All_Notifications()
{
INotificationManager manager = new WindowNotificationManager();
Notification notification1 = new()
{
Message = "Notification text"
};
Notification notification2 = new()
{
Message = "Notification text"
};
manager.Show(notification1);
manager.Show(notification2);
Assert.Equal(2, ((WindowNotificationManager)manager).Notifications.Count());
manager.CloseAll();
Assert.True(!((WindowNotificationManager)manager).Notifications.Any(x => !x.IsClosing));
}
}
public class NotificationCardTests : ScopedTestBase
{
[Fact]
public void Should_Update_Pseudoclasses_When_NotificationType_Changes()
{
var target = new NotificationCard();
target.NotificationType = NotificationType.Error;
AssertPseudoClasses(target, ":error");
target.NotificationType = NotificationType.Information;
AssertPseudoClasses(target, ":information");
target.NotificationType = NotificationType.Success;
AssertPseudoClasses(target, ":success");
target.NotificationType = NotificationType.Warning;
AssertPseudoClasses(target, ":warning");
static void AssertPseudoClasses(NotificationCard target, string expected)
{
Assert.Contains(expected, target.Classes);
foreach (var pseudoclass in new[] { ":error", ":information", ":success", ":warning" }.Where(x => x != expected))
{
Assert.DoesNotContain(pseudoclass, target.Classes);
}
}
}
}
}