fix(grid): keep save actions visible

This commit is contained in:
t8y2
2026-05-18 17:46:42 +08:00
parent b6bf3009f8
commit cf86d7f3b4
3 changed files with 87 additions and 5 deletions
+57 -1
View File
@@ -1,6 +1,6 @@
import { strict as assert } from "node:assert";
import test from "node:test";
import { dataGridSaveActionMode } from "../../apps/desktop/src/lib/dataGridSaveUi.ts";
import { dataGridSaveActionMode, dataGridSaveToolbarState } from "../../apps/desktop/src/lib/dataGridSaveUi.ts";
test("uses concise save and commit labels for the primary grid save action", () => {
assert.deepEqual(dataGridSaveActionMode({ pendingChangeCount: 3, useTransaction: true }), {
@@ -15,3 +15,59 @@ test("uses concise save and commit labels for the primary grid save action", ()
secondaryActionKey: "grid.discard",
});
});
test("keeps grid save actions visible for editable grids even without pending changes", () => {
assert.deepEqual(
dataGridSaveToolbarState({
editable: true,
hasSaveTarget: true,
hasPendingChanges: false,
isSaving: false,
}),
{
showActions: true,
actionsDisabled: true,
},
);
assert.deepEqual(
dataGridSaveToolbarState({
editable: true,
hasSaveTarget: true,
hasPendingChanges: true,
isSaving: false,
}),
{
showActions: true,
actionsDisabled: false,
},
);
});
test("hides grid save actions when a grid cannot save edits", () => {
assert.deepEqual(
dataGridSaveToolbarState({
editable: false,
hasSaveTarget: true,
hasPendingChanges: false,
isSaving: false,
}),
{
showActions: false,
actionsDisabled: true,
},
);
assert.deepEqual(
dataGridSaveToolbarState({
editable: true,
hasSaveTarget: false,
hasPendingChanges: true,
isSaving: false,
}),
{
showActions: false,
actionsDisabled: true,
},
);
});