Files
sub2api/frontend/src/components/common/__tests__/BaseDialog.spec.ts
T
IanShaw027 2526a04226 fix(admin): empty web-search config on missing setting and reset dialog scroll
Return a disabled empty web-search-emulation config when the setting key is
absent, and reset BaseDialog body scroll on open for long modals.
2026-08-08 01:07:27 +08:00

38 lines
1.1 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import { nextTick } from 'vue'
import BaseDialog from '../BaseDialog.vue'
vi.mock('vue-i18n', () => ({
useI18n: () => ({ t: (key: string) => key })
}))
describe('BaseDialog', () => {
afterEach(() => {
document.body.innerHTML = ''
document.body.classList.remove('modal-open')
})
it('resets body scroll position when reopened', async () => {
const wrapper = mount(BaseDialog, {
attachTo: document.body,
props: { show: false, title: 'Details' },
slots: { default: '<div style="height: 2000px">content</div>' },
global: { stubs: { Icon: true } }
})
await wrapper.setProps({ show: true })
await nextTick()
const body = document.body.querySelector<HTMLElement>('.modal-body')
expect(body).not.toBeNull()
body!.scrollTop = 480
await wrapper.setProps({ show: false })
await wrapper.setProps({ show: true })
await nextTick()
expect(document.body.querySelector<HTMLElement>('.modal-body')?.scrollTop).toBe(0)
wrapper.unmount()
})
})