Skip to content

Commit 935e7bb

Browse files
lcharetteCopilot
andcommitted
Fix SearchComponent: Add version handling in search params and reset location in tests
Co-authored-by: Copilot <copilot@github.com>
1 parent 5448c18 commit 935e7bb

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

app/assets/SearchComponent.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ vi.mock('axios')
88
describe('SearchComponent', () => {
99
beforeEach(() => {
1010
vi.resetAllMocks()
11+
// Reset location to default
12+
Object.defineProperty(window, 'location', {
13+
value: { pathname: '/' },
14+
writable: true
15+
})
1116
})
1217

1318
it('renders the search trigger input', () => {
@@ -63,6 +68,28 @@ describe('SearchComponent', () => {
6368
expect(axios.get).toHaveBeenCalledWith('/api/search', { params: { q: 'test' } })
6469
})
6570

71+
it('includes version in search params when browsing a versioned page', async () => {
72+
Object.defineProperty(window, 'location', {
73+
value: { pathname: '/5.1/quick-start' },
74+
writable: true
75+
})
76+
77+
vi.mocked(axios.get).mockResolvedValue({
78+
data: { count: 0, size: 10, page: 1, rows: [] }
79+
})
80+
81+
const wrapper = mount(SearchComponent)
82+
const searchInput = wrapper.find('input[autofocus]')
83+
await searchInput.setValue('test')
84+
85+
await new Promise((resolve) => setTimeout(resolve, 0))
86+
await wrapper.vm.$nextTick()
87+
88+
expect(axios.get).toHaveBeenCalledWith('/api/search', {
89+
params: { q: 'test', version: '5.1' }
90+
})
91+
})
92+
6693
it('shows no results message when query is long enough but no results returned', async () => {
6794
const mockData = { count: 0, size: 10, page: 1, rows: [] }
6895
vi.mocked(axios.get).mockResolvedValue({ data: mockData })

app/assets/SearchComponent.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import axios from 'axios'
88
const minLength: number = 3
99
const dataUrl: string = '/api/search'
1010
11+
/**
12+
* Extract the current documentation version from the URL path.
13+
* URL structure: /{version}/{path} (e.g., /6.0/quick-start)
14+
* Returns null if no version is found (falls back to latest on the server).
15+
*/
16+
function getVersionFromUrl(): string | null {
17+
const match = window.location.pathname.match(/^\/(\d+\.\d+)(?:\/|$)/)
18+
return match ? match[1] : null
19+
}
20+
1121
/**
1222
* Reactive Variables
1323
*/
@@ -30,10 +40,12 @@ async function fetch() {
3040
}
3141
3242
loading.value = true
43+
const version = getVersionFromUrl()
3344
axios
3445
.get<ResultData>(dataUrl, {
3546
params: {
36-
q: searchQuery.value
47+
q: searchQuery.value,
48+
...(version !== null && { version })
3749
}
3850
})
3951
.then((response) => {

eslint.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import js from '@eslint/js'
22
import tseslint from 'typescript-eslint'
33
import pluginVue from 'eslint-plugin-vue'
44
import { defineConfig } from 'eslint/config'
5+
import globals from 'globals'
56

67
export default defineConfig([
78
{
89
files: ['**/*.{js,mjs,cjs,ts,mts,cts,vue}'],
910
plugins: { js },
10-
extends: ['js/recommended']
11+
extends: ['js/recommended'],
12+
languageOptions: {
13+
globals: globals.browser
14+
}
1115
},
1216
tseslint.configs.recommended,
1317
pluginVue.configs['flat/essential'],

0 commit comments

Comments
 (0)