forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackageSidebar.spec.ts
More file actions
48 lines (36 loc) · 1.32 KB
/
PackageSidebar.spec.ts
File metadata and controls
48 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { afterEach, describe, expect, it } from 'vitest'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import type { VueWrapper } from '@vue/test-utils'
import Sidebar from '~/components/Package/Sidebar.vue'
const VIEWPORT_HEIGHT = window.innerHeight
function mountSidebar(contentHeight?: number) {
return mountSuspended(Sidebar, {
attachTo: document.body,
slots: contentHeight
? { default: () => h('div', { style: `height:${contentHeight}px` }) }
: { default: () => 'Sidebar Content' },
})
}
describe('PackageSidebar', () => {
let wrapper: VueWrapper
afterEach(() => {
wrapper?.unmount()
})
it('renders slot content', async () => {
wrapper = await mountSidebar()
expect(wrapper.text()).toContain('Sidebar Content')
})
it('sets active=false when content is shorter than viewport', async () => {
wrapper = await mountSidebar(100)
expect(wrapper.attributes('data-active')).toBe('false')
})
it('sets active=true when content is taller than viewport', async () => {
wrapper = await mountSidebar(VIEWPORT_HEIGHT + 500)
await nextTick()
expect(wrapper.attributes('data-active')).toBe('true')
})
it('renders with direction=up by default', async () => {
wrapper = await mountSidebar()
expect(wrapper.attributes('data-direction')).toBe('up')
})
})