Skip to content

Commit e34f65f

Browse files
committed
fix: add aria labels + update tests
1 parent 16182bd commit e34f65f

5 files changed

Lines changed: 41 additions & 15 deletions

File tree

app/components/PackageDependencies.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const sortedOptionalDependencies = computed(() => {
6262
<a
6363
href="#dependencies"
6464
class="opacity-0 group-hover:opacity-100 text-fg-subtle hover:text-fg-muted transition-opacity duration-200 no-underline"
65+
:aria-label="$t('package.dependencies.anchor_link')"
6566
>
6667
<span class="i-carbon-link w-3 h-3 block" aria-hidden="true" />
6768
</a>
@@ -127,6 +128,7 @@ const sortedOptionalDependencies = computed(() => {
127128
<a
128129
href="#peer-dependencies"
129130
class="opacity-0 group-hover:opacity-100 text-fg-subtle hover:text-fg-muted transition-opacity duration-200 no-underline"
131+
:aria-label="$t('package.peer_dependencies.anchor_link')"
130132
>
131133
<span class="i-carbon-link w-3 h-3 block" aria-hidden="true" />
132134
</a>

app/components/PackageMaintainers.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ watch(
167167
<a
168168
href="#maintainers"
169169
class="opacity-0 group-hover:opacity-100 text-fg-subtle hover:text-fg-muted transition-opacity duration-200 no-underline"
170+
:aria-label="$t('package.maintainers.anchor_link')"
170171
>
171172
<span class="i-carbon-link w-3 h-3 block" aria-hidden="true" />
172173
</a>

app/components/PackageVersions.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ function getTagVersions(tag: string): VersionDisplay[] {
319319
<a
320320
href="#versions"
321321
class="opacity-0 group-hover:opacity-100 text-fg-subtle hover:text-fg-muted transition-opacity duration-200 no-underline"
322+
:aria-label="$t('package.versions.anchor_link')"
322323
>
323324
<span class="i-carbon-link w-3 h-3 block" aria-hidden="true" />
324325
</a>

i18n/locales/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
},
127127
"versions": {
128128
"title": "Versions",
129+
"anchor_link": "Link to versions section",
129130
"collapse": "Collapse {tag}",
130131
"expand": "Expand {tag}",
131132
"collapse_other": "Collapse other versions",
@@ -139,12 +140,14 @@
139140
},
140141
"dependencies": {
141142
"title": "Dependencies ({count})",
143+
"anchor_link": "Link to dependencies section",
142144
"list_label": "Package dependencies",
143145
"show_all": "show all {count} deps",
144146
"optional": "optional"
145147
},
146148
"peer_dependencies": {
147149
"title": "Peer Dependencies ({count})",
150+
"anchor_link": "Link to peer dependencies section",
148151
"list_label": "Package peer dependencies",
149152
"show_all": "show all {count} peer deps"
150153
},
@@ -155,6 +158,7 @@
155158
},
156159
"maintainers": {
157160
"title": "Maintainers",
161+
"anchor_link": "Link to maintainers section",
158162
"list_label": "Package maintainers",
159163
"you": "(you)",
160164
"via": "via {teams}",

test/nuxt/components/PackageVersions.spec.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ describe('PackageVersions', () => {
8282
},
8383
})
8484

85-
const link = component.find('a')
86-
expect(link.exists()).toBe(true)
87-
expect(link.text()).toBe('2.0.0')
85+
// Find version links (exclude anchor links that start with #)
86+
const versionLinks = component
87+
.findAll('a')
88+
.filter(a => !a.attributes('href')?.startsWith('#'))
89+
expect(versionLinks.length).toBeGreaterThan(0)
90+
expect(versionLinks[0]?.text()).toBe('2.0.0')
8891
})
8992

9093
it('renders scoped package version links correctly', async () => {
@@ -99,9 +102,12 @@ describe('PackageVersions', () => {
99102
},
100103
})
101104

102-
const link = component.find('a')
103-
expect(link.exists()).toBe(true)
104-
expect(link.text()).toBe('1.0.0')
105+
// Find version links (exclude anchor links that start with #)
106+
const versionLinks = component
107+
.findAll('a')
108+
.filter(a => !a.attributes('href')?.startsWith('#'))
109+
expect(versionLinks.length).toBeGreaterThan(0)
110+
expect(versionLinks[0]?.text()).toBe('1.0.0')
105111
})
106112
})
107113

@@ -190,8 +196,11 @@ describe('PackageVersions', () => {
190196
},
191197
})
192198

193-
const links = component.findAll('a')
194-
const versions = links.map(l => l.text())
199+
// Find version links (exclude anchor links that start with #)
200+
const versionLinks = component
201+
.findAll('a')
202+
.filter(a => !a.attributes('href')?.startsWith('#'))
203+
const versions = versionLinks.map(l => l.text())
195204
// Should be sorted by version descending
196205
expect(versions[0]).toBe('2.0.0')
197206
})
@@ -210,8 +219,12 @@ describe('PackageVersions', () => {
210219
},
211220
})
212221

213-
const link = component.find('a')
214-
expect(link.classes()).toContain('text-red-400')
222+
// Find version links (exclude anchor links that start with #)
223+
const versionLinks = component
224+
.findAll('a')
225+
.filter(a => !a.attributes('href')?.startsWith('#'))
226+
expect(versionLinks.length).toBeGreaterThan(0)
227+
expect(versionLinks[0]?.classes()).toContain('text-red-400')
215228
})
216229

217230
it('shows deprecated version in title attribute', async () => {
@@ -226,8 +239,12 @@ describe('PackageVersions', () => {
226239
},
227240
})
228241

229-
const link = component.find('a')
230-
expect(link.attributes('title')).toContain('deprecated')
242+
// Find version links (exclude anchor links that start with #)
243+
const versionLinks = component
244+
.findAll('a')
245+
.filter(a => !a.attributes('href')?.startsWith('#'))
246+
expect(versionLinks.length).toBeGreaterThan(0)
247+
expect(versionLinks[0]?.attributes('title')).toContain('deprecated')
231248
})
232249

233250
it('filters deprecated tags from visible list when package is not deprecated', async () => {
@@ -552,9 +569,10 @@ describe('PackageVersions', () => {
552569
},
553570
})
554571

555-
// Count visible version links (excluding "Other versions" section)
556-
// The first set of links before the "Other versions" button
557-
const visibleLinks = component.findAll('a')
572+
// Count visible version links (excluding anchor links that start with #)
573+
const visibleLinks = component
574+
.findAll('a')
575+
.filter(a => !a.attributes('href')?.startsWith('#'))
558576
// Should have max 10 visible links in the main section
559577
expect(visibleLinks.length).toBeLessThanOrEqual(10)
560578
})

0 commit comments

Comments
 (0)