// Smoke tests of My account item rows (Phase 32.2 UI-SPEC C3): a section // without Items renders as before, an empty Items list renders the dashed // empty block, and a danger item action confirms with :title filled and // posts the item route. Fixtures are neutral acme.* data. import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { enableAutoUnmount, flushPromises } from '@vue/test-utils' import { setBundle } from '../../src/app/i18n' import { toasts } from '../../src/state/useToasts' import { langFixture } from '../fixtures/typed' import { API, mountApp, profile, requestsTo, resetState, type Route } from '../helpers' const CONTRIBUTIONS = `${API}/account/contributions` // openapi-fetch encodes each path parameter once. const REVOKE = `${API}/account/contribution-items/agents/client%3A1/actions/revoke` const envelope = (data: unknown) => ({ body: { data, meta: {} } }) const plain = { name: 'site_link', label: 'Site account', description: '', status: 'Not linked', actions: [{ name: 'open', label: 'Link account', confirm: '', danger: false }], items: null, item_actions: null, items_empty: '', } const agents = { name: 'agents', label: 'Connected agents', description: '', status: 'Connector address: https://example.test/mcp', actions: [], items: [ { id: 'client:1', title: 'Acme Agent', subtitle: 'Read the admin, Acme', meta: ['Connected 2026-11-01', 'Never used'] }, ], item_actions: [{ name: 'revoke', label: 'Revoke', confirm: 'Revoke the connection “:title”?', danger: true }], items_empty: '', } async function openAccount(routes: Record) { return mountApp( '/account', { [`GET ${API}/auth/me`]: envelope(profile.data), [`GET ${API}/account/tokens`]: envelope([]), ...routes, }, { attach: true }, ) } beforeEach(() => { resetState() setBundle( { ...langFixture.data, 'backend::lang.myaccount.items_empty': { other: 'Nothing here yet.' }, 'backend::lang.myaccount.item_action_named': { other: ':action: :title' }, }, 'en', ) }) afterEach(() => { document.body.innerHTML = '' vi.restoreAllMocks() }) enableAutoUnmount(afterEach) describe('My account item rows (UI-SPEC C3)', () => { it('a section without items renders no list and no empty block', async () => { const { wrapper } = await openAccount({ [`GET ${CONTRIBUTIONS}`]: envelope([plain]) }) const card = wrapper.find('[data-account-contribution="site_link"]') expect(card.find('[data-account-contribution-status]').text()).toBe('Not linked') expect(card.find('[data-account-contribution-action="open"]').exists()).toBe(true) expect(card.find('[role="list"]').exists()).toBe(false) expect(card.find('[data-account-items-empty]').exists()).toBe(false) }) it('a section with items [] renders the empty block under the status line', async () => { const { wrapper } = await openAccount({ [`GET ${CONTRIBUTIONS}`]: envelope([{ ...agents, items: [] }]) }) const card = wrapper.find('[data-account-contribution="agents"]') expect(card.find('[data-account-contribution-status]').exists()).toBe(true) expect(card.find('[data-account-items-empty]').text()).toBe('Nothing here yet.') expect(card.find('[data-account-item]').exists()).toBe(false) }) it('a danger item action confirms with :title filled and posts the item route', async () => { let loads = 0 const { wrapper, calls } = await openAccount({ [`GET ${CONTRIBUTIONS}`]: () => { loads++ return envelope([loads === 1 ? agents : { ...agents, items: [] }]) }, [`POST ${REVOKE}`]: envelope({ message: 'Connection revoked', url: '' }), }) const row = wrapper.find('[data-account-item="client:1"]') expect(row.attributes('role')).toBe('listitem') expect(row.text()).toContain('Acme Agent') expect(row.text()).toContain('Connected 2026-11-01 · Never used') const button = row.find('[data-account-item-action="revoke"]') expect(button.attributes('aria-label')).toBe('Revoke: Acme Agent') await button.trigger('click') await flushPromises() const dialog = document.body.querySelector('[data-confirm-dialog]') expect(dialog?.textContent).toContain('Revoke the connection “Acme Agent”?') expect(requestsTo(calls, 'POST', REVOKE)).toHaveLength(0) dialog!.querySelector('[data-action="confirm"]')!.click() await flushPromises() expect(requestsTo(calls, 'POST', REVOKE)).toHaveLength(1) expect(toasts.value.map((toast) => toast.text)).toEqual(['Connection revoked']) expect(requestsTo(calls, 'GET', CONTRIBUTIONS)).toHaveLength(2) expect(wrapper.find('[data-account-items-empty]').exists()).toBe(true) expect(document.activeElement?.textContent).toBe('Connected agents') }) })