Skip to content

Commit da9fec6

Browse files
authored
test(forms): the application form offers only the licences its licence type allows (#2101)
The required nextcloud-vue (2.181.0) narrows a dependent field's options with x-openregister-dependent-values; a vitest runs the library's own narrowing over the app's tables, and the Playwright spec is written. Ticks the Implement item of landscape-dependent-field-options task 3. Assisted-by: ClaudeCode:claude-opus-5-5
1 parent 20e834c commit da9fec6

3 files changed

Lines changed: 186 additions & 2 deletions

File tree

‎openspec/changes/landscape-dependent-field-options/tasks.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
- **files**: `package.json`, `package-lock.json`
2525
- **acceptance_criteria**:
2626
- GIVEN the application form WHEN the licence type is Closed source THEN the licence field offers no options
27-
- [ ] Implement (after ConductionNL/nextcloud-vue releases CnFormDialog support for x-openregister-dependent-values)
28-
- [ ] Test (Playwright `tests/e2e/workflows/dependent-field-options.spec.ts`)
27+
- [x] Implement (after ConductionNL/nextcloud-vue releases CnFormDialog support for x-openregister-dependent-values)
28+
> 21 Nov: released; `package.json` already requires `@conduction/nextcloud-vue` `^2.181.0` (lock 2.181.0), whose CnFormDialog narrows a field's options with `narrowToDependentValues()` and clears a value its new row does not allow. `tests/vitest/dependentFieldOptionsForm.spec.js` (5) runs the library's own methods over the merged module and organisation schemas: no licence for Closed source, the five open-source licences for Open source, the full list with no licence type, and collaboration types only for a collaboration.
29+
- [ ] Test (Playwright `tests/e2e/workflows/dependent-field-options.spec.ts`: written from the scenario, not yet run against a live instance)
2930

3031
## Verification
3132

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// SPDX-License-Identifier: EUPL-1.2
2+
// SPDX-FileCopyrightText: 2026 Conduction B.V.
3+
/**
4+
* Dependent field options: the edit form of an application offers no licence
5+
* while its licence type is Closed source, and the five open-source licences
6+
* once the licence type is Open source.
7+
*
8+
* Seeds one closed-source application carrying this run's RUN_ID through the
9+
* objects API and removes it afterwards. The narrowing itself is covered by
10+
* tests/vitest/dependentFieldOptionsForm.spec.js and the save rule by
11+
* tests/Unit/Settings/DependentFieldOptionsTest.php.
12+
*
13+
* Written from the change's scenario; not yet run against a live instance.
14+
*
15+
* @spec openspec/changes/landscape-dependent-field-options/specs/dependent-field-options/spec.md#requirement-req-dfo-003-the-form-offers-only-the-allowed-options
16+
*/
17+
import type { APIRequestContext } from '@playwright/test'
18+
import type { VoorzieningenConfig } from './_fixtures.ts'
19+
20+
import { expect, test } from '@playwright/test'
21+
import {
22+
createObject,
23+
deleteObject,
24+
newApiContext,
25+
resolveConfig,
26+
RUN_ID,
27+
} from './_fixtures.ts'
28+
import { dismissSupportDialog, gotoAppRoute } from './_ui.ts'
29+
30+
const OPEN_SOURCE_LICENCES = [
31+
'MIT License',
32+
'GNU General Public License (GPL)',
33+
'Apache License 2.0',
34+
'BSD License (Berkeley Software Distribution)',
35+
'European Union Public Licence (EUPL), version 1.2',
36+
]
37+
38+
let apiCtx: APIRequestContext
39+
let cfg: VoorzieningenConfig
40+
let moduleId = ''
41+
42+
test.beforeAll(async () => {
43+
apiCtx = await newApiContext()
44+
cfg = await resolveConfig(apiCtx)
45+
moduleId = await createObject(apiCtx, cfg.register, 'module', {
46+
name: `${RUN_ID} closed application`,
47+
licentietype: 'Closed source',
48+
})
49+
})
50+
51+
test.afterAll(async () => {
52+
if (!apiCtx) return
53+
if (moduleId) {
54+
await deleteObject(apiCtx, cfg.register, 'module', moduleId)
55+
}
56+
await apiCtx.dispose()
57+
})
58+
59+
// @e2e dependent-field-options::switching-an-application-to-open-source-opens-the-licence-list
60+
test('switching an application to open source opens the licence list', async ({ page }) => {
61+
await gotoAppRoute(page, `/modules/${moduleId}`)
62+
await dismissSupportDialog(page)
63+
await page.getByRole('button', { name: 'Edit', exact: true }).first().click()
64+
const dialog = page.locator('[role="dialog"], .modal-container').first()
65+
await dialog.waitFor({ state: 'visible', timeout: 15000 })
66+
67+
const licence = dialog.getByLabel('License', { exact: true }).first()
68+
await licence.click()
69+
await expect(page.getByRole('option')).toHaveCount(0)
70+
await page.keyboard.press('Escape')
71+
72+
const licenceType = dialog.getByLabel('License type').first()
73+
await licenceType.click()
74+
await page.getByRole('option', { name: 'Open source', exact: true }).first().click()
75+
76+
await licence.click()
77+
const options = page.getByRole('option')
78+
await expect(options).toHaveCount(OPEN_SOURCE_LICENCES.length, { timeout: 15000 })
79+
for (const name of OPEN_SOURCE_LICENCES) {
80+
await expect(page.getByRole('option', { name, exact: true })).toBeVisible()
81+
}
82+
})
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// @vitest-environment jsdom
2+
/**
3+
* SPDX-License-Identifier: EUPL-1.2
4+
* Copyright (C) 2026 Conduction B.V.
5+
*
6+
* The application form offers only the licences its licence type allows, and
7+
* the organisation form only the collaboration types its type allows: the
8+
* library's CnFormDialog (from @conduction/nextcloud-vue 2.181.0, the version
9+
* package.json requires) narrows its options with the
10+
* x-openregister-dependent-values tables of lib/Settings/register.d/
11+
* dependent-field-options.json.
12+
*
13+
* The methods run with the merged schema as `this`, so the test reads the
14+
* library's real narrowing over the app's real tables.
15+
*
16+
* @spec openspec/changes/landscape-dependent-field-options/specs/dependent-field-options/spec.md#requirement-req-dfo-003-the-form-offers-only-the-allowed-options
17+
*/
18+
import * as fs from 'fs'
19+
import * as path from 'path'
20+
import { describe, expect, it } from 'vitest'
21+
22+
const root = path.resolve(__dirname, '../..')
23+
const read = (file) => JSON.parse(fs.readFileSync(path.join(root, file), 'utf8'))
24+
25+
const monolith = read('lib/Settings/softwarecatalogus_register.json')
26+
const tables = read('lib/Settings/register.d/dependent-field-options.json')
27+
28+
/**
29+
* A schema of the monolith with the fragment's dependent-values tables merged in.
30+
*
31+
* @param {string} slug The schema slug.
32+
* @return {object} The merged schema.
33+
*/
34+
function mergedSchema(slug) {
35+
const base = monolith.components.schemas[slug]
36+
const overlay = tables.components.schemas[slug].properties
37+
const properties = { ...base.properties }
38+
for (const [key, value] of Object.entries(overlay)) {
39+
properties[key] = { ...properties[key], ...value }
40+
}
41+
return { ...base, properties }
42+
}
43+
44+
/**
45+
* The options the form offers for a field, given the controlling value.
46+
*
47+
* @param {object} methods CnFormDialog's methods.
48+
* @param {object} schema The schema.
49+
* @param {string} key The dependent field.
50+
* @param {object} formData The form values.
51+
* @return {Array<string>} The offered option values.
52+
*/
53+
function offered(methods, schema, key, formData) {
54+
const context = { schema, formData }
55+
context.dependentValuesOf = methods.dependentValuesOf.bind(context)
56+
context.dependentAllowed = methods.dependentAllowed.bind(context)
57+
const property = schema.properties[key]
58+
const values = property.enum || property.items?.enum || []
59+
const options = values.map((value) => ({ id: value, label: value }))
60+
return methods.narrowToDependentValues.call(context, { key }, options).map((option) => option.id)
61+
}
62+
63+
const { default: CnFormDialog } = await import('../../node_modules/@conduction/nextcloud-vue/src/components/CnFormDialog/CnFormDialog.vue')
64+
const { methods } = CnFormDialog
65+
66+
describe('the package the form support comes from', () => {
67+
it('requires a nextcloud-vue whose CnFormDialog reads the dependent-values tables', () => {
68+
const pkg = read('package.json')
69+
expect(pkg.dependencies['@conduction/nextcloud-vue']).toMatch(/^\^2\.(18[1-9]|19\d|[2-9]\d\d)\./)
70+
expect(typeof methods.narrowToDependentValues).toBe('function')
71+
expect(typeof methods.dependentAllowed).toBe('function')
72+
})
73+
})
74+
75+
describe('the application form', () => {
76+
const schema = mergedSchema('module')
77+
78+
it('offers no licence when the licence type is Closed source', () => {
79+
expect(offered(methods, schema, 'licence', { licentietype: 'Closed source' })).toEqual([])
80+
})
81+
82+
it('offers the open-source licences when the licence type is Open source', () => {
83+
const licences = offered(methods, schema, 'licence', { licentietype: 'Open source' })
84+
expect(licences).toEqual(tables.components.schemas.module.properties.licence['x-openregister-dependent-values'].allowed['Open source'])
85+
expect(licences).toContain('European Union Public Licence (EUPL), version 1.2')
86+
})
87+
88+
it('leaves the licence open while no licence type is chosen', () => {
89+
const all = schema.properties.licence.enum || schema.properties.licence.items?.enum
90+
expect(offered(methods, schema, 'licence', {})).toEqual(all)
91+
})
92+
})
93+
94+
describe('the organisation form', () => {
95+
const schema = mergedSchema('organization')
96+
97+
it('offers collaboration types only for a collaboration', () => {
98+
expect(offered(methods, schema, 'samenwerkingtype', { type: 'Municipality' })).toEqual([])
99+
expect(offered(methods, schema, 'samenwerkingtype', { type: 'Collaboration' })).toContain('Shared Service Center')
100+
})
101+
})

0 commit comments

Comments
 (0)