Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/components/BackButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script setup lang="ts">
const router = useRouter()
const canGoBack = useCanGoBack()
</script>

<template>
<button
v-if="canGoBack"
type="button"
class="inline-flex items-center gap-2 p-1.5 -mx-1.5 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70 shrink-0"
@click="router.back()"
>
<span class="i-lucide:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
<span class="sr-only sm:not-sr-only">{{ $t('nav.back') }}</span>
</button>
</template>
13 changes: 1 addition & 12 deletions app/pages/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import type { Role } from '#server/api/contributors.get'
import { SPONSORS } from '~/assets/logos/sponsors'
import { OSS_PARTNERS } from '~/assets/logos/oss-partners'

const router = useRouter()
const canGoBack = useCanGoBack()

useSeoMeta({
title: () => `${$t('about.title')} - npmx`,
ogTitle: () => `${$t('about.title')} - npmx`,
Expand Down Expand Up @@ -57,15 +54,7 @@ const roleLabels = computed(
<h1 class="font-mono text-3xl sm:text-4xl font-medium">
{{ $t('about.heading') }}
</h1>
<button
type="button"
class="cursor-pointer inline-flex items-center gap-2 p-1.5 -mx-1.5 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70 shrink-0"
@click="router.back()"
v-if="canGoBack"
>
<span class="i-lucide:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
<span class="hidden sm:inline">{{ $t('nav.back') }}</span>
</button>
<BackButton />
</div>
<p class="text-fg-muted text-lg">
{{ $t('tagline') }}
Expand Down
13 changes: 1 addition & 12 deletions app/pages/accessibility.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ defineOgImageComponent('Default', {
title: () => $t('a11y.title'),
description: () => $t('a11y.welcome', { app: 'npmx' }),
})

const router = useRouter()
const canGoBack = useCanGoBack()
</script>

<template>
Expand All @@ -25,15 +22,7 @@ const canGoBack = useCanGoBack()
<h1 class="font-mono text-3xl sm:text-4xl font-medium">
{{ $t('a11y.title') }}
</h1>
<button
type="button"
class="cursor-pointer inline-flex items-center gap-2 p-1.5 -mx-1.5 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded shrink-0"
@click="router.back()"
v-if="canGoBack"
>
<span class="i-lucide:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
<span class="sr-only sm:not-sr-only">{{ $t('nav.back') }}</span>
</button>
<BackButton />
</div>
</header>

Expand Down
12 changes: 1 addition & 11 deletions app/pages/compare.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ definePageMeta({
})

const { locale } = useI18n()
const router = useRouter()
const canGoBack = useCanGoBack()
const { copied, copy } = useClipboard({ copiedDuring: 2000 })
const maxPackages = 4

Expand Down Expand Up @@ -173,15 +171,7 @@ useSeoMeta({
<h1 class="font-mono text-3xl sm:text-4xl font-medium">
{{ $t('compare.packages.title') }}
</h1>
<button
type="button"
class="cursor-pointer inline-flex items-center gap-2 p-1.5 -mx-1.5 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70 shrink-0"
@click="router.back()"
v-if="canGoBack"
>
<span class="i-lucide:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
<span class="hidden sm:inline">{{ $t('nav.back') }}</span>
</button>
<BackButton />
</div>
<p class="text-fg-muted text-lg">
{{ $t('compare.packages.tagline') }}
Expand Down
13 changes: 1 addition & 12 deletions app/pages/pds.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<script setup lang="ts">
import type { AtprotoProfile } from '#shared/types/atproto'

const router = useRouter()
const canGoBack = useCanGoBack()

useSeoMeta({
title: () => `${$t('pds.title')} - npmx`,
ogTitle: () => `${$t('pds.title')} - npmx`,
Expand Down Expand Up @@ -51,15 +48,7 @@ const totalAccounts = computed(() => pdsUsers.value.length)
<h1 class="font-mono text-3xl sm:text-4xl font-medium">
{{ $t('pds.title') }}
</h1>
<button
type="button"
class="cursor-pointer inline-flex items-center gap-2 p-1.5 -mx-1.5 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70 shrink-0"
@click="router.back()"
v-if="canGoBack"
>
<span class="i-lucide:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
<span class="hidden sm:inline">{{ $t('nav.back') }}</span>
</button>
<BackButton />
</div>
<p class="text-fg-muted text-lg">
{{ $t('pds.meta_description') }}
Expand Down
12 changes: 1 addition & 11 deletions app/pages/privacy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ defineOgImageComponent('Default', {
description: () => $t('privacy_policy.welcome', { app: 'npmx' }),
})

const router = useRouter()
const canGoBack = useCanGoBack()
const buildInfo = useAppConfig().buildInfo
const { locale } = useI18n()
</script>
Expand All @@ -27,15 +25,7 @@ const { locale } = useI18n()
<h1 class="font-mono text-3xl sm:text-4xl font-medium">
{{ $t('privacy_policy.title') }}
</h1>
<button
type="button"
class="cursor-pointer inline-flex items-center gap-2 p-1.5 -mx-1.5 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70 shrink-0"
@click="router.back()"
v-if="canGoBack"
>
<span class="i-lucide:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
<span class="sr-only sm:not-sr-only">{{ $t('nav.back') }}</span>
</button>
<BackButton />
</div>
<i18n-t
keypath="privacy_policy.last_updated"
Expand Down
13 changes: 1 addition & 12 deletions app/pages/recharging.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ defineOgImageComponent('Default', {
description: () => $t('vacations.meta_description'),
})

const router = useRouter()
const canGoBack = useCanGoBack()

const { data: stats } = useFetch('/api/repo-stats')

/**
Expand Down Expand Up @@ -74,15 +71,7 @@ const icons = [
<h1 class="font-mono text-3xl sm:text-4xl font-medium">
{{ $t('vacations.heading') }}
</h1>
<button
type="button"
class="cursor-pointer inline-flex items-center gap-2 p-1.5 -mx-1.5 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70 shrink-0"
@click="router.back()"
v-if="canGoBack"
>
<span class="i-lucide:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
<span class="sr-only sm:not-sr-only">{{ $t('nav.back') }}</span>
</button>
<BackButton />
</div>
<i18n-t
keypath="vacations.subtitle"
Expand Down
11 changes: 1 addition & 10 deletions app/pages/settings.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
const router = useRouter()
const canGoBack = useCanGoBack()
const { settings } = useSettings()
const { locale: currentLocale, locales, setLocale: setNuxti18nLocale } = useI18n()
const colorMode = useColorMode()
Expand Down Expand Up @@ -51,15 +50,7 @@ const setLocale: typeof setNuxti18nLocale = newLocale => {
<h1 class="font-mono text-3xl sm:text-4xl font-medium">
{{ $t('settings.title') }}
</h1>
<button
type="button"
class="cursor-pointer inline-flex items-center gap-2 p-1.5 -mx-1.5 font-mono text-sm text-fg-muted hover:text-fg transition-colors duration-200 rounded focus-visible:outline-accent/70 shrink-0"
@click="router.back()"
v-if="canGoBack"
>
<span class="i-lucide:arrow-left rtl-flip w-4 h-4" aria-hidden="true" />
<span class="sr-only sm:not-sr-only">{{ $t('nav.back') }}</span>
</button>
<BackButton />
</div>
<p class="text-fg-muted text-lg">
{{ $t('settings.tagline') }}
Expand Down
16 changes: 16 additions & 0 deletions test/nuxt/a11y.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ vi.mock('vue-data-ui/vue-ui-xy', () => {
}
})

vi.mock('~/composables/useCanGoBack', () => {
return {
useCanGoBack: () => shallowRef(true),
}
})

// Import components from #components where possible
// For server/client variants, we need to import directly to test the specific variant
import {
Expand All @@ -125,6 +131,7 @@ import {
AboutLogoList,
AuthorAvatar,
AuthorList,
BackButton,
BlogPostFederatedArticles,
BlogPostListCard,
BlogPostWrapper,
Expand Down Expand Up @@ -457,6 +464,15 @@ describe('component accessibility audits', () => {
})
})

describe('BackButton', () => {
it('should have no accessibility violations', async () => {
const component = await mountSuspended(BackButton)
expect(component.find('button').exists()).toBe(true)
const results = await runAxe(component)
expect(results.violations).toEqual([])
})
})

describe('TagStatic', () => {
it('should have no accessibility violations', async () => {
const component = await mountSuspended(TagStatic, {
Expand Down
10 changes: 7 additions & 3 deletions test/unit/a11y-component-coverage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const SKIPPED_COMPONENTS: Record<string, string> = {
'Translation/StatusByFile.unused.vue': 'Unused component, might be needed in the future',
}

function normalizeComponentPath(filePath: string): string {
return filePath.replaceAll('\\', '/')
}

/**
* Recursively get all Vue component files in a directory.
*/
Expand All @@ -63,7 +67,7 @@ function getVueFiles(dir: string, baseDir: string = dir): string[] {
files.push(...getVueFiles(fullPath, baseDir))
} else if (entry.isFile() && entry.name.endsWith('.vue')) {
// Get relative path from base components directory
files.push(path.relative(baseDir, fullPath))
files.push(normalizeComponentPath(path.relative(baseDir, fullPath)))
}
}

Expand All @@ -88,7 +92,7 @@ function parseComponentsDeclaration(dtsPath: string): Map<string, string[]> {
let match
while ((match = exportRegex.exec(content)) !== null) {
const componentName = match[1]!
const filePath = match[2]!
const filePath = normalizeComponentPath(match[2]!)

const existing = componentMap.get(componentName) || []
if (!existing.includes(filePath)) {
Expand Down Expand Up @@ -117,7 +121,7 @@ function getTestedComponents(
let match

while ((match = directImportRegex.exec(testFileContent)) !== null) {
tested.add(match[1]!)
tested.add(normalizeComponentPath(match[1]!))
}

// Match #components imports like:
Expand Down
Loading