|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { expect, mergeTests } from '@playwright/test' |
| 7 | +import { test as formTest } from '../support/fixtures/form' |
| 8 | +import { test as appNavigationTest } from '../support/fixtures/navigation' |
| 9 | +import { test as randomUserTest } from '../support/fixtures/random-user' |
| 10 | +import { test as submitTest } from '../support/fixtures/submit' |
| 11 | +import { test as topBarTest } from '../support/fixtures/topBar' |
| 12 | +import { waitForApiResponse } from '../support/helpers' |
| 13 | +import { QuestionType } from '../support/sections/QuestionType' |
| 14 | +import { FormsView } from '../support/sections/TopBarSection' |
| 15 | + |
| 16 | +const test = mergeTests( |
| 17 | + randomUserTest, |
| 18 | + appNavigationTest, |
| 19 | + formTest, |
| 20 | + topBarTest, |
| 21 | + submitTest, |
| 22 | +) |
| 23 | + |
| 24 | +test.describe('Form settings', () => { |
| 25 | + // Setup: create a form with one question, open the Settings sidebar tab |
| 26 | + test.beforeEach(async ({ page, appNavigation, form }) => { |
| 27 | + await page.goto('apps/forms') |
| 28 | + await page.waitForURL(/apps\/forms\/?$/) |
| 29 | + await appNavigation.clickNewForm() |
| 30 | + await form.fillTitle('Settings test form') |
| 31 | + |
| 32 | + await form.addQuestion(QuestionType.ShortAnswer) |
| 33 | + const questions = await form.getQuestions() |
| 34 | + await questions[0].fillTitle('Your answer') |
| 35 | + |
| 36 | + // Open sidebar and switch to Settings tab |
| 37 | + await page.getByRole('button', { name: /Share/ }).click() |
| 38 | + const settingsTab = page.getByRole('tab', { name: /Settings/ }) |
| 39 | + await settingsTab.click() |
| 40 | + await expect( |
| 41 | + page.getByRole('checkbox', { name: /Close form/ }), |
| 42 | + ).toBeVisible() |
| 43 | + }) |
| 44 | + |
| 45 | + test('Closing a form blocks submissions', async ({ page, topBar }) => { |
| 46 | + const saved = waitForApiResponse(page, 'PATCH') |
| 47 | + await page |
| 48 | + .getByRole('checkbox', { name: /Close form/ }) |
| 49 | + .click({ force: true }) |
| 50 | + await saved |
| 51 | + |
| 52 | + await topBar.toggleView(FormsView.View) |
| 53 | + |
| 54 | + // NcEmptyContent renders with role="note" — scope to main to avoid |
| 55 | + // matching the "Form closed" status text in the sidebar navigation. |
| 56 | + const main = page.getByRole('main') |
| 57 | + await expect(main.getByText('Form closed')).toBeVisible() |
| 58 | + await expect( |
| 59 | + main.getByText('This form was closed and is no longer taking responses'), |
| 60 | + ).toBeVisible() |
| 61 | + }) |
| 62 | + |
| 63 | + test('Reopening a closed form allows submissions', async ({ |
| 64 | + page, |
| 65 | + topBar, |
| 66 | + submitView, |
| 67 | + }) => { |
| 68 | + // Close the form |
| 69 | + const closed = waitForApiResponse(page, 'PATCH') |
| 70 | + await page |
| 71 | + .getByRole('checkbox', { name: /Close form/ }) |
| 72 | + .click({ force: true }) |
| 73 | + await closed |
| 74 | + |
| 75 | + // Reopen the form |
| 76 | + const reopened = waitForApiResponse(page, 'PATCH') |
| 77 | + await page |
| 78 | + .getByRole('checkbox', { name: /Close form/ }) |
| 79 | + .click({ force: true }) |
| 80 | + await reopened |
| 81 | + |
| 82 | + await topBar.toggleView(FormsView.View) |
| 83 | + |
| 84 | + // Form should be accessible — questions visible and submit button present |
| 85 | + await expect(submitView.submitButton).toBeVisible() |
| 86 | + }) |
| 87 | + |
| 88 | + test('Anonymous mode shows anonymous message on submit view', async ({ |
| 89 | + page, |
| 90 | + topBar, |
| 91 | + }) => { |
| 92 | + const saved = waitForApiResponse(page, 'PATCH') |
| 93 | + await page |
| 94 | + .getByRole('checkbox', { name: /Store responses anonymously/ }) |
| 95 | + .click({ force: true }) |
| 96 | + await saved |
| 97 | + |
| 98 | + await topBar.toggleView(FormsView.View) |
| 99 | + |
| 100 | + await expect(page.getByText('Responses are anonymous.')).toBeVisible() |
| 101 | + }) |
| 102 | + |
| 103 | + test('Non-anonymous mode shows account-connected message on edit view', async ({ |
| 104 | + page, |
| 105 | + }) => { |
| 106 | + // The Create (edit) view always shows this message when anonymous |
| 107 | + // is off, because the editor is always in a logged-in context. |
| 108 | + // The Submit route doesn't receive isLoggedIn from the router, so |
| 109 | + // the message only appears on the edit view. |
| 110 | + await expect( |
| 111 | + page.getByText('Responses are connected to your account.'), |
| 112 | + ).toBeVisible() |
| 113 | + }) |
| 114 | +}) |
0 commit comments