diff --git a/playwright/e2e/results-view.spec.ts b/playwright/e2e/results-view.spec.ts index a8b8358a1..7b8687d36 100644 --- a/playwright/e2e/results-view.spec.ts +++ b/playwright/e2e/results-view.spec.ts @@ -101,15 +101,15 @@ test.describe('Results view', () => { await expect(resultsView.page).toHaveURL(/\/results\/summary$/) }) - test('Navigating to /results redirects to /results/summary', async ({ page }) => { + test('Navigating to /results redirects to last viewed subview', async ({ page }) => { // Start on the responses tab await page.goto(page.url().replace(/\/summary$/, '/responses')) await page.waitForURL(/\/results\/responses$/) // Navigate to the parent results route await page.goto(page.url().replace(/\/responses$/, '')) - await page.waitForURL(/\/results\/summary$/) - await expect(page).toHaveURL(/\/results\/summary$/) + await page.waitForURL(/\/results\/responses$/) + await expect(page).toHaveURL(/\/results\/responses$/) }) }) diff --git a/playwright/support/sections/SubmitSection.ts b/playwright/support/sections/SubmitSection.ts index a23e0e097..80ea540bd 100644 --- a/playwright/support/sections/SubmitSection.ts +++ b/playwright/support/sections/SubmitSection.ts @@ -13,9 +13,10 @@ export class SubmitSection { constructor(public readonly page: Page) { this.clearFormButton = this.page.getByRole('button', { name: 'Clear form' }) this.submitButton = this.page.getByRole('button', { name: 'Submit' }) - this.successMessage = this.page.getByText( - 'Thank you for completing the form!', - ) + this.successMessage = this.page + .getByRole('main') + .locator('.forms-emptycontent') + .getByText('Thank you for completing the form!') } /** diff --git a/src/router.ts b/src/router.ts index 811bcc099..6432f1375 100644 --- a/src/router.ts +++ b/src/router.ts @@ -33,11 +33,11 @@ const routes = [ }, { path: '/:hash/results', - props: { default: true }, children: [ { path: '', name: 'results', + props: { default: true }, redirect: (to) => { const validViews = ['summary', 'responses'] const storedView = localStorage.getItem( @@ -56,11 +56,13 @@ const routes = [ { path: 'summary', name: 'results.summary', + props: { default: true }, components: { default: Results }, }, { path: 'responses', name: 'results.responses', + props: { default: true }, components: { default: Results }, }, ], diff --git a/src/views/Results.vue b/src/views/Results.vue index e2a137c11..658da8d0d 100644 --- a/src/views/Results.vue +++ b/src/views/Results.vue @@ -505,6 +505,7 @@ export default { // Reload results when form changes async hash() { await this.fetchFullForm(this.form.id) + await this.loadFormResults() SetWindowTitle(this.formTitle) }, @@ -538,6 +539,10 @@ export default { }, async beforeMount() { + // Determine the initial viewId based on the route + const viewId = this.isSummaryView ? 'summary' : 'responses' + this.saveActiveResponseViewToLocalStorage(viewId) + await this.fetchFullForm(this.form.id) this.loadFormResults() SetWindowTitle(this.formTitle)