shinkan-jinkendo/frontend/src/utils/navReturnContext.test.js
Lars 6e6270b717
All checks were successful
Deploy Development / deploy (push) Successful in 41s
Test Suite / pytest-backend (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m17s
Enhance navigation and return context in exercise and training module components
- Introduced a new `PageReturnLink` component for consistent back navigation across pages.
- Updated `SaveSelectedExercisesAsModuleModal` and `SaveExercisesAsModuleModal` to utilize `navigateWithAppReturn`, preserving navigation context when redirecting after saving.
- Enhanced `TrainingModuleEditPage` and `TrainingUnitEditPage` with improved return context handling, allowing users to navigate back to their previous locations seamlessly.
- Added CSS styles for the new return link to improve visual consistency and user experience.
2026-05-20 07:25:05 +02:00

86 lines
2.6 KiB
JavaScript

import { describe, expect, it, vi } from 'vitest'
import {
appReturnFromPlanningReturn,
buildExercisesListReturnContext,
buildNavReturnContext,
buildPlanningHubReturnContext,
goNavReturn,
readNavReturnFromLocation,
resolveNavReturnTarget,
} from './navReturnContext.js'
describe('navReturnContext', () => {
it('buildNavReturnContext requires path and label', () => {
expect(buildNavReturnContext({ path: '/x', label: 'Zurück' })).toEqual({
v: 1,
path: '/x',
label: 'Zurück',
})
expect(buildNavReturnContext({ path: '', label: 'X' })).toBeNull()
})
it('buildExercisesListReturnContext', () => {
const ctx = buildExercisesListReturnContext()
expect(ctx.path).toBe('/exercises')
expect(ctx.kind).toBe('exerciseList')
})
it('readNavReturnFromLocation prefers appReturn', () => {
const ctx = buildExercisesListReturnContext()
expect(readNavReturnFromLocation({ state: { appReturn: ctx } })).toEqual(ctx)
})
it('readNavReturnFromLocation bridges planningReturn', () => {
const loc = {
state: {
planningReturn: {
v: 1,
selectedGroupId: '3',
planView: 'list',
calendarMonthStr: '',
startDate: '',
endDate: '',
planScope: 'group',
assignedToMeOnly: false,
},
},
}
const ctx = readNavReturnFromLocation(loc)
expect(ctx?.kind).toBe('planningHub')
expect(ctx?.path).toContain('/planning')
expect(ctx?.label).toBe('Zurück zur Planung')
})
it('appReturnFromPlanningReturn', () => {
const ctx = appReturnFromPlanningReturn({
v: 1,
selectedGroupId: '',
planView: 'calendar',
calendarMonthStr: '2026-05',
startDate: '',
endDate: '',
planScope: 'group',
assignedToMeOnly: false,
})
expect(ctx?.path).toContain('month=2026-05')
})
it('resolveNavReturnTarget uses fallback when no state', () => {
const fb = { path: '/planning/training-modules', label: 'Zurück zur Modul-Bibliothek' }
expect(resolveNavReturnTarget({ state: null }, fb)).toEqual({ ...fb, fromContext: false })
})
it('goNavReturn navigates to context path first', () => {
const navigate = vi.fn()
const ctx = buildExercisesListReturnContext()
goNavReturn(navigate, { state: { appReturn: ctx } }, null)
expect(navigate).toHaveBeenCalledWith('/exercises')
})
it('buildPlanningHubReturnContext', () => {
const ctx = buildPlanningHubReturnContext({ selectedGroupId: '7', planView: 'list' })
expect(ctx?.path).toContain('group=7')
expect(ctx?.kind).toBe('planningHub')
})
})