|
@@ -0,0 +1,52 @@
|
|
|
+// Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
|
|
+
|
|
|
+import type { RouteLocationNormalized, Router } from 'vue-router'
|
|
|
+import { Walker } from '../walker'
|
|
|
+
|
|
|
+const buildRouter = () =>
|
|
|
+ ({
|
|
|
+ afterEach: vi.fn(),
|
|
|
+ back: vi.fn(),
|
|
|
+ push: vi.fn(),
|
|
|
+ } as any as Router)
|
|
|
+
|
|
|
+describe('testing walker', () => {
|
|
|
+ it('has fallback route, if no back is in history', async () => {
|
|
|
+ const router = buildRouter()
|
|
|
+ const walker = new Walker(router)
|
|
|
+ expect(walker.hasBackUrl).toBe(false)
|
|
|
+ expect(walker.getBackUrl('/fallback')).toBe('/fallback')
|
|
|
+ await walker.back('/fallback')
|
|
|
+ expect(router.push).toHaveBeenCalledWith('/fallback')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('has back route, if there is back route in history', async () => {
|
|
|
+ window.history.replaceState({ back: '/back' }, '', '/back')
|
|
|
+ const router = buildRouter()
|
|
|
+ const walker = new Walker(router)
|
|
|
+ expect(walker.hasBackUrl).toBe(true)
|
|
|
+ expect(walker.getBackUrl('/fallback')).toBe('/back')
|
|
|
+ await walker.back('/fallback')
|
|
|
+ expect(router.back).toHaveBeenCalled()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('changes back route after changing route', () => {
|
|
|
+ window.history.replaceState({ back: null }, '', '/back')
|
|
|
+
|
|
|
+ const router = buildRouter()
|
|
|
+ const walker = new Walker(router)
|
|
|
+
|
|
|
+ expect(walker.hasBackUrl).toBe(false)
|
|
|
+
|
|
|
+ const route = {} as RouteLocationNormalized
|
|
|
+
|
|
|
+ const afterEach = vi.mocked(router.afterEach).mock.calls[0][0]
|
|
|
+
|
|
|
+ window.history.replaceState({ back: '/back' }, '', '/back')
|
|
|
+
|
|
|
+ afterEach(route, route)
|
|
|
+
|
|
|
+ expect(walker.hasBackUrl).toBe(true)
|
|
|
+ expect(walker.getBackUrl('/fallback')).toBe('/back')
|
|
|
+ })
|
|
|
+})
|