-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathsubmit-form.spec.ts
More file actions
82 lines (69 loc) · 2.77 KB
/
submit-form.spec.ts
File metadata and controls
82 lines (69 loc) · 2.77 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
71
72
73
74
75
76
77
78
79
80
81
82
/**
* 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('Form submission', () => {
// Setup: create a form with 4 question types
test.beforeEach(async ({ page, appNavigation, form }) => {
await page.goto('apps/forms')
await page.waitForURL(/apps\/forms\/?$/)
await appNavigation.clickNewForm()
await form.fillTitle('Submission test form')
// Add a short answer question
await form.addQuestion(QuestionType.ShortAnswer)
const questions1 = await form.getQuestions()
await questions1[0].fillTitle('Your name')
// Add a checkboxes question with options
await form.addQuestion(QuestionType.Checkboxes)
const questions2 = await form.getQuestions()
await questions2[1].fillTitle('Favorite fruits')
await questions2[1].addAnswer('Apple')
await questions2[1].addAnswer('Banana')
await questions2[1].addAnswer('Cherry')
// Add a dropdown question with options
await form.addQuestion(QuestionType.Dropdown)
const questions3 = await form.getQuestions()
await questions3[2].fillTitle('Your country')
await questions3[2].addAnswer('Germany')
await questions3[2].addAnswer('France')
await questions3[2].addAnswer('Spain')
// Add a date question
await form.addQuestion(QuestionType.Date)
const questions4 = await form.getQuestions()
await questions4[3].fillTitle('Birth date')
})
test('Fill and submit a form', async ({ topBar, submitView }) => {
await topBar.toggleView(FormsView.View)
await submitView.fillText('Your name', 'Alice')
await submitView.checkOption('Favorite fruits', 'Apple')
await submitView.checkOption('Favorite fruits', 'Cherry')
await submitView.selectDropdown('Your country', 'Germany')
await submitView.submit()
await expect(submitView.successMessage).toBeVisible()
})
test('Partial submission succeeds when no fields are required', async ({
topBar,
submitView,
}) => {
await topBar.toggleView(FormsView.View)
// Only fill the short answer, leave everything else empty
await submitView.fillText('Your name', 'Bob')
await submitView.submit()
await expect(submitView.successMessage).toBeVisible()
})
})