mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-31 08:25:35 +00:00
Return a disabled empty web-search-emulation config when the setting key is absent, and reset BaseDialog body scroll on open for long modals.
38 lines
1.1 KiB
TypeScript
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()
|
|
})
|
|
})
|