ray-template/__test__/components/disabled-directive.spec.ts
XiaoDaiGua-Ray 15b1da763f
fix: address system-wide UI and data review findings
Restore keyboard navigation and fix page refresh, icons, and table interactions.

Guard concurrent edits and align Mock persistence with the API contracts.
2026-11-18 10:25:41 +08:00

38 lines
1.1 KiB
TypeScript

import { mount } from '@vue/test-utils'
import { defineComponent, h, ref, withDirectives } from 'vue'
import disabled from '../../packages/directives/src/modules/disabled'
it('restores a native button and toggles the whole form without changing its children', async () => {
const value = ref(false)
const directive = disabled()
const wrapper = mount(
defineComponent(
() => () =>
h('div', [
withDirectives(h('button'), [[directive, value.value]]),
withDirectives(h('form', [h('input', { disabled: true })]), [
[directive, value.value],
]),
]),
),
)
try {
const button = wrapper.get('button').element
const form = wrapper.get('form').element
expect(button.disabled).toBe(false)
value.value = true
await wrapper.vm.$nextTick()
expect(button.disabled).toBe(true)
expect(form.hasAttribute('inert')).toBe(true)
value.value = false
await wrapper.vm.$nextTick()
expect(button.disabled).toBe(false)
expect(form.hasAttribute('inert')).toBe(false)
expect(wrapper.get('input').element.disabled).toBe(true)
} finally {
wrapper.unmount()
}
})