diff --git a/neode-ui/src/views/server/OpenWrtGateway.test.ts b/neode-ui/src/views/server/OpenWrtGateway.test.ts new file mode 100644 index 00000000..768291e5 --- /dev/null +++ b/neode-ui/src/views/server/OpenWrtGateway.test.ts @@ -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() + }) +}) diff --git a/neode-ui/src/views/server/OpenWrtGateway.vue b/neode-ui/src/views/server/OpenWrtGateway.vue index ef8e9597..5811074d 100644 --- a/neode-ui/src/views/server/OpenWrtGateway.vue +++ b/neode-ui/src/views/server/OpenWrtGateway.vue @@ -260,6 +260,7 @@ function pickDetectedRouter(ip: string) { function disconnectRouter() { host.value = status.value?.host ?? host.value connectedParams.value = null + error.value = '' detectError.value = '' detectedCandidates.value = [] showConnectForm.value = true @@ -533,7 +534,10 @@ onMounted(() => {

{{ error }}

- +
+ + +