diff --git a/frontend/app/components/global/BaseDialog.test.ts b/frontend/app/components/global/BaseDialog.test.ts new file mode 100644 index 000000000..5d4206713 --- /dev/null +++ b/frontend/app/components/global/BaseDialog.test.ts @@ -0,0 +1,45 @@ +import { mount } from "@vue/test-utils"; +import { describe, expect, test } from "vitest"; +import BaseDialog from "./BaseDialog.vue"; + +function mountDialog(props: Record) { + return mount(BaseDialog, { + props: { modelValue: true, ...props }, + global: { + mocks: { + $vuetify: { display: { xs: false } }, + }, + stubs: { + // the keydown listener falls through to this element + VDialog: { template: "
" }, + BaseDialogContent: { template: "
" }, + }, + }, + }); +} + +describe("BaseDialog submit on Enter", () => { + test("submits when submit is enabled", async () => { + const wrapper = mountDialog({ canSubmit: true }); + await wrapper.find(".dialog").trigger("keydown", { key: "Enter" }); + expect(wrapper.emitted("submit")).toHaveLength(1); + }); + + test("does not submit when submit is disabled", async () => { + const wrapper = mountDialog({ canSubmit: true, submitDisabled: true }); + await wrapper.find(".dialog").trigger("keydown", { key: "Enter" }); + expect(wrapper.emitted("submit")).toBeUndefined(); + }); + + test("does not confirm when submit is disabled", async () => { + const wrapper = mountDialog({ canConfirm: true, submitDisabled: true }); + await wrapper.find(".dialog").trigger("keydown", { key: "Enter" }); + expect(wrapper.emitted("confirm")).toBeUndefined(); + }); + + test("does not submit when submit on Enter is turned off", async () => { + const wrapper = mountDialog({ canSubmit: true, disableSubmitOnEnter: true }); + await wrapper.find(".dialog").trigger("keydown", { key: "Enter" }); + expect(wrapper.emitted("submit")).toBeUndefined(); + }); +}); diff --git a/frontend/app/components/global/BaseDialog.vue b/frontend/app/components/global/BaseDialog.vue index b4d9b9978..54d61742c 100644 --- a/frontend/app/components/global/BaseDialog.vue +++ b/frontend/app/components/global/BaseDialog.vue @@ -144,15 +144,14 @@ function submitEvent() { } function submitOnEnter() { - if (props.disableSubmitOnEnter) { + // Enter must respect submitDisabled like the buttons do, for both confirm and submit dialogs + if (props.disableSubmitOnEnter || props.submitDisabled) { return; } if (props.canConfirm) { - if (!props.submitDisabled) { - emit("confirm"); - dialog.value = false; - } + emit("confirm"); + dialog.value = false; return; } diff --git a/frontend/app/pages/g/[groupSlug]/cookbooks/index.vue b/frontend/app/pages/g/[groupSlug]/cookbooks/index.vue index aafcac972..f643b2394 100644 --- a/frontend/app/pages/g/[groupSlug]/cookbooks/index.vue +++ b/frontend/app/pages/g/[groupSlug]/cookbooks/index.vue @@ -10,7 +10,7 @@ :title="$t('cookbook.create-a-cookbook')" :submit-icon="$globals.icons.save" :submit-text="$t('general.save')" - :submit-disabled="!createTarget.queryFilterString" + :submit-disabled="!createTarget.name?.trim() || !createTarget.queryFilterString" can-submit disable-submit-on-enter @submit="actions.updateOne(createTarget)" @@ -21,6 +21,27 @@ + + + + + + + - - + - - -
- - {{ $globals.icons.pages }} - - {{ cookbook.name }} -
- -
- - - - - - - -
-
-
+ + + {{ $globals.icons.pages }} + + {{ cookbook.name }} + + + + {{ $globals.icons.edit }} + + + + {{ $globals.icons.arrowUpDown }} + + + + @@ -151,6 +145,7 @@ definePageMeta({ const dialogStates = reactive({ create: false, + edit: false, delete: false, }); @@ -202,6 +197,14 @@ async function createCookbook() { dialogStates.create = true; } +// edit +const editTarget = ref(null); +function editEventHandler(item: CookBookOut) { + // edit a copy, so cancelling the dialog discards the changes + editTarget.value = structuredClone(toRaw(item)); + dialogStates.edit = true; +} + // delete const deleteTarget = ref(null); function deleteEventHandler(item: CookBookOut) {