فهرست منبع

Persist the displayed default system type on save (#306)

The type dropdown has no empty option, so a fresh system displayed
'baremetal' while the edit model still held null — saving wrote no
type at all until the user manually re-picked one. Default the edit
model to the first valid type when the system has none, add a
system-type-value testid to the read view, and cover it with an E2E
regression test (verified failing before the fix).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Tim Jones 14 ساعت پیش
والد
کامیت
2344f5e017

+ 1 - 1
Shared.Rcl/Systems/SystemCardComponent.razor

@@ -94,7 +94,7 @@
             }
             else if (!string.IsNullOrWhiteSpace(System.Type))
             {
-                <div class="text-zinc-300">@System.Type</div>
+                <div class="text-zinc-300" data-testid="system-type-value">@System.Type</div>
             }
         </div>
 

+ 4 - 1
Shared.Rcl/Systems/SystemEditModel.cs

@@ -23,7 +23,10 @@ public sealed class SystemEditModel {
     public static SystemEditModel From(SystemResource system) {
         return new SystemEditModel {
             Name = system.Name,
-            Type = system.Type,
+            // The type dropdown has no empty option, so a system without a
+            // type still displays the first choice; default to it so what the
+            // user sees is what gets saved (#306).
+            Type = system.Type ?? SystemResource.ValidSystemTypes[0],
             Os = system.Os,
             Cores = system.Cores,
             Ram = system.Ram,

+ 3 - 0
Tests.E2e/PageObjectModels/SystemCardPom.cs

@@ -81,6 +81,9 @@ public class SystemCardPom(IPage page) {
     public ILocator TypeSelect(string name)
         => Card(name).GetByTestId("system-type-select");
 
+    public ILocator TypeValue(string name)
+        => Card(name).GetByTestId("system-type-value");
+
     public ILocator OsInput(string name)
         => Card(name).GetByTestId("system-os-input");
 

+ 34 - 0
Tests.E2e/SystemCardTests.cs

@@ -119,6 +119,40 @@ public class SystemCardTests(
         }
     }
 
+    [Fact]
+    public async Task Saving_Without_Touching_Type_Persists_The_Displayed_Default() {
+        (IBrowserContext context, IPage page) = await CreatePageAsync();
+        var name = $"e2e-sys-type-{Guid.NewGuid():N}"[..16];
+
+        try {
+            await page.GotoAsync($"{_fixture.BaseUrl}/systems/list");
+
+            var list = new SystemsListPom(page);
+            await list.AddSystemAsync(name);
+
+            if (!page.Url.Contains($"/resources/systems/{name}",
+                    StringComparison.OrdinalIgnoreCase))
+                await list.OpenSystemAsync(name);
+
+            var card = new SystemCardPom(page);
+            await card.AssertVisibleAsync(name);
+
+            // The dropdown shows 'baremetal' for a fresh system; save without
+            // touching it — the displayed default must actually persist (#306).
+            await card.BeginEditAsync(name);
+            await card.SaveAsync(name);
+
+            await Assertions.Expect(card.TypeValue(name)).ToHaveTextAsync("baremetal");
+
+            await page.ReloadAsync();
+            await card.AssertVisibleAsync(name);
+            await Assertions.Expect(card.TypeValue(name)).ToHaveTextAsync("baremetal");
+        }
+        finally {
+            await context.CloseAsync();
+        }
+    }
+
     // ============================================================
     // Cancel Edit
     // ============================================================