- Implemented `goalProgressResolver` utility for resolving progress keys, slices, and periods. - Refactored `DepartmentGoals` to integrate `goalProgressResolver` for improved clarity and modularity. - Updated progress calculations with cadence-aware key handling and fallback resolution. - Add isLoading handling and loader animations to `DepartmentWeather` and improve `GET` request concurrency.
73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
normalizeTimeframeKey,
|
|
resolveGoalProgressKey,
|
|
resolveGoalProgressPeriod,
|
|
resolveGoalProgressSlice,
|
|
toProgressNumber
|
|
} from '@/views/dashboards/departmentDashboard/modules/goals/functions/goalProgressResolver.js';
|
|
|
|
describe('goal progress resolver', () => {
|
|
it('normalizes until_now to to_date', () => {
|
|
expect(normalizeTimeframeKey('until_now')).toBe('to_date');
|
|
expect(normalizeTimeframeKey('month')).toBe('month');
|
|
});
|
|
|
|
it('resolves legacy this_week alias for week timeframe', () => {
|
|
const scope = {
|
|
this_week: { count: 3, target: 7 }
|
|
};
|
|
|
|
expect(resolveGoalProgressKey(scope, 'week', {})).toBe('this_week');
|
|
expect(resolveGoalProgressSlice(scope, 'week', {})).toEqual({ count: 3, target: 7 });
|
|
});
|
|
|
|
it('resolves cadence-aware keys for bi-weekly targets', () => {
|
|
const scope = {
|
|
every_2_weeks: { count: 5, target: 14 },
|
|
week: { count: 1, target: 7 }
|
|
};
|
|
const criteria = {
|
|
target_duration: 'WEEKS',
|
|
target_duration_every: 2
|
|
};
|
|
|
|
expect(resolveGoalProgressKey(scope, 'week', criteria)).toBe('every_2_weeks');
|
|
expect(resolveGoalProgressSlice(scope, 'week', criteria)).toEqual({ count: 5, target: 14 });
|
|
});
|
|
|
|
it('falls back to preferred OpenAPI keys when selected key is missing', () => {
|
|
const scope = {
|
|
to_date: { count: 21, target: 30 },
|
|
all: { count: 42, target: 100 }
|
|
};
|
|
|
|
expect(resolveGoalProgressKey(scope, 'month', {})).toBe('to_date');
|
|
});
|
|
|
|
it('extracts period from snake_case or camelCase date fields', () => {
|
|
expect(resolveGoalProgressPeriod(
|
|
{ date_from: '2026-03-24T00:00:00+01:00', date_end: '2026-04-06T23:59:59+01:00' },
|
|
{ start: '2026-03-01T00:00:00+01:00', end: '2026-05-01T23:59:59+01:00' }
|
|
)).toEqual({
|
|
from: '2026-03-24T00:00:00+01:00',
|
|
end: '2026-04-06T23:59:59+01:00'
|
|
});
|
|
|
|
expect(resolveGoalProgressPeriod(
|
|
{ dateFrom: '2026-03-24T00:00:00+01:00', dateEnd: '2026-04-06T23:59:59+01:00' },
|
|
{ start: '2026-03-01T00:00:00+01:00', end: '2026-05-01T23:59:59+01:00' }
|
|
)).toEqual({
|
|
from: '2026-03-24T00:00:00+01:00',
|
|
end: '2026-04-06T23:59:59+01:00'
|
|
});
|
|
});
|
|
|
|
it('parses numeric strings safely for progress values', () => {
|
|
expect(toProgressNumber('12.5')).toBe(12.5);
|
|
expect(toProgressNumber(8)).toBe(8);
|
|
expect(toProgressNumber('')).toBe(null);
|
|
expect(toProgressNumber('abc')).toBe(null);
|
|
});
|
|
});
|