-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathrequired-fields.spec.ts
More file actions
70 lines (58 loc) · 2.24 KB
/
required-fields.spec.ts
File metadata and controls
70 lines (58 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { expect, mergeTests } from '@playwright/test'
import { test as formTest } from '../support/fixtures/form.ts'
import { test as appNavigationTest } from '../support/fixtures/navigation.ts'
import { test as randomUserTest } from '../support/fixtures/random-user.ts'
import { test as submitTest } from '../support/fixtures/submit.ts'
import { test as topBarTest } from '../support/fixtures/topBar.ts'
import { QuestionType } from '../support/sections/QuestionType.ts'
import { FormsView } from '../support/sections/TopBarSection.ts'
const test = mergeTests(
randomUserTest,
appNavigationTest,
formTest,
topBarTest,
submitTest,
)
test.describe('Required field validation', () => {
// Setup: create form with 2 questions, mark the first as required
test.beforeEach(async ({ page, appNavigation, form }) => {
await page.goto('apps/forms')
await page.waitForURL(/apps\/forms\/?$/)
await appNavigation.clickNewForm()
await form.fillTitle('Required fields test')
// Add a required short answer
await form.addQuestion(QuestionType.ShortAnswer)
const questions = await form.getQuestions()
await questions[0].fillTitle('Required field')
await questions[0].toggleRequired()
// Add a non-required question
await form.addQuestion(QuestionType.ShortAnswer)
const questions2 = await form.getQuestions()
await questions2[1].fillTitle('Optional field')
})
test('Submit with empty required field shows validation error', async ({
topBar,
submitView,
}) => {
await topBar.toggleView(FormsView.View)
// Fill only the optional field
await submitView.fillText('Optional field', 'some text')
// Try to submit — should fail due to required field
await submitView.submitButton.click()
// The form should NOT show success message (submission blocked by HTML5 validation)
await expect(submitView.successMessage).not.toBeVisible()
})
test('Submit succeeds after filling required field', async ({
topBar,
submitView,
}) => {
await topBar.toggleView(FormsView.View)
await submitView.fillText('Required field', 'my answer')
await submitView.submit()
await expect(submitView.successMessage).toBeVisible()
})
})