fix(openwrt): make stale router config recoverable (#103)
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
import { createPinia } from 'pinia'
|
||||||
|
import { flushPromises, mount } from '@vue/test-utils'
|
||||||
|
|
||||||
|
vi.mock('vue-router', () => ({
|
||||||
|
useRouter: () => ({ push: vi.fn() }),
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('@/api/rpc-client', () => ({
|
||||||
|
rpcClient: { call: vi.fn() },
|
||||||
|
}))
|
||||||
|
|
||||||
|
import { rpcClient } from '@/api/rpc-client'
|
||||||
|
import OpenWrtGateway from './OpenWrtGateway.vue'
|
||||||
|
|
||||||
|
describe('OpenWrtGateway stale cached router recovery (#103)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks()
|
||||||
|
sessionStorage.clear()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('offers reconfiguration when the saved router can no longer connect', async () => {
|
||||||
|
vi.mocked(rpcClient.call).mockRejectedValue(new Error('Connection timed out'))
|
||||||
|
const wrapper = mount(OpenWrtGateway, {
|
||||||
|
global: { plugins: [createPinia()] },
|
||||||
|
})
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const reconfigure = wrapper.findAll('button').find(button => button.text() === 'Reconfigure router')
|
||||||
|
expect(reconfigure).toBeDefined()
|
||||||
|
await reconfigure!.trigger('click')
|
||||||
|
|
||||||
|
expect(wrapper.text()).toContain('Connect to Router')
|
||||||
|
expect(wrapper.text()).not.toContain('Connection timed out')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -260,6 +260,7 @@ function pickDetectedRouter(ip: string) {
|
|||||||
function disconnectRouter() {
|
function disconnectRouter() {
|
||||||
host.value = status.value?.host ?? host.value
|
host.value = status.value?.host ?? host.value
|
||||||
connectedParams.value = null
|
connectedParams.value = null
|
||||||
|
error.value = ''
|
||||||
detectError.value = ''
|
detectError.value = ''
|
||||||
detectedCandidates.value = []
|
detectedCandidates.value = []
|
||||||
showConnectForm.value = true
|
showConnectForm.value = true
|
||||||
@@ -533,7 +534,10 @@ onMounted(() => {
|
|||||||
<!-- Error state -->
|
<!-- Error state -->
|
||||||
<div v-else-if="error" class="glass-card p-6 mb-4">
|
<div v-else-if="error" class="glass-card p-6 mb-4">
|
||||||
<p class="text-sm text-red-300">{{ error }}</p>
|
<p class="text-sm text-red-300">{{ error }}</p>
|
||||||
<button class="mt-3 text-xs text-white/50 hover:text-white transition-colors underline" @click="load()">Retry</button>
|
<div class="mt-3 flex items-center gap-4">
|
||||||
|
<button class="text-xs text-white/50 hover:text-white transition-colors underline" @click="load()">Retry</button>
|
||||||
|
<button class="text-xs text-orange-300/80 hover:text-orange-200 transition-colors underline" @click="disconnectRouter">Reconfigure router</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Status panels -->
|
<!-- Status panels -->
|
||||||
|
|||||||
Reference in New Issue
Block a user