forked from
npmx.dev/npmx.dev
[READ-ONLY]
a fast, modern browser for the npm registry
1import { afterEach, describe, expect, it } from 'vitest'
2import { mountSuspended } from '@nuxt/test-utils/runtime'
3import type { VueWrapper } from '@vue/test-utils'
4import Sidebar from '~/components/Package/Sidebar.vue'
5
6const VIEWPORT_HEIGHT = window.innerHeight
7
8function mountSidebar(contentHeight?: number) {
9 return mountSuspended(Sidebar, {
10 attachTo: document.body,
11 slots: contentHeight
12 ? { default: () => h('div', { style: `height:${contentHeight}px` }) }
13 : { default: () => 'Sidebar Content' },
14 })
15}
16
17describe('PackageSidebar', () => {
18 let wrapper: VueWrapper
19
20 afterEach(() => {
21 wrapper?.unmount()
22 })
23
24 it('renders slot content', async () => {
25 wrapper = await mountSidebar()
26
27 expect(wrapper.text()).toContain('Sidebar Content')
28 })
29
30 it('sets active=false when content is shorter than viewport', async () => {
31 wrapper = await mountSidebar(100)
32
33 expect(wrapper.attributes('data-active')).toBe('false')
34 })
35
36 it('sets active=true when content is taller than viewport', async () => {
37 wrapper = await mountSidebar(VIEWPORT_HEIGHT + 500)
38 await nextTick()
39
40 expect(wrapper.attributes('data-active')).toBe('true')
41 })
42
43 it('renders with direction=up by default', async () => {
44 wrapper = await mountSidebar()
45
46 expect(wrapper.attributes('data-direction')).toBe('up')
47 })
48})