using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using CursorLang.Interop;
using CursorLang.Services;
using CursorLang.Tests.Infrastructure;
namespace CursorLang.Tests.Services;
///
/// The icon in the notification area and its menu — the whole interface of an
/// application that works in the background.
///
///
/// The icon needs a window of its own, so the checks run on the interface thread.
/// Whether the tray accepts the icon is up to Windows: there is no notification area
/// in a session without a desktop, and such a check skips itself.
///
public sealed class TrayIconTests
{
[Fact]
public void The_icon_ends_up_in_the_notification_area()
{
Sta.Run(() =>
{
using var tray = new TrayIcon(new FakeLocalizationService());
if (!tray.Install())
{
Assert.Skip("Windows did not take the icon — there is no notification area here");
}
// Asking twice changes nothing: a second icon of the same
// application in the tray is not what anyone wants
Assert.True(tray.Install());
});
}
[Fact]
public void The_icon_is_taken_away_on_the_way_out()
{
Sta.Run(() =>
{
var tray = new TrayIcon(new FakeLocalizationService());
tray.Install();
tray.Dispose();
// A second disposal is what the container does after the application
// has already shut the tray down itself
tray.Dispose();
});
}
[Fact]
public void The_menu_offers_the_settings_and_the_way_out()
{
Sta.Run(() =>
{
using var tray = new TrayIcon(new FakeLocalizationService());
List