Skip to content

Commit 9fb88a4

Browse files
committed
test: add coverage for PackageLikeCard
1 parent a305d43 commit 9fb88a4

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { afterEach, describe, expect, it } from 'vitest'
2+
import { mountSuspended } from '@nuxt/test-utils/runtime'
3+
import type { VueWrapper } from '@vue/test-utils'
4+
import LikeCard from '~/components/Package/LikeCard.vue'
5+
6+
describe('PackageLikeCard', () => {
7+
let wrapper: VueWrapper
8+
9+
afterEach(() => {
10+
wrapper?.unmount()
11+
})
12+
13+
function mountLikeCard(packageUrl: string) {
14+
return mountSuspended(LikeCard, {
15+
props: { packageUrl },
16+
attachTo: document.body,
17+
})
18+
}
19+
20+
it('renders the package name', async () => {
21+
wrapper = await mountLikeCard('https://npmx.dev/package/vue')
22+
23+
expect(wrapper.text()).toContain('vue')
24+
})
25+
26+
it('truncates a long package name instead of overflowing', async () => {
27+
const longName = 'a'.repeat(200)
28+
wrapper = await mountLikeCard(`https://npmx.dev/package/${longName}`)
29+
30+
const nameEl = wrapper.find('span.truncate').element as HTMLElement
31+
expect(nameEl.scrollWidth).toBeGreaterThan(nameEl.clientWidth)
32+
})
33+
34+
it('shows the full name in a title attribute on hover', async () => {
35+
const longName = 'a'.repeat(200)
36+
wrapper = await mountLikeCard(`https://npmx.dev/package/${longName}`)
37+
38+
const nameEl = wrapper.find('span.truncate')
39+
expect(nameEl.attributes('title')).toBe(longName)
40+
})
41+
42+
it('extracts scoped package name from URL', async () => {
43+
wrapper = await mountLikeCard('https://npmx.dev/package/@scope/pkg')
44+
45+
expect(wrapper.find('span.truncate').text()).toBe('@scope/pkg')
46+
})
47+
})

0 commit comments

Comments
 (0)