Skip to content

Commit 41d4536

Browse files
test(results): cover the scale figures and the promoter score
The figures and the promoter score are computed in the frontend only, which has no unit tests, so end-to-end tests are their only coverage. They check the figures above the bars of a scale question, the promoter score of the promoter sub type, its absence on a plain 0-10 scale, the absence of the figures on a rating, and the questions the add-question menu creates for the "Promoter score" and "Numbers" entries, including the default labels of a promoter score question. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent 8a9af8e commit 41d4536

1 file changed

Lines changed: 195 additions & 0 deletions

File tree

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import type { APIRequestContext } from '@playwright/test'
7+
8+
import { expect, mergeTests } from '@playwright/test'
9+
import { test as formTest } from '../support/fixtures/form.ts'
10+
import { test as appNavigationTest } from '../support/fixtures/navigation.ts'
11+
import { test as randomUserTest } from '../support/fixtures/random-user.ts'
12+
import { test as resultsTest } from '../support/fixtures/results.ts'
13+
import { api, waitForApiResponse } from '../support/helpers.ts'
14+
import {
15+
LinearScaleSubtype,
16+
QuestionType,
17+
} from '../support/sections/QuestionType.ts'
18+
19+
const test = mergeTests(randomUserTest, appNavigationTest, formTest, resultsTest)
20+
21+
/**
22+
* Create a form with the linear scale "Recommend" and one submission per answer
23+
*
24+
* @param request the request context of the page
25+
* @param subtype the sub type of the scale, or null for a plain scale
26+
* @param extraSettings further extra settings of the scale
27+
* @param answers the answers to submit, one submission each
28+
*/
29+
async function createScaleForm(
30+
request: APIRequestContext,
31+
subtype: string | null,
32+
extraSettings: Record<string, unknown>,
33+
answers: string[] = [],
34+
) {
35+
const form = await api(request, 'POST', '/forms')
36+
await api(request, 'PATCH', `/forms/${form.id}`, {
37+
keyValuePairs: { submitMultiple: true },
38+
})
39+
const scale = await api(request, 'POST', `/forms/${form.id}/questions`, {
40+
type: 'linearscale',
41+
subtype,
42+
text: 'Recommend',
43+
})
44+
if (Object.keys(extraSettings).length > 0) {
45+
await api(request, 'PATCH', `/forms/${form.id}/questions/${scale.id}`, {
46+
keyValuePairs: {
47+
extraSettings: { ...scale.extraSettings, ...extraSettings },
48+
},
49+
})
50+
}
51+
for (const answer of answers) {
52+
await api(request, 'POST', `/forms/${form.id}/submissions`, {
53+
answers: { [scale.id]: [answer] },
54+
})
55+
}
56+
return form
57+
}
58+
59+
test('Scale figures and the promoter score are shown above the bars', async ({
60+
page,
61+
resultsView,
62+
}) => {
63+
const form = await createScaleForm(page.request, 'promoter', {}, [
64+
'10',
65+
'9',
66+
'7',
67+
'3',
68+
])
69+
await page.goto(`apps/forms/${form.hash}/results`)
70+
await page.waitForURL(/\/results\/summary$/)
71+
72+
const summary = resultsView.getSummaryForQuestion('Recommend')
73+
await expect(
74+
summary.getByText(
75+
'Linear scale (0: Not at all likely, 10: Extremely likely)',
76+
{ exact: true },
77+
),
78+
).toBeVisible()
79+
const figure = (label: string) => summary.locator(`dt:text-is("${label}") + dd`)
80+
await expect(figure('Answers')).toHaveText('4')
81+
await expect(figure('Average')).toHaveText('7.3')
82+
await expect(figure('Median')).toHaveText('8')
83+
await expect(figure('Minimum')).toHaveText('3')
84+
await expect(figure('Maximum')).toHaveText('10')
85+
const promoterLabel = summary.locator('dt', { hasText: 'Promoter score' })
86+
await expect(promoterLabel).toBeVisible()
87+
await expect(promoterLabel.locator('.hidden-visually')).toHaveText(
88+
'(promoters − detractors)',
89+
)
90+
await expect(promoterLabel.locator('+ dd')).toHaveText('+25')
91+
await expect(
92+
summary.getByText('25% detractors · 25% passives · 50% promoters'),
93+
).toBeVisible()
94+
await expect(summary.locator('dl + ol meter')).not.toHaveCount(0)
95+
})
96+
97+
test('A plain 0 to 10 scale shows no promoter score', async ({
98+
page,
99+
resultsView,
100+
}) => {
101+
const form = await createScaleForm(
102+
page.request,
103+
null,
104+
{ optionsLowest: 0, optionsHighest: 10 },
105+
['10', '3'],
106+
)
107+
await page.goto(`apps/forms/${form.hash}/results`)
108+
await page.waitForURL(/\/results\/summary$/)
109+
110+
const summary = resultsView.getSummaryForQuestion('Recommend')
111+
await expect(summary.locator('dt:text-is("Average") + dd')).toHaveText('6.5')
112+
await expect(summary.getByText(/Promoter score/)).toHaveCount(0)
113+
})
114+
115+
test('A rating shows its average rating and no scale figures', async ({
116+
page,
117+
resultsView,
118+
}) => {
119+
const form = await createScaleForm(page.request, 'rating', {}, ['5', '4'])
120+
await page.goto(`apps/forms/${form.hash}/results`)
121+
await page.waitForURL(/\/results\/summary$/)
122+
123+
const summary = resultsView.getSummaryForQuestion('Recommend')
124+
await expect(summary.getByText('4.5 of 5', { exact: true })).toBeVisible()
125+
await expect(
126+
summary.getByText('Average rating 4.5 of 5, from 2 ratings'),
127+
).toHaveCount(1)
128+
await expect(summary.locator('dl')).toHaveCount(0)
129+
await expect(summary.getByText(/Promoter score/)).toHaveCount(0)
130+
})
131+
132+
test('A promoter score question from the menu is a fixed 0 to 10 scale', async ({
133+
page,
134+
appNavigation,
135+
form,
136+
}) => {
137+
await page.goto('apps/forms')
138+
await appNavigation.clickNewForm()
139+
await form.fillTitle('Promoter form')
140+
141+
const created = waitForApiResponse(page, 'POST')
142+
await form.addQuestion(QuestionType.LinearScale, LinearScaleSubtype.Promoter)
143+
const response = await created
144+
expect(response.request().postDataJSON()).toMatchObject({
145+
type: 'linearscale',
146+
subtype: 'promoter',
147+
})
148+
expect((await response.json()).ocs.data.extraSettings).toEqual({
149+
questionType: 'promoter',
150+
optionsLowest: 0,
151+
optionsHighest: 10,
152+
})
153+
154+
const [question] = await form.getQuestions()
155+
await expect(question.section.getByRole('radio')).toHaveCount(11)
156+
await expect(question.section.getByRole('radio').first()).toHaveAccessibleName(
157+
'0',
158+
)
159+
await expect(question.section.getByRole('radio').last()).toHaveAccessibleName(
160+
'10',
161+
)
162+
await expect(
163+
question.section.getByRole('textbox', { name: 'Label for lowest value' }),
164+
).toHaveValue('Not at all likely')
165+
await expect(
166+
question.section.getByRole('textbox', { name: 'Label for highest value' }),
167+
).toHaveValue('Extremely likely')
168+
169+
await question.openActionsMenu()
170+
await expect(page.getByRole('checkbox', { name: 'Required' })).toBeVisible()
171+
await expect(page.getByRole('combobox', { name: 'Lowest value' })).toHaveCount(0)
172+
await expect(page.getByRole('combobox', { name: 'Highest value' })).toHaveCount(
173+
0,
174+
)
175+
})
176+
177+
test('A numbers question from the menu has no sub type', async ({
178+
page,
179+
appNavigation,
180+
form,
181+
}) => {
182+
await page.goto('apps/forms')
183+
await appNavigation.clickNewForm()
184+
await form.fillTitle('Numbers form')
185+
186+
const created = waitForApiResponse(page, 'POST')
187+
await form.addQuestion(QuestionType.LinearScale, LinearScaleSubtype.Numbers)
188+
const response = await created
189+
expect(response.request().postDataJSON().subtype).toBeNull()
190+
expect((await response.json()).ocs.data.extraSettings).toEqual({})
191+
192+
const [question] = await form.getQuestions()
193+
await question.openActionsMenu()
194+
await expect(page.getByRole('combobox', { name: 'Lowest value' })).toBeVisible()
195+
})

0 commit comments

Comments
 (0)