Files
Nexus.Reader/tests/NexusReader.Application.Tests/Services/AutosaveEngineTests.cs
T
Antigravity c94e8f0acb feat(creator): overhaul Creator flow, editor duplication, and staging setup (#83)
This pull request completely overhauls the Creator editor flow, resolves the editor duplication race condition, aligns layout/styling themes in light and dark mode, and adds Docker staging setups.

### Key Changes
1. **Creator Flow Polish**: Redesigned the editor canvas to prevent double scrolling by delegating overflow to the editor canvas layer, updated styles to a premium aesthetic.
2. **Race Condition Prevention**: Resolved Crepe editor duplication when loading or switching chapters by tracking state via shared window maps (`window.editorCache`, `window.editorStates`) and checking `_lastInitializedEditorId` synchronously in Blazor.
3. **Theme Synchronization**: Integrated explicit theme initialization (`ThemeService.InitializeAsync()`) and anchored CSS isolation selectors to correctly sync with Light (Soft Sepia) and Deep Dark theme preferences.
4. **Staging Automation**: Created staging docker configurations with `--nexus-only` flag to allow iterative development without resetting PG/Neo4j database containers.

---------

Co-authored-by: Marek Jasiński <jasins.marek@gmail.com>
Reviewed-on: #83
Co-authored-by: Antigravity <antigravity@google.com>
Co-committed-by: Antigravity <antigravity@google.com>
2026-06-15 17:15:42 +00:00

62 lines
2.1 KiB
C#

using System.Text.Json;
using FluentAssertions;
using NexusReader.Application.Common;
using NexusReader.Application.DTOs.Media;
using Xunit;
namespace NexusReader.Application.Tests.Services;
public class AutosaveEngineTests
{
[Fact]
public void SerializeAndDeserialize_LocalBackupEnvelope_Succeeds()
{
// Arrange
var envelope = new LocalBackupEnvelope
{
ChapterId = Guid.NewGuid(),
Timestamp = DateTime.UtcNow.AddMinutes(-10),
MarkdownContent = "# Hello Autosave"
};
// Act
var json = JsonSerializer.Serialize(envelope, AppJsonContext.Default.LocalBackupEnvelope);
var deserialized = JsonSerializer.Deserialize(json, AppJsonContext.Default.LocalBackupEnvelope);
// Assert
deserialized.Should().NotBeNull();
deserialized!.ChapterId.Should().Be(envelope.ChapterId);
deserialized.MarkdownContent.Should().Be(envelope.MarkdownContent);
// Truncate milliseconds to avoid precision discrepancies in text representation
deserialized.Timestamp.ToUniversalTime().Date.Should().Be(envelope.Timestamp.ToUniversalTime().Date);
}
[Fact]
public void SerializeAndDeserialize_AutosaveChapterRequest_Succeeds()
{
// Arrange
var request = new AutosaveChapterRequest("# Content to Autosave");
// Act
var json = JsonSerializer.Serialize(request, AppJsonContext.Default.AutosaveChapterRequest);
var deserialized = JsonSerializer.Deserialize(json, AppJsonContext.Default.AutosaveChapterRequest);
// Assert
deserialized.Should().NotBeNull();
deserialized!.MarkdownContent.Should().Be(request.MarkdownContent);
}
[Fact]
public void BackupEviction_CheckAgeLogic_EvictsCorrectly()
{
// Arrange
var now = DateTime.UtcNow;
var freshTimestamp = now.AddDays(-6);
var expiredTimestamp = now.AddDays(-8);
// Act & Assert
(now - freshTimestamp).TotalDays.Should().BeLessThanOrEqualTo(7.0);
(now - expiredTimestamp).TotalDays.Should().BeGreaterThan(7.0);
}
}