|
| 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 randomUserTest } from '../support/fixtures/random-user' |
| 8 | +import { test as appNavigationTest } from '../support/fixtures/navigation' |
| 9 | +import { test as formTest } from '../support/fixtures/form' |
| 10 | +import { QuestionType } from '../support/sections/QuestionType' |
| 11 | + |
| 12 | +const test = mergeTests(randomUserTest, appNavigationTest, formTest) |
| 13 | + |
| 14 | +test.describe('Question editing lifecycle', () => { |
| 15 | + test.beforeEach(async ({ page, appNavigation, form }) => { |
| 16 | + await page.goto('apps/forms') |
| 17 | + await page.waitForURL(/apps\/forms\/?$/) |
| 18 | + await appNavigation.clickNewForm() |
| 19 | + await form.fillTitle('Editing test form') |
| 20 | + }) |
| 21 | + |
| 22 | + const questionTypes = [ |
| 23 | + QuestionType.ShortAnswer, |
| 24 | + QuestionType.LongAnswer, |
| 25 | + QuestionType.Checkboxes, |
| 26 | + QuestionType.RadioButtons, |
| 27 | + QuestionType.Dropdown, |
| 28 | + QuestionType.Date, |
| 29 | + QuestionType.LinearScale, |
| 30 | + QuestionType.Color, |
| 31 | + ] |
| 32 | + |
| 33 | + for (const type of questionTypes) { |
| 34 | + test(`Add a ${type} question`, async ({ form }) => { |
| 35 | + await form.addQuestion(type) |
| 36 | + |
| 37 | + const questions = await form.getQuestions() |
| 38 | + expect(questions).toHaveLength(1) |
| 39 | + await expect(questions[0].titleInput).toBeVisible() |
| 40 | + }) |
| 41 | + } |
| 42 | + |
| 43 | + test('Edit question title and description', async ({ form }) => { |
| 44 | + await form.addQuestion(QuestionType.ShortAnswer) |
| 45 | + |
| 46 | + const questions = await form.getQuestions() |
| 47 | + const question = questions[0] |
| 48 | + |
| 49 | + await question.fillTitle('What is your name?') |
| 50 | + await expect(question.titleInput).toHaveValue('What is your name?') |
| 51 | + |
| 52 | + await question.fillDescription('Please enter your full name') |
| 53 | + await expect(question.descriptionInput).toHaveValue( |
| 54 | + 'Please enter your full name', |
| 55 | + ) |
| 56 | + }) |
| 57 | + |
| 58 | + test('Add answer options to a checkbox question', async ({ form }) => { |
| 59 | + await form.addQuestion(QuestionType.Checkboxes) |
| 60 | + |
| 61 | + const questions = await form.getQuestions() |
| 62 | + const question = questions[0] |
| 63 | + |
| 64 | + await question.addAnswer('Option A') |
| 65 | + await question.addAnswer('Option B') |
| 66 | + await question.addAnswer('Option C') |
| 67 | + |
| 68 | + await expect(question.answerInputs).toHaveCount(3) |
| 69 | + }) |
| 70 | + |
| 71 | + test('Delete a question', async ({ page, form }) => { |
| 72 | + await form.addQuestion(QuestionType.ShortAnswer) |
| 73 | + await form.addQuestion(QuestionType.LongAnswer) |
| 74 | + |
| 75 | + let questions = await form.getQuestions() |
| 76 | + expect(questions).toHaveLength(2) |
| 77 | + await questions[0].fillTitle('First question') |
| 78 | + await questions[1].fillTitle('Second question') |
| 79 | + |
| 80 | + await questions[0].delete() |
| 81 | + |
| 82 | + // Wait for Vue to re-render after deletion before taking a snapshot |
| 83 | + await expect( |
| 84 | + page.getByRole('listitem', { name: /Question number \d+/i }), |
| 85 | + ).toHaveCount(1) |
| 86 | + questions = await form.getQuestions() |
| 87 | + await expect(questions[0].titleInput).toHaveValue('Second question') |
| 88 | + }) |
| 89 | + |
| 90 | + test('Clone a question', async ({ form }) => { |
| 91 | + await form.addQuestion(QuestionType.Checkboxes) |
| 92 | + |
| 93 | + const questions = await form.getQuestions() |
| 94 | + const question = questions[0] |
| 95 | + await question.fillTitle('Favorite colors') |
| 96 | + await question.addAnswer('Red') |
| 97 | + await question.addAnswer('Blue') |
| 98 | + |
| 99 | + await question.clone() |
| 100 | + |
| 101 | + const updatedQuestions = await form.getQuestions() |
| 102 | + expect(updatedQuestions).toHaveLength(2) |
| 103 | + |
| 104 | + // The clone should have the same title and options |
| 105 | + const clone = updatedQuestions[1] |
| 106 | + await expect(clone.titleInput).toHaveValue('Favorite colors') |
| 107 | + await expect(clone.answerInputs).toHaveCount(2) |
| 108 | + }) |
| 109 | +}) |
0 commit comments