fix: preserve blank CVs and reliable editor undo

This commit is contained in:
cesnimda
2026-10-27 07:37:03 +01:00
parent 5d4b8f23ce
commit 663023a088
22 changed files with 950 additions and 101 deletions
+66
View File
@@ -28,6 +28,72 @@ public sealed class CvBuilderTests
// ---- Resolver (the lens over the master profile) ----
[Fact]
public void Explicit_blank_roundtrips_without_inheriting_profile_content_or_header()
{
var settings = CvVariantSettingsJson.Deserialize("{\"sectionsExplicit\":true,\"includeProfileContact\":false,\"sections\":[],\"showPhoto\":true}");
var json = CvVariantSettingsJson.Serialize(settings);
Assert.Contains("\"sectionsExplicit\":true", json);
Assert.Contains("\"includeProfileContact\":false", json);
var model = CvVariantResolver.Build(Rich(), CvVariantSettingsJson.Deserialize(json), "Fallback", "data:image/png;base64,AA==");
Assert.Empty(model.Sections);
Assert.Empty(model.FullName);
Assert.Null(model.Headline);
Assert.Empty(model.Contact);
Assert.Null(model.PhotoDataUrl);
foreach (var theme in CvThemeCatalog.Themes)
{
var html = new ThemedCvRenderer().Render(model, theme, settings).Html;
Assert.DoesNotContain("<header", html);
Assert.DoesNotContain("Ada Lovelace", html);
Assert.DoesNotContain("Fallback", html);
}
}
[Fact]
public void Explicit_sections_include_only_selected_content_and_allow_authored_headline()
{
var settings = CvVariantSettingsJson.Deserialize("{\"sectionsExplicit\":true,\"includeProfileContact\":false,\"headline\":\"Authored headline\",\"sections\":[{\"key\":\"skills\"}]}");
var model = CvVariantResolver.Build(Rich(), settings, "Fallback", null);
Assert.Equal("skills", Assert.Single(model.Sections).Key);
Assert.Equal("Authored headline", model.Headline);
Assert.Empty(model.FullName);
Assert.Empty(model.Contact);
}
[Fact]
public void Legacy_inclusion_flags_remain_absent_and_preserve_profile_inheritance()
{
var settings = CvVariantSettingsJson.Deserialize("{\"sections\":[]}");
var json = CvVariantSettingsJson.Serialize(settings);
Assert.DoesNotContain("sectionsExplicit", json);
Assert.DoesNotContain("includeProfileContact", json);
var model = CvVariantResolver.Build(Rich(), settings, "Fallback", null);
Assert.Equal("Ada Lovelace", model.FullName);
Assert.NotEmpty(model.Sections);
Assert.NotEmpty(model.Contact);
}
[Fact]
public async Task Explicit_blank_survives_save_duplicate_restore_and_design_change()
{
var (db, service) = NewService("user-1");
await using var dispose = db;
var settings = CvVariantSettingsJson.Deserialize("{\"sectionsExplicit\":true,\"includeProfileContact\":false,\"sections\":[]}");
var created = await service.CreateAsync("user-1", "Blank", null, settings, default);
settings.ThemeId = "clean";
await service.SaveAsync("user-1", created.Id, null, settings, "manual", 1, default);
var copy = await service.DuplicateAsync("user-1", created.Id, null, default);
var restored = await service.RestoreVersionAsync("user-1", created.Id, 1, 2, default);
foreach (var document in new[] { copy!, restored! })
{
var stored = CvVariantSettingsJson.Deserialize(document.SettingsJson);
Assert.Contains("\"sectionsExplicit\":true", document.SettingsJson);
Assert.Contains("\"includeProfileContact\":false", document.SettingsJson);
Assert.Empty(CvVariantResolver.Build(Rich(), stored, "Fallback", null).Sections);
}
}
[Fact]
public void Resolver_defaults_include_every_populated_section()
{