Skip to content

Commit 04bd490

Browse files
authored
fix(ui): truncate long package names on profile package likes page (#1757)
1 parent 80dc9be commit 04bd490

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

app/components/Package/LikeCard.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ const likeAction = async () => {
7171

7272
<template>
7373
<NuxtLink :to="packageRoute(name)">
74-
<BaseCard class="font-mono flex justify-between">
75-
{{ name }}
76-
<div class="flex items-center gap-4 justify-between">
74+
<BaseCard class="font-mono flex justify-between min-w-0">
75+
<span class="truncate min-w-0" :title="name">{{ name }}</span>
76+
<div class="flex items-center gap-4 justify-between shrink-0">
7777
<ClientOnly>
7878
<TooltipApp
7979
:text="likesData?.userHasLiked ? $t('package.likes.unlike') : $t('package.likes.like')"
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)