From 63c3b9696b19b62a1755edd17f50c62396269a61 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 23 Nov 2026 22:23:25 +0100 Subject: [PATCH] feat(section): ask whether deleting a section keeps its questions Deleting a section with questions asks whether to delete only the section, so its questions join the part before it, or the section with its questions, as in Microsoft Forms. The questions are deleted one after the other with the existing endpoint, and the editor warns once about the jumps this changes. An empty section is deleted directly. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- playwright/e2e/sections.spec.ts | 63 +++++++++- src/components/Questions/Question.vue | 6 +- src/views/Create.vue | 160 +++++++++++++++++++------- 3 files changed, 185 insertions(+), 44 deletions(-) diff --git a/playwright/e2e/sections.spec.ts b/playwright/e2e/sections.spec.ts index c748f410d..e5866f0e4 100644 --- a/playwright/e2e/sections.spec.ts +++ b/playwright/e2e/sections.spec.ts @@ -583,6 +583,62 @@ test.describe('Sections', () => { await expect(label(2)).toHaveText('End of the form') }) + test('Deleting a section asks whether to keep its questions', async ({ + page, + }) => { + const form = await api(page.request, 'POST', '/forms') + for (const [type, text] of [ + ['section', 'Part one'], + ['short', 'First'], + ['section', 'Part two'], + ['short', 'Second'], + ['short', 'Third'], + ['section', 'Empty part'], + ]) { + await api(page.request, 'POST', `/forms/${form.id}/questions`, { + type, + text, + }) + } + await page.goto(`apps/forms/${form.hash}/edit`) + const deleteSection = async (number: number) => { + await page + .getByRole('listitem', { name: `Section number ${number}` }) + .getByRole('button', { name: 'Actions', exact: true }) + .click() + await page.getByRole('menuitem', { name: 'Delete section' }).click() + } + + await deleteSection(3) + await expect( + page.getByRole('listitem', { name: 'Section number 3' }), + ).toHaveCount(0) + + await deleteSection(2) + const dialog = page.getByRole('dialog', { name: 'Delete section' }) + await expect(dialog).toContainText( + 'Delete only the section, so its 2 questions join the part before it', + ) + await dialog.getByRole('button', { name: 'Keep questions' }).click() + await expect( + page.getByRole('listitem', { name: 'Section number 2' }), + ).toHaveCount(0) + await expect( + page.getByRole('listitem', { name: 'Question number 3' }), + ).toBeVisible() + + await deleteSection(1) + await expect(dialog).toContainText( + 'Delete only the section, so its 3 questions stay in a form without sections', + ) + await dialog.getByRole('button', { name: 'Delete questions' }).click() + await expect( + page.getByRole('listitem', { name: /^(Question|Section) number/ }), + ).toHaveCount(0) + const { questions } = await api(page.request, 'GET', `/forms/${form.id}`) + expect(questions).toEqual([]) + }) + test('Each page checks its required questions, an empty section is an info page', async ({ page, submitView, @@ -874,7 +930,12 @@ test.describe('Sections', () => { const start = page.getByRole('listitem', { name: 'Section number 1' }) await start.getByRole('button', { name: 'Actions', exact: true }).click() - await page.getByRole('menuitem', { name: 'Delete question' }).click() + await page.getByRole('menuitem', { name: 'Delete section' }).click() + const dialog = page.getByRole('dialog', { name: 'Delete section' }) + await expect(dialog).toContainText( + 'Delete only the section, so its question joins the next section', + ) + await dialog.getByRole('button', { name: 'Keep questions' }).click() await expect( page.getByRole('textbox', { name: 'Title of section number 1' }), diff --git a/src/components/Questions/Question.vue b/src/components/Questions/Question.vue index e2fd65c51..101c4a46d 100644 --- a/src/components/Questions/Question.vue +++ b/src/components/Questions/Question.vue @@ -169,7 +169,11 @@ - {{ t('forms', 'Delete question') }} + {{ + isSection + ? t('forms', 'Delete section') + : t('forms', 'Delete question') + }} diff --git a/src/views/Create.vue b/src/views/Create.vue index bd3da326c..c966f3aef 100644 --- a/src/views/Create.vue +++ b/src/views/Create.vue @@ -198,7 +198,7 @@ " @update:options="updateQuestionOptions(index, $event)" @clone="cloneQuestion(question, index)" - @delete="deleteQuestion(question.id)" + @delete="onDelete(question.id)" @moveDown="onMoveDown(index)" @moveUp="onMoveUp(index)">