Enhance frontend testing setup and refactor TrainingPlanningPageRoot component
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 19s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m21s
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 19s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m21s
- Added Vitest as a testing framework and included test scripts in package.json for improved testing capabilities. - Refactored TrainingPlanningPageRoot component by removing unused state variables and imports, streamlining the code for better readability and performance. - Introduced new utility functions for planning routes to enhance navigation within the training planning interface.
This commit is contained in:
1 parent
295c7e7efc
commit
16eaf839e7
17 files changed
+1854
-786
No files matched your search
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Zentrale Routen & Rückkehr-Kontext Trainingsplanung ↔ Einheiten-Editor.
|
||||
* Alle Navigations-URLs für Kalender-Einheiten hier pflegen (Drift-Schutz).
|
||||
*/
|
||||
|
||||
export const PLANNING_HUB_PATH = '/planning'
|
||||
|
||||
export function buildPlanUnitEditPath(unitId) {
|
||||
const id = Number(unitId)
|
||||
if (!Number.isFinite(id) || id < 1) return PLANNING_HUB_PATH
|
||||
return `/planning/units/${id}/edit`
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ groupId?: string|number, plannedDate?: string, templateId?: string|number, mode?: string }} opts
|
||||
*/
|
||||
export function buildPlanUnitNewPath(opts = {}) {
|
||||
const params = new URLSearchParams()
|
||||
if (opts.groupId != null && opts.groupId !== '') params.set('group', String(opts.groupId))
|
||||
if (opts.plannedDate) params.set('date', String(opts.plannedDate).slice(0, 10))
|
||||
if (opts.templateId != null && opts.templateId !== '') params.set('template', String(opts.templateId))
|
||||
if (opts.mode === 'debrief') params.set('mode', 'debrief')
|
||||
const q = params.toString()
|
||||
return q ? `/planning/units/new?${q}` : '/planning/units/new'
|
||||
}
|
||||
|
||||
/** @param {import('react-router-dom').URLSearchParams|string|null|undefined} raw */
|
||||
export function legacyPlanningUnitDeepLinkTarget(raw) {
|
||||
const params =
|
||||
raw instanceof URLSearchParams ? raw : new URLSearchParams(typeof raw === 'string' ? raw : '')
|
||||
const uid = params.get('unit')
|
||||
if (!uid) return null
|
||||
const idNum = parseInt(uid, 10)
|
||||
if (!Number.isFinite(idNum) || idNum < 1) return null
|
||||
const debrief = params.get('debrief')
|
||||
const base = buildPlanUnitEditPath(idNum)
|
||||
if (debrief === '1' || debrief === 'true') {
|
||||
return `${base}?mode=debrief`
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* selectedGroupId?: string,
|
||||
* planView?: string,
|
||||
* calendarMonthStr?: string,
|
||||
* startDate?: string,
|
||||
* endDate?: string,
|
||||
* planScope?: string,
|
||||
* assignedToMeOnly?: boolean,
|
||||
* }} hubState
|
||||
*/
|
||||
export function buildPlanningHubReturnState(hubState = {}) {
|
||||
return {
|
||||
v: 1,
|
||||
selectedGroupId: hubState.selectedGroupId != null ? String(hubState.selectedGroupId) : '',
|
||||
planView: hubState.planView || 'list',
|
||||
calendarMonthStr: hubState.calendarMonthStr || '',
|
||||
startDate: hubState.startDate || '',
|
||||
endDate: hubState.endDate || '',
|
||||
planScope: hubState.planScope || 'group',
|
||||
assignedToMeOnly: Boolean(hubState.assignedToMeOnly),
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {ReturnType<typeof buildPlanningHubReturnState>|null|undefined} state */
|
||||
export function planningHubPathFromReturnState(state) {
|
||||
if (!state || state.v !== 1) return PLANNING_HUB_PATH
|
||||
const params = new URLSearchParams()
|
||||
if (state.selectedGroupId) params.set('group', state.selectedGroupId)
|
||||
if (state.planView && state.planView !== 'list') params.set('view', state.planView)
|
||||
if (state.planView === 'calendar' && state.calendarMonthStr) {
|
||||
params.set('month', state.calendarMonthStr)
|
||||
}
|
||||
if (state.startDate) params.set('start', state.startDate)
|
||||
if (state.endDate) params.set('end', state.endDate)
|
||||
if (state.planScope && state.planScope !== 'group') params.set('scope', state.planScope)
|
||||
if (state.assignedToMeOnly) params.set('mine', '1')
|
||||
const q = params.toString()
|
||||
return q ? `${PLANNING_HUB_PATH}?${q}` : PLANNING_HUB_PATH
|
||||
}
|
||||
|
||||
/** Hub-Query beim Mount auf State-Felder mappen. */
|
||||
export function parsePlanningHubQuery(searchParams) {
|
||||
const p = searchParams instanceof URLSearchParams ? searchParams : new URLSearchParams(searchParams || '')
|
||||
return {
|
||||
selectedGroupId: p.get('group') || '',
|
||||
planView: p.get('view') === 'calendar' ? 'calendar' : 'list',
|
||||
calendarMonthStr: p.get('month') || '',
|
||||
startDate: p.get('start') || '',
|
||||
endDate: p.get('end') || '',
|
||||
planScope: p.get('scope') === 'club' ? 'club' : 'group',
|
||||
assignedToMeOnly: p.get('mine') === '1',
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
buildPlanUnitEditPath,
|
||||
buildPlanUnitNewPath,
|
||||
buildPlanningHubReturnState,
|
||||
legacyPlanningUnitDeepLinkTarget,
|
||||
parsePlanningHubQuery,
|
||||
planningHubPathFromReturnState,
|
||||
} from './planningUnitRoutes.js'
|
||||
|
||||
describe('planningUnitRoutes', () => {
|
||||
it('buildPlanUnitEditPath', () => {
|
||||
expect(buildPlanUnitEditPath(42)).toBe('/planning/units/42/edit')
|
||||
expect(buildPlanUnitEditPath('7')).toBe('/planning/units/7/edit')
|
||||
expect(buildPlanUnitEditPath(0)).toBe('/planning')
|
||||
})
|
||||
|
||||
it('buildPlanUnitNewPath with query', () => {
|
||||
expect(buildPlanUnitNewPath({ groupId: 3, plannedDate: '2026-05-20' })).toBe(
|
||||
'/planning/units/new?group=3&date=2026-05-20'
|
||||
)
|
||||
expect(buildPlanUnitNewPath()).toBe('/planning/units/new')
|
||||
})
|
||||
|
||||
it('legacyPlanningUnitDeepLinkTarget', () => {
|
||||
expect(legacyPlanningUnitDeepLinkTarget('unit=5')).toBe('/planning/units/5/edit')
|
||||
expect(legacyPlanningUnitDeepLinkTarget('unit=5&debrief=1')).toBe(
|
||||
'/planning/units/5/edit?mode=debrief'
|
||||
)
|
||||
expect(legacyPlanningUnitDeepLinkTarget('')).toBeNull()
|
||||
})
|
||||
|
||||
it('planning hub return roundtrip', () => {
|
||||
const state = buildPlanningHubReturnState({
|
||||
selectedGroupId: '12',
|
||||
planView: 'calendar',
|
||||
calendarMonthStr: '2026-06',
|
||||
assignedToMeOnly: true,
|
||||
})
|
||||
const path = planningHubPathFromReturnState(state)
|
||||
expect(path).toContain('/planning?')
|
||||
expect(path).toContain('group=12')
|
||||
expect(path).toContain('view=calendar')
|
||||
expect(path).toContain('month=2026-06')
|
||||
expect(path).toContain('mine=1')
|
||||
|
||||
const parsed = parsePlanningHubQuery(path.split('?')[1] || '')
|
||||
expect(parsed.selectedGroupId).toBe('12')
|
||||
expect(parsed.planView).toBe('calendar')
|
||||
expect(parsed.calendarMonthStr).toBe('2026-06')
|
||||
expect(parsed.assignedToMeOnly).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,133 @@
|
||||
import { buildPlanPayloadForSave, defaultSection } from './trainingUnitSectionsForm'
|
||||
import { sessionAssignDefaults } from './trainingPlanningPageHelpers'
|
||||
|
||||
/** Leeres Formular für neue Einheit (ohne async Varianten-Anreicherung). */
|
||||
export function createEmptyTrainingUnitFormData({
|
||||
groupId = '',
|
||||
plannedDate = '',
|
||||
timeStart = '',
|
||||
timeEnd = '',
|
||||
} = {}) {
|
||||
return {
|
||||
group_id: groupId != null ? String(groupId) : '',
|
||||
planned_date: plannedDate || '',
|
||||
planned_time_start: timeStart || '',
|
||||
planned_time_end: timeEnd || '',
|
||||
planned_focus: '',
|
||||
actual_date: '',
|
||||
actual_time_start: '',
|
||||
actual_time_end: '',
|
||||
attendance_count: '',
|
||||
status: 'planned',
|
||||
notes: '',
|
||||
trainer_notes: '',
|
||||
debrief_completed: false,
|
||||
sections: [defaultSection('Hauptteil')],
|
||||
...sessionAssignDefaults(),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API-Zeile → Formular (sync). `sections` müssen vorher via normalizeUnitToForm + enrich kommen.
|
||||
* @param {object} fullUnit
|
||||
* @param {object} sections — bereits angereicherte Editor-Sections
|
||||
*/
|
||||
export function trainingUnitToFormFields(fullUnit, sections) {
|
||||
const efLead =
|
||||
fullUnit.effective_lead_trainer_profile_id != null
|
||||
? Number(fullUnit.effective_lead_trainer_profile_id)
|
||||
: null
|
||||
let assistantIds = []
|
||||
if (Array.isArray(fullUnit.assistant_trainer_profile_ids)) {
|
||||
assistantIds = fullUnit.assistant_trainer_profile_ids
|
||||
.map((x) => Number(x))
|
||||
.filter((n) => Number.isFinite(n) && n >= 1)
|
||||
}
|
||||
if (efLead != null && Number.isFinite(efLead)) {
|
||||
assistantIds = assistantIds.filter((id) => id !== efLead)
|
||||
}
|
||||
|
||||
return {
|
||||
group_id: fullUnit.group_id,
|
||||
planned_date: fullUnit.planned_date || '',
|
||||
planned_time_start: fullUnit.planned_time_start?.slice?.(0, 5) || fullUnit.planned_time_start || '',
|
||||
planned_time_end: fullUnit.planned_time_end?.slice?.(0, 5) || fullUnit.planned_time_end || '',
|
||||
planned_focus: fullUnit.planned_focus || '',
|
||||
actual_date: fullUnit.actual_date || '',
|
||||
actual_time_start: fullUnit.actual_time_start?.slice?.(0, 5) || fullUnit.actual_time_start || '',
|
||||
actual_time_end: fullUnit.actual_time_end?.slice?.(0, 5) || fullUnit.actual_time_end || '',
|
||||
attendance_count: fullUnit.attendance_count ?? '',
|
||||
status: fullUnit.status || 'planned',
|
||||
notes: fullUnit.notes || '',
|
||||
trainer_notes: fullUnit.trainer_notes || '',
|
||||
debrief_completed: Boolean(fullUnit.debrief_completed_at),
|
||||
sections,
|
||||
lead_trainer_profile_id:
|
||||
fullUnit.lead_trainer_profile_id != null && fullUnit.lead_trainer_profile_id !== ''
|
||||
? String(fullUnit.lead_trainer_profile_id)
|
||||
: '',
|
||||
session_assistants_inherit:
|
||||
fullUnit.assistant_trainer_profile_ids == null ||
|
||||
fullUnit.assistant_trainer_profile_ids === undefined,
|
||||
session_assistant_profile_ids: assistantIds,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formular → API-Payload (identisch zur bisherigen Modal-Logik).
|
||||
* @param {object} formData
|
||||
* @param {{ editingUnit?: object|null, draftPlanTemplateId?: string }} opts
|
||||
*/
|
||||
export function buildTrainingUnitSavePayload(formData, { editingUnit = null, draftPlanTemplateId = '' } = {}) {
|
||||
const planPart = buildPlanPayloadForSave(formData.sections)
|
||||
const payload = {
|
||||
planned_date: formData.planned_date,
|
||||
planned_time_start: formData.planned_time_start || null,
|
||||
planned_time_end: formData.planned_time_end || null,
|
||||
planned_focus: formData.planned_focus || null,
|
||||
actual_date: formData.actual_date || null,
|
||||
actual_time_start: formData.actual_time_start || null,
|
||||
actual_time_end: formData.actual_time_end || null,
|
||||
attendance_count: formData.attendance_count ? parseInt(formData.attendance_count, 10) : null,
|
||||
status: formData.status || 'planned',
|
||||
notes: formData.notes || null,
|
||||
trainer_notes: formData.trainer_notes || null,
|
||||
...planPart,
|
||||
}
|
||||
|
||||
if (editingUnit) {
|
||||
payload.debrief_completed =
|
||||
(formData.status || '') === 'completed' ? !!formData.debrief_completed : false
|
||||
}
|
||||
|
||||
const leadStr = String(formData.lead_trainer_profile_id || '').trim()
|
||||
if (leadStr) {
|
||||
payload.lead_trainer_profile_id = parseInt(leadStr, 10)
|
||||
} else if (editingUnit) {
|
||||
payload.lead_trainer_profile_id = null
|
||||
}
|
||||
|
||||
if (formData.session_assistants_inherit) {
|
||||
if (editingUnit) payload.assistant_trainer_profile_ids = null
|
||||
} else {
|
||||
payload.assistant_trainer_profile_ids = [...(formData.session_assistant_profile_ids || [])].sort(
|
||||
(a, b) => a - b
|
||||
)
|
||||
}
|
||||
|
||||
if (!editingUnit) {
|
||||
payload.group_id = parseInt(formData.group_id, 10)
|
||||
if (draftPlanTemplateId) {
|
||||
payload.plan_template_id = parseInt(draftPlanTemplateId, 10)
|
||||
}
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
||||
export function validateTrainingUnitFormForSave(formData) {
|
||||
if (!formData?.group_id || !formData?.planned_date) {
|
||||
return { ok: false, message: 'Gruppe und Datum sind Pflichtfelder' }
|
||||
}
|
||||
return { ok: true }
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
buildTrainingUnitSavePayload,
|
||||
createEmptyTrainingUnitFormData,
|
||||
validateTrainingUnitFormForSave,
|
||||
} from './trainingUnitEditorCore.js'
|
||||
|
||||
describe('trainingUnitEditorCore', () => {
|
||||
it('createEmptyTrainingUnitFormData defaults', () => {
|
||||
const fd = createEmptyTrainingUnitFormData({ groupId: '2', plannedDate: '2026-05-01' })
|
||||
expect(fd.group_id).toBe('2')
|
||||
expect(fd.planned_date).toBe('2026-05-01')
|
||||
expect(fd.sections).toHaveLength(1)
|
||||
expect(fd.sections[0].title).toBe('Hauptteil')
|
||||
})
|
||||
|
||||
it('validateTrainingUnitFormForSave', () => {
|
||||
expect(validateTrainingUnitFormForSave({ group_id: '', planned_date: '' }).ok).toBe(false)
|
||||
expect(validateTrainingUnitFormForSave({ group_id: '1', planned_date: '2026-01-01' }).ok).toBe(true)
|
||||
})
|
||||
|
||||
it('buildTrainingUnitSavePayload create includes group and template', () => {
|
||||
const formData = createEmptyTrainingUnitFormData({ groupId: '5', plannedDate: '2026-05-10' })
|
||||
const payload = buildTrainingUnitSavePayload(formData, { draftPlanTemplateId: '9' })
|
||||
expect(payload.group_id).toBe(5)
|
||||
expect(payload.plan_template_id).toBe(9)
|
||||
expect(payload.planned_date).toBe('2026-05-10')
|
||||
expect(payload.sections).toBeDefined()
|
||||
})
|
||||
|
||||
it('buildTrainingUnitSavePayload update sets debrief and clears lead when empty', () => {
|
||||
const formData = {
|
||||
...createEmptyTrainingUnitFormData({ groupId: '5', plannedDate: '2026-05-10' }),
|
||||
status: 'completed',
|
||||
debrief_completed: true,
|
||||
lead_trainer_profile_id: '',
|
||||
session_assistants_inherit: true,
|
||||
}
|
||||
const payload = buildTrainingUnitSavePayload(formData, { editingUnit: { id: 1 } })
|
||||
expect(payload.debrief_completed).toBe(true)
|
||||
expect(payload.lead_trainer_profile_id).toBeNull()
|
||||
expect(payload.assistant_trainer_profile_ids).toBeNull()
|
||||
expect(payload.group_id).toBeUndefined()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user