Extracts the clipboard bitmap read into a shared ClipboardBitmap helper (also used by the terminal view); the description TextBox now routes an image paste through AddFilesAsync as a unique paste-*.png attachment. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
using ClaudeDo.Ui.Services;
|
|
|
|
namespace ClaudeDo.Ui.Tests.Services;
|
|
|
|
public class ClipboardImageTempStoreTests : IDisposable
|
|
{
|
|
private readonly string _dir;
|
|
|
|
public ClipboardImageTempStoreTests()
|
|
{
|
|
_dir = Path.Combine(Path.GetTempPath(), "ClaudeDo.Ui.Tests-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(_dir);
|
|
}
|
|
|
|
public void Dispose() { try { Directory.Delete(_dir, true); } catch { } }
|
|
|
|
[Fact]
|
|
public void NewPngPath_IsUniqueAndUnderTheGivenDir()
|
|
{
|
|
var now = new DateTime(2026, 9, 16, 10, 30, 0, DateTimeKind.Utc);
|
|
|
|
var a = ClipboardImageTempStore.NewPngPath(_dir, now);
|
|
var b = ClipboardImageTempStore.NewPngPath(_dir, now);
|
|
|
|
Assert.NotEqual(a, b);
|
|
Assert.Equal(_dir, Path.GetDirectoryName(a));
|
|
Assert.Equal(".png", Path.GetExtension(a));
|
|
}
|
|
|
|
[Fact]
|
|
public void NewPngFileName_IsUniquePasteNameWithoutDirectory()
|
|
{
|
|
var now = new DateTime(2026, 9, 16, 10, 30, 0, 123, DateTimeKind.Utc);
|
|
|
|
var a = ClipboardImageTempStore.NewPngFileName(now);
|
|
var b = ClipboardImageTempStore.NewPngFileName(now);
|
|
|
|
Assert.NotEqual(a, b);
|
|
Assert.StartsWith("paste-20260916-103000123-", a);
|
|
Assert.EndsWith(".png", a);
|
|
Assert.Equal(a, Path.GetFileName(a));
|
|
}
|
|
|
|
[Fact]
|
|
public void DeleteOlderThan_RemovesOnlyFilesPastTheMaxAge()
|
|
{
|
|
var now = DateTime.UtcNow;
|
|
var oldFile = Path.Combine(_dir, "old.png");
|
|
var freshFile = Path.Combine(_dir, "fresh.png");
|
|
File.WriteAllText(oldFile, "x");
|
|
File.WriteAllText(freshFile, "x");
|
|
File.SetLastWriteTimeUtc(oldFile, now - TimeSpan.FromHours(25));
|
|
File.SetLastWriteTimeUtc(freshFile, now - TimeSpan.FromHours(1));
|
|
|
|
ClipboardImageTempStore.DeleteOlderThan(_dir, TimeSpan.FromHours(24), now);
|
|
|
|
Assert.False(File.Exists(oldFile));
|
|
Assert.True(File.Exists(freshFile));
|
|
}
|
|
|
|
[Fact]
|
|
public void DeleteOlderThan_NonExistentDir_DoesNotThrow()
|
|
{
|
|
ClipboardImageTempStore.DeleteOlderThan(Path.Combine(_dir, "missing"), TimeSpan.FromHours(24), DateTime.UtcNow);
|
|
}
|
|
}
|