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
37 changes: 37 additions & 0 deletions playwright/e2e/edit-submission.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,41 @@ test.describe('Edit submission', () => {
await submitView.submit()
await expect(submitView.successMessage).toBeVisible()
})

test('The draft of a form opened from the navigation while editing a submission is restored', async ({
page,
appNavigation,
form,
topBar,
resultsView,
submitView,
}) => {
const resultsUrl = page.url().replace(/\/submit.*$/, '/results')
await appNavigation.clickNewForm()
await expect(form.titleField).toHaveValue('')
await form.fillTitle('Draft form')
await form.addQuestion(QuestionType.ShortAnswer)
const questions = await form.getQuestions()
await questions[0].fillTitle('Pet name')
await topBar.toggleView(FormsView.View)
await submitView.fillText('Pet name', 'Rex')

page.once('dialog', (dialog) => dialog.accept())
await page.goto(resultsUrl)
await resultsView.switchToResponses()
await resultsView.editSubmission()
await expect(
await submitView.getGridCellInput('Skills matrix', 'Beginner', 'Python'),
).toBeChecked()
await appNavigation.getOwnForm('Draft form').click()
await page
.getByRole('dialog', { name: 'Leave form' })
.getByRole('button', { name: 'Leave' })
.click()

await expect(
submitView.getQuestion('Pet name').getByRole('textbox'),
).toHaveValue('Rex')
await expect(page.getByRole('dialog', { name: 'Clear form' })).toHaveCount(0)
})
})
28 changes: 28 additions & 0 deletions playwright/e2e/submit-form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ test.describe('Form submission', () => {
await expect(submitView.successMessage).toBeVisible()
})

test('The draft of a form opened from the navigation is restored', async ({
page,
appNavigation,
form,
topBar,
submitView,
}) => {
const submitUrl = page.url().replace(/\/edit$/, '/submit')
await appNavigation.clickNewForm()
await expect(form.titleField).toHaveValue('')
await form.fillTitle('Draft form')
await form.addQuestion(QuestionType.ShortAnswer)
const questions = await form.getQuestions()
await questions[0].fillTitle('Pet name')
await topBar.toggleView(FormsView.View)
await submitView.fillText('Pet name', 'Rex')

page.once('dialog', (dialog) => dialog.accept())
await page.goto(submitUrl)
await expect(submitView.getQuestion('Your name')).toBeVisible()
await appNavigation.getOwnForm('Draft form').click()

await expect(
submitView.getQuestion('Pet name').getByRole('textbox'),
).toHaveValue('Rex')
await expect(page.getByRole('dialog', { name: 'Clear form' })).toHaveCount(0)
})

test('Partial submission succeeds when no fields are required', async ({
topBar,
submitView,
Expand Down
9 changes: 6 additions & 3 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ export default defineComponent({
*/
function initFromLocalStorage(): void {
const savedState = getFormValuesFromLocalStorage()
if (!savedState) {
if (!savedState || !props.form.questions) {
return
}

Expand Down Expand Up @@ -1141,15 +1141,18 @@ export default defineComponent({

watch(
() => props.hash,
(): void => {
async (hash: string): Promise<void> => {
// If public view, abort. Should normally not occur.
if (props.publicView) {
logger.error('Hash changed on public view. Aborting.')
return
}
resetData()
// Fetch full form on change
void viewForm.fetchFullForm(props.form.id)
await viewForm.fetchFullForm(props.form.id)
if (hash !== props.hash) {
return
}
initFromLocalStorage()
SetWindowTitle(viewForm.formTitle.value)
},
Expand Down
Loading