Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions playwright/e2e/question-editing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 5 additions & 2 deletions src/composables/useQuestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>): void => {
pendingExtraSettings = { ...pendingExtraSettings, ...newSettings }
options.emit('update:extraSettings', {
...props.extraSettings,
...pendingExtraSettings,
})
saveExtraSettings()
}

Expand Down
Loading