fix(36): polish ScopePicker search collapse, unique panel IDs, and lazy catalog expand

This commit is contained in:
Jakub Zych
2026-11-25 01:29:28 +01:00
parent 51b60b94b8
commit bfb0bee809
7 changed files with 158 additions and 25 deletions

View File

@@ -306,4 +306,111 @@ describe('ScopePicker.vue', () => {
expect(wrapper.find('[data-scope-filter="selected"]').text()).toBe('Selected (1)')
expect((wrapper.find('[data-action="scope-picker-apply"]').element as HTMLButtonElement).disabled).toBe(false)
})
it('allows collapsing matching groups during search without mutating pre-search expand state (IN-02)', async () => {
const wrapper = mountInteractivePicker({ catalog: smallCatalog })
await flushPromises()
// Collapse SEO before searching (Journal stays expanded, SEO collapsed).
const togglesBefore = wrapper.findAll('[data-scope-group-toggle]')
await togglesBefore[1]!.trigger('click')
await flushPromises()
expect(wrapper.findAll('[data-scope-group-toggle]').map((b) => b.attributes('aria-expanded'))).toEqual([
'true',
'false',
])
// Search for "SEO" -> auto-expands SEO.
const search = wrapper.find('[data-scope-search]')
await search.setValue('seo')
await flushPromises()
expect(wrapper.find('[data-scope-group-toggle]').attributes('aria-expanded')).toBe('true')
// User can temporarily collapse the matching group during search.
await wrapper.find('[data-scope-group-toggle]').trigger('click')
await flushPromises()
expect(wrapper.find('[data-scope-group-toggle]').attributes('aria-expanded')).toBe('false')
// Changing the query re-expands matching groups; clearing restores exact pre-search state.
await search.setValue('seo:read')
await flushPromises()
expect(wrapper.find('[data-scope-group-toggle]').attributes('aria-expanded')).toBe('true')
await wrapper.find('[data-action="clear-scope-search"]').trigger('click')
await flushPromises()
expect(wrapper.findAll('[data-scope-group-toggle]').map((b) => b.attributes('aria-expanded'))).toEqual([
'true',
'false',
])
})
it('uses unique per-instance panel IDs and initializes smart expansion when catalog loads lazily (IN-03)', async () => {
const DualHarness = defineComponent({
components: { ScopePicker },
setup() {
const aRead = ref(false)
const aScopes = ref<Set<string>>(new Set())
const bRead = ref(false)
const bScopes = ref<Set<string>>(new Set())
return { catalog: smallCatalog, aRead, aScopes, bRead, bScopes }
},
template: `
<div>
<div data-first>
<ScopePicker
:catalog="catalog"
v-model:draft-admin-read="aRead"
v-model:draft-scopes="aScopes"
cancel-label="Cancel"
/>
</div>
<div data-second>
<ScopePicker
:catalog="catalog"
v-model:draft-admin-read="bRead"
v-model:draft-scopes="bScopes"
cancel-label="Cancel"
/>
</div>
</div>
`,
})
const dual = mount(DualHarness, { attachTo: document.body })
await flushPromises()
const firstPanelId = dual.find('[data-first] [data-scope-group-toggle]').attributes('aria-controls')
const secondPanelId = dual.find('[data-second] [data-scope-group-toggle]').attributes('aria-controls')
expect(firstPanelId).toBeTruthy()
expect(secondPanelId).toBeTruthy()
expect(firstPanelId).not.toBe(secondPanelId)
// Lazy catalog: starts empty, then populates with smallCatalog -> smart expand triggers automatically.
const lazyCatalog = ref<AdminAPITokenScope[]>([])
const LazyHarness = defineComponent({
components: { ScopePicker },
setup() {
const draftAdminRead = ref(false)
const draftScopes = ref<Set<string>>(new Set())
return { lazyCatalog, draftAdminRead, draftScopes }
},
template: `
<ScopePicker
:catalog="lazyCatalog"
v-model:draft-admin-read="draftAdminRead"
v-model:draft-scopes="draftScopes"
cancel-label="Cancel"
/>
`,
})
const lazy = mount(LazyHarness, { attachTo: document.body })
await flushPromises()
expect(lazy.findAll('[data-scope-group]')).toHaveLength(0)
lazyCatalog.value = smallCatalog
await flushPromises()
expect(lazy.findAll('[data-scope-group-toggle]').map((b) => b.attributes('aria-expanded'))).toEqual([
'true',
'true',
])
})
})