-
{{ t('forms', 'Promoter score (promoters − detractors)') }}
-
{{ formatCount(promoterBreakdown.score) }}
+
+
+ {{ t('forms', 'Promoter score') }}
+
+ {{ t('forms', '(promoters − detractors)') }}
+
+
+
+ {{ formatScore(promoterBreakdown.score) }}
+
+
+
+
{{
formatPromoterShares(
- promoterBreakdown.promoters,
promoterBreakdown.detractors,
+ promoterBreakdown.passives,
+ promoterBreakdown.promoters,
)
}}
@@ -288,6 +304,7 @@ const oneDecimal = new Intl.NumberFormat(locale, {
maximumFractionDigits: 1,
})
const percent = new Intl.NumberFormat(locale, { style: 'percent' })
+const signedCount = new Intl.NumberFormat(locale, { signDisplay: 'exceptZero' })
/**
* Format a percentage from 0 to 100 for the user's locale
@@ -299,17 +316,39 @@ function formatPercent(percentage: number): string {
}
/**
- * The shares of promoters and detractors as text, e.g. "50% promoters, 25% detractors"
+ * The shares of detractors, passives and promoters as text, e.g. "25% detractors · 25% passives · 50% promoters"
*
- * @param promoters the share of promoters in percent
* @param detractors the share of detractors in percent
+ * @param passives the share of passives in percent
+ * @param promoters the share of promoters in percent
+ */
+function formatPromoterShares(
+ detractors: number,
+ passives: number,
+ promoters: number,
+): string {
+ // TRANSLATORS {detractors}, {passives} and {promoters} are percentages, e.g. "25% detractors · 25% passives · 50% promoters"
+ return t(
+ 'forms',
+ '{detractors} detractors · {passives} passives · {promoters} promoters',
+ {
+ detractors: formatPercent(detractors),
+ passives: formatPercent(passives),
+ promoters: formatPercent(promoters),
+ },
+ )
+}
+
+/**
+ * The promoter score with its sign, e.g. "+11", "0" or "−25"
+ *
+ * @param score the promoter score
*/
-function formatPromoterShares(promoters: number, detractors: number): string {
- // TRANSLATORS {promoters} and {detractors} are percentages, e.g. "50% promoters, 25% detractors"
- return t('forms', '{promoters} promoters, {detractors} detractors', {
- promoters: formatPercent(promoters),
- detractors: formatPercent(detractors),
- })
+function formatScore(score: number): string {
+ return signedCount
+ .formatToParts(score)
+ .map((part) => (part.type === 'minusSign' ? '−' : part.value))
+ .join('')
}
export default defineComponent({
@@ -876,9 +915,9 @@ export default defineComponent({
})
/**
- * Promoter and detractor shares in percent and the promoter score, the difference of
- * the two, using the 9-10 / 7-8 / 0-6 split. Null unless the question has the promoter
- * sub type and answers.
+ * Answers per group, detractor, passive and promoter shares in percent and the promoter
+ * score, the difference of the promoter and detractor shares, using the 9-10 / 7-8 / 0-6
+ * split. Null unless the question has the promoter sub type and answers.
*/
const promoterBreakdown = computed(() => {
if (
@@ -893,13 +932,15 @@ export default defineComponent({
}
const promoters = values.filter((value) => value >= 9).length
const detractors = values.filter((value) => value <= 6).length
+ const passives = values.length - promoters - detractors
const share = (count: number) =>
- Math.sign(count)
- * Math.round((Math.abs(count) * 100) / values.length) || 0
+ Math.round((count * 100) / values.length)
return {
+ counts: { detractors, passives, promoters },
promoters: share(promoters),
+ passives: share(passives),
detractors: share(detractors),
- score: share(promoters - detractors),
+ score: share(promoters) - share(detractors),
}
})
@@ -921,6 +962,8 @@ export default defineComponent({
formatCount,
formatPercent,
formatPromoterShares,
+ formatScore,
+ promoterGroups: ['detractors', 'passives', 'promoters'] as const,
oneDecimal,
t,
}
@@ -1138,6 +1181,10 @@ export default defineComponent({
@container (max-width: 631px) {
grid-template-columns: repeat(3, 1fr);
+
+ > div.question-summary__figures-promoter {
+ grid-column: 1 / -1;
+ }
}
@container (max-width: 375px) {
@@ -1175,10 +1222,57 @@ export default defineComponent({
font-weight: bold;
}
+ > .question-summary__figures-promoter {
+ grid-column: span 3;
+ }
+
dd.question-summary__figures-detail {
color: var(--color-text-maxcontrast);
- font-size: 0.9em;
+ font-size: var(--default-font-size);
font-weight: normal;
}
+
+ dd.question-summary__figures-split {
+ border-radius: var(--border-radius-pill);
+ display: flex;
+ gap: 2px;
+ height: calc(var(--default-grid-baseline) * 2);
+ margin-block: var(--default-grid-baseline);
+ overflow: hidden;
+
+ > span {
+ flex-basis: 0;
+ }
+ }
+
+ .question-summary__figures-split--detractors {
+ background-color: var(--color-element-error);
+ }
+
+ .question-summary__figures-split--passives {
+ background-color: var(--color-element-warning);
+ }
+
+ .question-summary__figures-split--promoters {
+ background-color: var(--color-element-success);
+ }
+
+ @media (forced-colors: active) {
+ dd.question-summary__figures-split {
+ border: 1px solid CanvasText;
+ }
+
+ .question-summary__figures-split--detractors {
+ background-color: CanvasText;
+ }
+
+ .question-summary__figures-split--passives {
+ background-color: GrayText;
+ }
+
+ .question-summary__figures-split--promoters {
+ background-color: Highlight;
+ }
+ }
}
From 0f1aa83d90ed8e13148b5068307eb5a6d7693f2c Mon Sep 17 00:00:00 2001
From: Andy Scherzinger
Date: Sat, 21 Nov 2026 16:24:59 +0100
Subject: [PATCH 14/15] 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
---
playwright/e2e/results-scale-figures.spec.ts | 243 +++++++++++++++++++
1 file changed, 243 insertions(+)
create mode 100644 playwright/e2e/results-scale-figures.spec.ts
diff --git a/playwright/e2e/results-scale-figures.spec.ts b/playwright/e2e/results-scale-figures.spec.ts
new file mode 100644
index 000000000..0b01277c0
--- /dev/null
+++ b/playwright/e2e/results-scale-figures.spec.ts
@@ -0,0 +1,243 @@
+/**
+ * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import type { APIRequestContext } from '@playwright/test'
+
+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 resultsTest } from '../support/fixtures/results.ts'
+import { api, waitForApiResponse } from '../support/helpers.ts'
+import {
+ LinearScaleSubtype,
+ QuestionType,
+} from '../support/sections/QuestionType.ts'
+
+const test = mergeTests(randomUserTest, appNavigationTest, formTest, resultsTest)
+
+/**
+ * Create a form with the linear scale "Recommend" and one submission per answer
+ *
+ * @param request the request context of the page
+ * @param subtype the sub type of the scale, or null for a plain scale
+ * @param extraSettings further extra settings of the scale
+ * @param answers the answers to submit, one submission each
+ */
+async function createScaleForm(
+ request: APIRequestContext,
+ subtype: string | null,
+ extraSettings: Record,
+ answers: string[] = [],
+) {
+ const form = await api(request, 'POST', '/forms')
+ await api(request, 'PATCH', `/forms/${form.id}`, {
+ keyValuePairs: { submitMultiple: true },
+ })
+ const scale = await api(request, 'POST', `/forms/${form.id}/questions`, {
+ type: 'linearscale',
+ subtype,
+ text: 'Recommend',
+ })
+ if (Object.keys(extraSettings).length > 0) {
+ await api(request, 'PATCH', `/forms/${form.id}/questions/${scale.id}`, {
+ keyValuePairs: {
+ extraSettings: { ...scale.extraSettings, ...extraSettings },
+ },
+ })
+ }
+ for (const answer of answers) {
+ await api(request, 'POST', `/forms/${form.id}/submissions`, {
+ answers: { [scale.id]: [answer] },
+ })
+ }
+ return form
+}
+
+test('Scale figures and the promoter score are shown above the bars', async ({
+ page,
+ resultsView,
+}) => {
+ const form = await createScaleForm(page.request, 'promoter', {}, [
+ '10',
+ '9',
+ '7',
+ '3',
+ ])
+ await page.goto(`apps/forms/${form.hash}/results`)
+ await page.waitForURL(/\/results\/summary$/)
+
+ const summary = resultsView.getSummaryForQuestion('Recommend')
+ await expect(
+ summary.getByText(
+ 'Linear scale (0: Not at all likely, 10: Extremely likely)',
+ { exact: true },
+ ),
+ ).toBeVisible()
+ const figure = (label: string) => summary.locator(`dt:text-is("${label}") + dd`)
+ await expect(figure('Answers')).toHaveText('4')
+ await expect(figure('Average')).toHaveText('7.3')
+ await expect(figure('Median')).toHaveText('8')
+ await expect(figure('Minimum')).toHaveText('3')
+ await expect(figure('Maximum')).toHaveText('10')
+ const promoterLabel = summary.locator('dt', { hasText: 'Promoter score' })
+ await expect(promoterLabel).toBeVisible()
+ await expect(promoterLabel.locator('.hidden-visually')).toHaveText(
+ '(promoters − detractors)',
+ )
+ await expect(promoterLabel.locator('+ dd')).toHaveText('+25')
+ await expect(
+ summary.getByText('25% detractors · 25% passives · 50% promoters'),
+ ).toBeVisible()
+ await expect(summary.locator('dl + ol meter')).not.toHaveCount(0)
+})
+
+test('The promoter score is the difference of the shares it shows', async ({
+ page,
+ resultsView,
+}) => {
+ const form = await createScaleForm(page.request, 'promoter', {}, [
+ '10',
+ '9',
+ '8',
+ '8',
+ '7',
+ '6',
+ ])
+ await page.goto(`apps/forms/${form.hash}/results`)
+ await page.waitForURL(/\/results\/summary$/)
+
+ const summary = resultsView.getSummaryForQuestion('Recommend')
+ await expect(
+ summary.getByText('17% detractors · 50% passives · 33% promoters'),
+ ).toBeVisible()
+ await expect(
+ summary.locator('dt', { hasText: 'Promoter score' }).locator('+ dd'),
+ ).toHaveText('+16')
+})
+
+test('A plain 0 to 10 scale shows no promoter score', async ({
+ page,
+ resultsView,
+}) => {
+ const form = await createScaleForm(
+ page.request,
+ null,
+ { optionsLowest: 0, optionsHighest: 10 },
+ ['10', '3'],
+ )
+ await page.goto(`apps/forms/${form.hash}/results`)
+ await page.waitForURL(/\/results\/summary$/)
+
+ const summary = resultsView.getSummaryForQuestion('Recommend')
+ await expect(summary.locator('dt:text-is("Average") + dd')).toHaveText('6.5')
+ await expect(summary.getByText(/Promoter score/)).toHaveCount(0)
+})
+
+test('The scale figures leave out answers outside the scale', async ({
+ page,
+ resultsView,
+}) => {
+ const form = await createScaleForm(page.request, null, { optionsHighest: 10 }, [
+ '2',
+ '4',
+ '9',
+ ])
+ const [scale] = (await api(page.request, 'GET', `/forms/${form.id}`)).questions
+ await api(page.request, 'PATCH', `/forms/${form.id}/questions/${scale.id}`, {
+ keyValuePairs: { extraSettings: { optionsHighest: 5 } },
+ })
+ await page.goto(`apps/forms/${form.hash}/results`)
+ await page.waitForURL(/\/results\/summary$/)
+
+ const summary = resultsView.getSummaryForQuestion('Recommend')
+ const figure = (label: string) => summary.locator(`dt:text-is("${label}") + dd`)
+ await expect(figure('Answers')).toHaveText('2')
+ await expect(figure('Average')).toHaveText('3.0')
+ await expect(figure('Maximum')).toHaveText('4')
+ await expect(summary.getByText('1 (33%): 9')).toBeVisible()
+})
+
+test('A rating shows its average rating and no scale figures', async ({
+ page,
+ resultsView,
+}) => {
+ const form = await createScaleForm(page.request, 'rating', {}, ['5', '4'])
+ await page.goto(`apps/forms/${form.hash}/results`)
+ await page.waitForURL(/\/results\/summary$/)
+
+ const summary = resultsView.getSummaryForQuestion('Recommend')
+ await expect(summary.getByText('4.5 of 5', { exact: true })).toBeVisible()
+ await expect(
+ summary.getByText('Average rating 4.5 of 5, from 2 ratings'),
+ ).toHaveCount(1)
+ await expect(summary.locator('dl')).toHaveCount(0)
+ await expect(summary.getByText(/Promoter score/)).toHaveCount(0)
+})
+
+test('A promoter score question from the menu is a fixed 0 to 10 scale', async ({
+ page,
+ appNavigation,
+ form,
+}) => {
+ await page.goto('apps/forms')
+ await appNavigation.clickNewForm()
+ await form.fillTitle('Promoter form')
+
+ const created = waitForApiResponse(page, 'POST')
+ await form.addQuestion(QuestionType.LinearScale, LinearScaleSubtype.Promoter)
+ const response = await created
+ expect(response.request().postDataJSON()).toMatchObject({
+ type: 'linearscale',
+ subtype: 'promoter',
+ })
+ expect((await response.json()).ocs.data.extraSettings).toEqual({
+ questionType: 'promoter',
+ optionsLowest: 0,
+ optionsHighest: 10,
+ })
+
+ const [question] = await form.getQuestions()
+ await expect(question.section.getByRole('radio')).toHaveCount(11)
+ await expect(question.section.getByRole('radio').first()).toHaveAccessibleName(
+ '0',
+ )
+ await expect(question.section.getByRole('radio').last()).toHaveAccessibleName(
+ '10',
+ )
+ await expect(
+ question.section.getByRole('textbox', { name: 'Label for lowest value' }),
+ ).toHaveValue('Not at all likely')
+ await expect(
+ question.section.getByRole('textbox', { name: 'Label for highest value' }),
+ ).toHaveValue('Extremely likely')
+
+ await question.openActionsMenu()
+ await expect(page.getByRole('checkbox', { name: 'Required' })).toBeVisible()
+ await expect(page.getByRole('combobox', { name: 'Lowest value' })).toHaveCount(0)
+ await expect(page.getByRole('combobox', { name: 'Highest value' })).toHaveCount(
+ 0,
+ )
+})
+
+test('A numbers question from the menu has no sub type', async ({
+ page,
+ appNavigation,
+ form,
+}) => {
+ await page.goto('apps/forms')
+ await appNavigation.clickNewForm()
+ await form.fillTitle('Numbers form')
+
+ const created = waitForApiResponse(page, 'POST')
+ await form.addQuestion(QuestionType.LinearScale, LinearScaleSubtype.Numbers)
+ const response = await created
+ expect(response.request().postDataJSON().subtype).toBeNull()
+ expect((await response.json()).ocs.data.extraSettings).toEqual({})
+
+ const [question] = await form.getQuestions()
+ await question.openActionsMenu()
+ await expect(page.getByRole('combobox', { name: 'Lowest value' })).toBeVisible()
+})
From d33b990c43bab5a0b1c971962eb7b71570f7df98 Mon Sep 17 00:00:00 2001
From: Andy Scherzinger
Date: Mon, 23 Nov 2026 12:34:34 +0100
Subject: [PATCH 15/15] refactor(results): drop the minimum and maximum from
the scale figures
The lowest and highest answer add little next to the bars below, which
already show the spread of the answers. Keep the answer count, average
and median, and lay the remaining cards out in three columns.
Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Andy Scherzinger
---
playwright/e2e/results-scale-figures.spec.ts | 6 ++---
src/components/Results/ResultsSummary.vue | 28 ++++----------------
2 files changed, 8 insertions(+), 26 deletions(-)
diff --git a/playwright/e2e/results-scale-figures.spec.ts b/playwright/e2e/results-scale-figures.spec.ts
index 0b01277c0..8edeb03d1 100644
--- a/playwright/e2e/results-scale-figures.spec.ts
+++ b/playwright/e2e/results-scale-figures.spec.ts
@@ -80,8 +80,8 @@ test('Scale figures and the promoter score are shown above the bars', async ({
await expect(figure('Answers')).toHaveText('4')
await expect(figure('Average')).toHaveText('7.3')
await expect(figure('Median')).toHaveText('8')
- await expect(figure('Minimum')).toHaveText('3')
- await expect(figure('Maximum')).toHaveText('10')
+ await expect(figure('Minimum')).toHaveCount(0)
+ await expect(figure('Maximum')).toHaveCount(0)
const promoterLabel = summary.locator('dt', { hasText: 'Promoter score' })
await expect(promoterLabel).toBeVisible()
await expect(promoterLabel.locator('.hidden-visually')).toHaveText(
@@ -156,7 +156,7 @@ test('The scale figures leave out answers outside the scale', async ({
const figure = (label: string) => summary.locator(`dt:text-is("${label}") + dd`)
await expect(figure('Answers')).toHaveText('2')
await expect(figure('Average')).toHaveText('3.0')
- await expect(figure('Maximum')).toHaveText('4')
+ await expect(figure('Median')).toHaveText('3')
await expect(summary.getByText('1 (33%): 9')).toBeVisible()
})
diff --git a/src/components/Results/ResultsSummary.vue b/src/components/Results/ResultsSummary.vue
index 2ce22c101..740926ed6 100644
--- a/src/components/Results/ResultsSummary.vue
+++ b/src/components/Results/ResultsSummary.vue
@@ -25,14 +25,6 @@
{{ t('forms', 'Median') }}
{{ formatCount(numericStats.median) }}
-
-
{{ t('forms', 'Minimum') }}
- {{ formatCount(numericStats.min) }}
-
-
-
{{ t('forms', 'Maximum') }}
- {{ formatCount(numericStats.max) }}
-
{{ t('forms', 'Promoter score') }}
@@ -885,7 +877,7 @@ export default defineComponent({
})
/**
- * Answer count, average, median, minimum and maximum of a linear scale question;
+ * Answer count, average and median of a linear scale question;
* null without answers and for a rating.
*/
const numericStats = computed(() => {
@@ -909,8 +901,6 @@ export default defineComponent({
count: values.length,
mean: sum / values.length,
median,
- min: values[0],
- max: values[values.length - 1],
}
})
@@ -1174,23 +1164,15 @@ export default defineComponent({
.question-summary__figures {
display: grid;
gap: calc(var(--default-grid-baseline) * 2);
- grid-template-columns: repeat(5, 1fr);
+ grid-template-columns: repeat(3, 1fr);
margin-block: calc(var(--default-grid-baseline) * 3)
calc(var(--default-grid-baseline) * 4);
padding: 0;
- @container (max-width: 631px) {
- grid-template-columns: repeat(3, 1fr);
-
- > div.question-summary__figures-promoter {
- grid-column: 1 / -1;
- }
- }
-
@container (max-width: 375px) {
grid-template-columns: repeat(2, 1fr);
- > div:nth-child(5) {
+ > div:nth-child(3) {
grid-column: span 2;
}
}
@@ -1222,8 +1204,8 @@ export default defineComponent({
font-weight: bold;
}
- > .question-summary__figures-promoter {
- grid-column: span 3;
+ > div.question-summary__figures-promoter {
+ grid-column: 1 / -1;
}
dd.question-summary__figures-detail {