diff --git a/playwright/e2e/question-editing.spec.ts b/playwright/e2e/question-editing.spec.ts index 6b37d0c00..cfa6650ae 100644 --- a/playwright/e2e/question-editing.spec.ts +++ b/playwright/e2e/question-editing.spec.ts @@ -87,6 +87,35 @@ test.describe('Question editing lifecycle', () => { await expect(questions[0].titleInput).toHaveValue('Second question') }) + test('Saves the value of a setting chosen last in quick succession', async ({ + form, + page, + }) => { + await form.addQuestion(QuestionType.LinearScale) + const question = (await form.getQuestions())[0] + await question.openActionsMenu() + const highest = page.getByRole('combobox', { name: 'Highest value' }) + const saved = page.waitForResponse( + (response) => + response.request().method() === 'PATCH' + && response.request().postDataJSON()?.keyValuePairs?.extraSettings + !== undefined, + ) + + await highest.click() + await page.getByRole('option', { name: '7', exact: true }).click() + await highest.click() + await page.getByRole('option', { name: '5', exact: true }).click() + expect((await saved).ok()).toBeTruthy() + + await page.reload() + await expect( + page + .getByRole('listitem', { name: /Question number \d+/i }) + .getByRole('radio'), + ).toHaveCount(5) + }) + test('Clone a question', async ({ form }) => { await form.addQuestion(QuestionType.Checkboxes) diff --git a/src/composables/useQuestion.ts b/src/composables/useQuestion.ts index 87d903c75..e99be4999 100644 --- a/src/composables/useQuestion.ts +++ b/src/composables/useQuestion.ts @@ -212,17 +212,20 @@ export function useQuestion(props: QuestionPropsLike, options: UseQuestionOption const saveExtraSettings = debounce(function () { const newExtraSettings = { ...props.extraSettings, ...pendingExtraSettings } pendingExtraSettings = {} - options.emit('update:extraSettings', newExtraSettings) saveQuestionProperty('extraSettings', newExtraSettings) }, INPUT_DEBOUNCE_MS) /** - * Save changed extra settings; changes within the debounce time are saved together + * Show changed extra settings at once and save them; changes within the debounce time are saved together * * @param newSettings the changed extra settings */ const onExtraSettingsChange = (newSettings: Record): void => { pendingExtraSettings = { ...pendingExtraSettings, ...newSettings } + options.emit('update:extraSettings', { + ...props.extraSettings, + ...pendingExtraSettings, + }) saveExtraSettings() }