Files
LlamaCasty/ytLive.Tests/LogsPanelTests.cs
T
gramps 9fa06c67c2 feat(ui): add current-launch logs tab
Add Live Chat and Logs tabs to the non-edit left panel. Expose a bounded process-local AppLog feed so the newest messages appear first without importing earlier startup.log contents or changing file logging.

Ref: https://obsproject.com/forum/resources/understanding-obs-studio-log.473
2026-11-02 11:06:43 -08:00

85 lines
3.4 KiB
C#

using System;
using System.IO;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using Microsoft.Data.Sqlite;
using Xunit;
using ytLive.Helpers;
using ytLive.ViewModels;
namespace ytLive.Tests;
[Collection("RealApp")]
public sealed class LogsPanelTests
{
private readonly RealAppHost _app;
public LogsPanelTests(RealAppHost app) => _app = app;
[Fact]
public void NonEditPanel_DefaultsToLiveChat_AndShowsCurrentLaunchLogsNewestFirst()
{
var directory = Path.Combine(Path.GetTempPath(), $"ytlive-logs-panel-{Guid.NewGuid():N}");
Directory.CreateDirectory(directory);
var databasePath = Path.Combine(directory, "layout.db");
var logPath = Path.Combine(directory, "startup.log");
File.WriteAllText(logPath, "previous-launch-sentinel" + Environment.NewLine);
AppLog.PathOverride = logPath;
MainViewModel.LayoutPathOverride = databasePath;
try
{
_app.Run(() =>
{
var window = new MainWindow();
try
{
window.Show();
window.UpdateLayout();
var vm = (MainViewModel)window.DataContext;
var panel = (UserControl)window.FindName("LeftPanel")!;
var chatTab = (ToggleButton)panel.FindName("LiveChatTabButton")!;
var logsTab = (ToggleButton)panel.FindName("LogsTabButton")!;
var logList = (ListBox)panel.FindName("LogListBox")!;
Assert.True(vm.IsLiveChatTabSelected);
Assert.True(chatTab.IsChecked);
Assert.False(logsTab.IsChecked);
Assert.Equal(System.Windows.Visibility.Collapsed, logList.Visibility);
vm.IsLogsTabSelected = true;
window.UpdateLayout();
Assert.True(logsTab.IsChecked);
Assert.False(chatTab.IsChecked);
Assert.Equal(System.Windows.Visibility.Visible, logList.Visibility);
AppLog.Write("LogsPanel older marker");
AppLog.Write("LogsPanel newer marker");
vm.RefreshCurrentLaunchLogs();
window.UpdateLayout();
var entries = vm.CurrentLaunchLogEntries.Select(entry => entry.Text).ToArray();
var newerIndex = Array.FindIndex(entries, text => text.Contains("LogsPanel newer marker", StringComparison.Ordinal));
var olderIndex = Array.FindIndex(entries, text => text.Contains("LogsPanel older marker", StringComparison.Ordinal));
Assert.True(newerIndex >= 0 && olderIndex >= 0, "new log writes did not reach the Logs tab");
Assert.True(newerIndex < olderIndex, "the Logs tab must put the newest entry first");
Assert.DoesNotContain(entries, text => text.Contains("previous-launch-sentinel", StringComparison.Ordinal));
Assert.Same(vm.CurrentLaunchLogEntries, logList.ItemsSource);
}
finally
{
window.Close();
}
});
}
finally
{
MainViewModel.LayoutPathOverride = null;
AppLog.PathOverride = null;
SqliteConnection.ClearAllPools();
try { Directory.Delete(directory, recursive: true); } catch { }
}
}
}