import { beforeEach, expect, it, vi } from 'vitest' const state=vi.hoisted(()=>({store:{delCachedView:vi.fn(),addCachedView:vi.fn()},router:{currentRoute:{value:{path:'/warehouse/stock',query:{projectId:'1'},hash:'#row-3',meta:{},matched:[]}},replace:vi.fn()}})) vi.mock('@/store/modules/tagsView',()=>({default:()=>state.store})) vi.mock('@/store/modules/permission',()=>({default:()=>({landingPath:'/index'})})) vi.mock('@/router',()=>({default:state.router})) import tab from '../../src/plugins/tab.js' import { registerPageGuard } from '../../src/utils/page-guards.js' beforeEach(()=>{vi.clearAllMocks();state.router.currentRoute.value={path:'/warehouse/stock',query:{projectId:'1'},hash:'#row-3',meta:{},matched:[]}}) it('refresh preserves query and hash instead of losing the current anchor',async()=>{ expect(await tab.refreshPage()).toBe(true) expect(state.router.replace).toHaveBeenCalledExactlyOnceWith({path:'/redirect/warehouse/stock',query:{projectId:'1'},hash:'#row-3'}) }) it('repeated clicks while a guard is pending cause one navigation, and cancellation evicts no cache',async()=>{ let resolve;const stop=registerPageGuard('/warehouse/stock',()=>new Promise(done=>{resolve=done})) try{ const pending=tab.refreshPage();expect(await tab.refreshPage()).toBe(false) resolve(false);expect(await pending).toBe(false) expect(state.store.delCachedView).not.toHaveBeenCalled();expect(state.router.replace).not.toHaveBeenCalled() }finally{stop()} }) it('intermediate redirect route never refreshes itself recursively',async()=>{ state.router.currentRoute.value.path='/redirect/warehouse/stock' expect(await tab.refreshPage()).toBe(false);expect(state.router.replace).not.toHaveBeenCalled() })