Skip to content

Commit 2782dc7

Browse files
authored
fix the bug and add e2e test
1 parent fbed36b commit 2782dc7

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

app/composables/useCompareReplacements.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ModuleReplacement } from 'module-replacements'
1+
import type { ModuleReplacement, ModuleReplacementMapping } from 'module-replacements'
22

33
export interface ReplacementSuggestion {
44
forPackage: string
@@ -41,8 +41,8 @@ export function useCompareReplacements(packageNames: MaybeRefOrGetter<string[]>)
4141
const results = await Promise.all(
4242
namesToCheck.map(async name => {
4343
try {
44-
const replacement = await $fetch<ModuleReplacement | null>(`/api/replacements/${name}`)
45-
return { name, replacement }
44+
const result = await $fetch<{ mapping: ModuleReplacementMapping; replacement: ModuleReplacement } | null>(`/api/replacements/${name}`)
45+
return { name, replacement: result?.replacement ?? null }
4646
} catch {
4747
return { name, replacement: null }
4848
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { expect, test } from './test-utils'
2+
3+
test.describe('Compare page - replacement suggestions', () => {
4+
test('shows "Consider no dep?" box for packages with native/simple replacements', async ({
5+
page,
6+
goto,
7+
}) => {
8+
// is-odd has a 'simple' replacement in module-replacements v3
9+
await goto('/compare?packages=is-odd,is-even', { waitUntil: 'hydration' })
10+
11+
// The suggestion box should appear after client-side fetch resolves
12+
// Button text comes from $t('package.replacement.consider_no_dep')
13+
const considerNoDepButton = page.getByRole('button', { name: /consider no dep/i })
14+
await expect(considerNoDepButton).toBeVisible({ timeout: 15_000 })
15+
})
16+
17+
test('does not show "Consider no dep?" box for packages without replacements', async ({
18+
page,
19+
goto,
20+
}) => {
21+
await goto('/compare?packages=nuxt,vue', { waitUntil: 'hydration' })
22+
23+
const considerNoDepButton = page.getByRole('button', { name: /consider no dep/i })
24+
await expect(considerNoDepButton).not.toBeVisible({ timeout: 10_000 })
25+
})
26+
})

0 commit comments

Comments
 (0)