Skip to content

Commit 314714e

Browse files
authored
test(ui): pin the outlined fields and primitive controls of six forms (#1308)
The form rule of the content migration (task 6.3) had no test, so a filled text field or a hand-built radio button or checkbox could slip back into these forms unnoticed. A shared helper now asserts that every text field is outlined and that every radio button and checkbox is an MdRadio or MdCheckbox, and the tests of CreateTokenDialog, PolicyDialog, SearchFilters (new test file), AuditView, PasswordCard and FileUpload call it. Signed-off-by: TheMeinerLP <github@themeinerlp.dev>
1 parent 0913c64 commit 314714e

7 files changed

Lines changed: 124 additions & 6 deletions

File tree

‎reposilite-frontend/src/components/account/PasswordCard.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { describe, it, expect, vi, beforeEach, afterEach, type Mock } from 'vite
1818
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
1919
import PasswordCard from './PasswordCard.vue'
2020
import { useSession } from '../../store/session'
21+
import { expectPrimitiveControls } from '../../helpers/primitiveControls'
2122

2223
const toast = vi.hoisted(() => ({ success: vi.fn() }))
2324

@@ -196,6 +197,12 @@ describe('PasswordCard', () => {
196197
expect(section.find('h3').text()).toBe('Change password')
197198
})
198199

200+
it('builds its text fields from primitives', () => {
201+
mountCard()
202+
203+
expectPrimitiveControls(wrapper)
204+
})
205+
199206
it('keeps the password card labelled by its section heading', () => {
200207
mountCard()
201208

‎reposilite-frontend/src/components/audit/AuditView.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { describe, it, expect, beforeEach, vi } from 'vitest'
2-
import { mount, flushPromises } from '@vue/test-utils'
2+
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
33
import { createRouter, createMemoryHistory } from 'vue-router'
44
import download from 'downloadjs'
55
import AuditView from './AuditView.vue'
6+
import { expectPrimitiveControls } from '../../helpers/primitiveControls'
67

78
// The client is swapped per test through this holder, as in the token view tests.
89
// The holder is set in beforeEach, so the null start is never read.
@@ -146,6 +147,15 @@ describe('AuditView loading', () => {
146147
})
147148
})
148149

150+
describe('AuditView controls', () => {
151+
it('builds its text fields from primitives', async () => {
152+
const wrapper = await mountView()
153+
154+
expectPrimitiveControls(wrapper as VueWrapper)
155+
wrapper.unmount()
156+
})
157+
})
158+
149159
describe('AuditView paging', () => {
150160
it('loads the next page with its cursor and adds the rows after the ones on screen', async () => {
151161
session.client = fakeClient({

‎reposilite-frontend/src/components/browser/FileUpload.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
1919
import { nextTick } from 'vue'
2020
import FileUpload from './FileUpload.vue'
2121
import MdCard from '../md/MdCard.vue'
22+
import { expectPrimitiveControls } from '../../helpers/primitiveControls'
2223

2324
// Every deploy stays pending, so a test can look at the form while the upload is in flight.
2425
const { deploy } = vi.hoisted(() => ({ deploy: { calls: [] as unknown[][] } }))
@@ -102,6 +103,22 @@ describe('FileUpload while an upload is in flight', () => {
102103
})
103104
})
104105

106+
describe('FileUpload primitives', () => {
107+
afterEach(() => {
108+
wrapper?.unmount()
109+
wrapper = undefined
110+
})
111+
112+
it('builds its text fields and checkboxes from primitives', async () => {
113+
await mountUpload()
114+
await selectFile('example-1.0.jar')
115+
await wrapper!.findAll('input[type="checkbox"]').find(box => (box.element as HTMLInputElement).labels?.[0]?.textContent?.includes('stub POM'))?.setValue(true)
116+
await nextTick()
117+
118+
expectPrimitiveControls(wrapper!)
119+
})
120+
})
121+
105122
describe('FileUpload controls', () => {
106123
afterEach(() => {
107124
wrapper?.unmount()

‎reposilite-frontend/src/components/identity/CreateTokenDialog.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { describe, it, expect, vi, beforeEach, afterEach, type Mock } from 'vite
1818
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
1919
import CreateTokenDialog from './CreateTokenDialog.vue'
2020
import MdFieldset from '../md/MdFieldset.vue'
21+
import { expectPrimitiveControls } from '../../helpers/primitiveControls'
2122
import type { IdentityTokenApi } from './identityTokens'
2223
import type { components } from '../../types/api'
2324
import { setClock, resetClock } from '../../helpers/clock'
@@ -74,6 +75,10 @@ describe('CreateTokenDialog', () => {
7475
resetClock()
7576
})
7677

78+
it('builds its text fields, radio buttons and checkboxes from primitives', () => {
79+
expectPrimitiveControls(wrapper, document.body)
80+
})
81+
7782
it('names the dialog after its heading', () => {
7883
const heading = dialog().querySelector('h2') as HTMLHeadingElement
7984

‎reposilite-frontend/src/components/maintenance/PolicyDialog.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
1919
import PolicyDialog from './PolicyDialog.vue'
2020
import MdFieldset from '../md/MdFieldset.vue'
2121
import type { PolicyPayload } from './policy'
22+
import { expectPrimitiveControls } from '../../helpers/primitiveControls'
2223

2324
let wrapper!: VueWrapper
2425

@@ -55,6 +56,14 @@ afterEach(() => {
5556
wrapper?.unmount()
5657
})
5758

59+
describe('PolicyDialog controls', () => {
60+
it('builds its text fields from primitives', async () => {
61+
await openDialog()
62+
63+
expectPrimitiveControls(wrapper, document.body)
64+
})
65+
})
66+
5867
describe('PolicyDialog validation', () => {
5968
it('does not send a policy with an empty id', async () => {
6069
await openDialog()

‎reposilite-frontend/src/components/search/SearchFilters.test.ts‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,34 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { describe, it, expect } from 'vitest'
18-
import { mount } from '@vue/test-utils'
17+
import { describe, it, expect, afterEach } from 'vitest'
18+
import { mount, type VueWrapper } from '@vue/test-utils'
1919
import MdFieldset from '../md/MdFieldset.vue'
2020
import SearchFilters from './SearchFilters.vue'
21-
import { DEFAULT_QUERY } from './searchQuery'
21+
import { DEFAULT_QUERY, parseSearchQuery } from './searchQuery'
22+
import type { Facets } from './searchResult'
23+
import { expectPrimitiveControls } from '../../helpers/primitiveControls'
2224

23-
const facets = { repository: [], extension: [], classifier: [], origin: [], snapshot: [] }
25+
const emptyFacets = { repository: [], extension: [], classifier: [], origin: [], snapshot: [] }
26+
27+
const facets: Facets = {
28+
repository: [{ value: 'releases', count: 4 }],
29+
extension: [{ value: 'jar', count: 3 }],
30+
classifier: [{ value: 'sources', count: 1 }],
31+
origin: [{ value: 'HOSTED', count: 4 }],
32+
snapshot: [{ value: 'false', count: 4 }]
33+
}
34+
35+
let wrapper: VueWrapper | undefined
36+
37+
afterEach(() => {
38+
wrapper?.unmount()
39+
wrapper = undefined
40+
})
2441

2542
describe('SearchFilters', () => {
2643
it('titles each group of filters with the legend of a shared fieldset', () => {
27-
const wrapper = mount(SearchFilters, { props: { query: { ...DEFAULT_QUERY }, facets } })
44+
const wrapper = mount(SearchFilters, { props: { query: { ...DEFAULT_QUERY }, facets: emptyFacets } })
2845

2946
const legends = wrapper.findAllComponents(MdFieldset).map(group => group.find('legend').text())
3047

@@ -34,3 +51,11 @@ describe('SearchFilters', () => {
3451
expect(wrapper.findAll('fieldset'), 'no hand-written fieldset is left').toHaveLength(legends.length)
3552
})
3653
})
54+
55+
describe('SearchFilters controls', () => {
56+
it('builds its text fields from primitives', () => {
57+
wrapper = mount(SearchFilters, { props: { query: parseSearchQuery(), facets } }) as VueWrapper
58+
59+
expectPrimitiveControls(wrapper)
60+
})
61+
})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2026 OneLiteFeather
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { expect } from 'vitest'
18+
import type { VueWrapper } from '@vue/test-utils'
19+
import MdTextField from '../components/md/MdTextField.vue'
20+
import MdRadio from '../components/md/MdRadio.vue'
21+
import MdCheckbox from '../components/md/MdCheckbox.vue'
22+
23+
/*
24+
* The form rule of the dashboard, as an assertion for the test of a component: every text field is the
25+
* default `outlined` variant, and every radio button and checkbox on the screen is drawn by a primitive,
26+
* never by a hand-built native input. `root` is the element to look into; a dialog is teleported, so it
27+
* is `document.body` there.
28+
*/
29+
const expectPrimitiveControls = (wrapper: VueWrapper, scope?: ParentNode) => {
30+
const root: ParentNode = scope ?? (wrapper.element as Element)
31+
const variants = wrapper.findAllComponents(MdTextField).map(field => field.props('variant') as string)
32+
expect(variants.length, 'the component draws text fields').toBeGreaterThan(0)
33+
expect(variants.every(variant => variant === 'outlined'), `every text field is outlined, got ${variants.join(', ')}`).toBe(true)
34+
35+
expect(
36+
root.querySelectorAll('input[type="radio"]').length,
37+
'every radio button is an MdRadio'
38+
).toBe(wrapper.findAllComponents(MdRadio).length)
39+
expect(
40+
root.querySelectorAll('input[type="checkbox"]').length,
41+
'every checkbox is an MdCheckbox'
42+
).toBe(wrapper.findAllComponents(MdCheckbox).length)
43+
}
44+
45+
export { expectPrimitiveControls }

0 commit comments

Comments
 (0)