2026-07-27 15:53:28 +08:00
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
import { createApp, defineComponent, h, nextTick, ref } from 'vue'
|
|
|
|
|
|
|
|
|
|
import JsonImportInput from '@/components/common/JsonImportInput.vue'
|
|
|
|
|
import { createI18n } from '@/i18n'
|
|
|
|
|
|
|
|
|
|
describe('JsonImportInput', () => {
|
|
|
|
|
it('keeps both mode panels in one layout track while switching modes', async () => {
|
|
|
|
|
const value = ref('')
|
|
|
|
|
const Host = defineComponent({
|
|
|
|
|
setup() {
|
|
|
|
|
return () => h(JsonImportInput, {
|
|
|
|
|
modelValue: value.value,
|
|
|
|
|
'onUpdate:modelValue': (nextValue: string) => {
|
|
|
|
|
value.value = nextValue
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
const root = document.createElement('div')
|
|
|
|
|
document.body.appendChild(root)
|
|
|
|
|
const app = createApp(Host)
|
|
|
|
|
app.use(createI18n())
|
|
|
|
|
app.mount(root)
|
|
|
|
|
|
|
|
|
|
const panels = root.querySelector<HTMLElement>('[data-testid="json-import-mode-panels"]')
|
|
|
|
|
const filePanel = root.querySelector<HTMLElement>('[data-testid="json-import-file-panel"]')
|
|
|
|
|
const manualPanel = root.querySelector<HTMLElement>('[data-testid="json-import-manual-panel"]')
|
|
|
|
|
expect(panels?.classList.contains('grid')).toBe(true)
|
|
|
|
|
expect(filePanel?.getAttribute('aria-hidden')).toBe('false')
|
|
|
|
|
expect(filePanel?.hasAttribute('inert')).toBe(false)
|
|
|
|
|
expect(manualPanel?.getAttribute('aria-hidden')).toBe('true')
|
2026-09-07 21:14:27 +08:00
|
|
|
expect(manualPanel?.hasAttribute('inert')).toBe(true)
|
2026-07-27 15:53:28 +08:00
|
|
|
|
|
|
|
|
root.querySelector<HTMLButtonElement>('[data-testid="json-import-mode-toggle"]')?.click()
|
|
|
|
|
await nextTick()
|
|
|
|
|
|
|
|
|
|
expect(root.querySelector('[data-testid="json-import-file-panel"]')).toBe(filePanel)
|
|
|
|
|
expect(root.querySelector('[data-testid="json-import-manual-panel"]')).toBe(manualPanel)
|
|
|
|
|
expect(filePanel?.getAttribute('aria-hidden')).toBe('true')
|
2026-09-07 21:14:27 +08:00
|
|
|
expect(filePanel?.hasAttribute('inert')).toBe(true)
|
2026-07-27 15:53:28 +08:00
|
|
|
expect(manualPanel?.getAttribute('aria-hidden')).toBe('false')
|
|
|
|
|
expect(manualPanel?.hasAttribute('inert')).toBe(false)
|
|
|
|
|
|
|
|
|
|
const textarea = root.querySelector<HTMLTextAreaElement>('textarea')
|
|
|
|
|
if (!textarea) throw new Error('Expected manual textarea')
|
|
|
|
|
textarea.value = 'credential-value'
|
|
|
|
|
textarea.dispatchEvent(new Event('input', { bubbles: true }))
|
|
|
|
|
await nextTick()
|
|
|
|
|
expect(value.value).toBe('credential-value')
|
|
|
|
|
|
|
|
|
|
root.querySelector<HTMLButtonElement>('[data-testid="json-import-mode-toggle"]')?.click()
|
|
|
|
|
await nextTick()
|
|
|
|
|
expect(value.value).toBe('')
|
|
|
|
|
expect(filePanel?.hasAttribute('inert')).toBe(false)
|
2026-09-07 21:14:27 +08:00
|
|
|
expect(manualPanel?.hasAttribute('inert')).toBe(true)
|
2026-07-27 15:53:28 +08:00
|
|
|
|
|
|
|
|
app.unmount()
|
|
|
|
|
root.remove()
|
|
|
|
|
})
|
|
|
|
|
})
|