Add date range field provider coverage

active-uix
dev 5 months ago
parent c668cc1543
commit 2b36e2036c

@ -36,9 +36,11 @@ Actualizacion 2026-05-15:
- Correccion TimeField: el announcer se inicializa con `$effect` en vez de
`onMount()` dentro de la clase, y `datetime` separa
`areAllTimeSegmentsFilledDOM(...)` del helper de fecha.
- Cobertura nueva para DateRangeField: validación de rango y foco de label
via `ActiveDom`.
- Validado por fase:
- `npm run check` -> 0 errores, 0 warnings.
- `npm run test` -> 183 archivos, 2074 tests OK.
- `npm run test` -> 184 archivos, 2077 tests OK.
- tests focales de Select/Popover/Toast/RangeCalendar -> 11 tests OK.
- tests focales Dialog/Drawer/Popover/Select -> 10 tests OK.
- `command-provider.svelte.test.ts` -> 2 tests OK.
@ -49,6 +51,7 @@ Actualizacion 2026-05-15:
- `time-range-picker-provider.svelte.test.ts` -> 3 tests OK.
- `time-range-field-provider.svelte.test.ts` -> 3 tests OK.
- `time-field-provider.svelte.test.ts` -> 3 tests OK.
- `date-range-field-provider.svelte.test.ts` -> 3 tests OK.
- guardia `rg "from './.*provider\\.svelte'" src/uix/soma/components -g 'exports.ts'`
-> solo queda `select/components/select-provider.svelte`, que es wrapper
publico, no runtime provider.

@ -476,11 +476,13 @@ Los tests por componente estan creciendo desde las piezas de mayor riesgo. A
- `time-field/time-field-provider.svelte.test.ts` — validación, sincronización
de segmentos 12h y commit solo cuando los segmentos renderizados estan
completos.
- `date-range-field/date-range-field-provider.svelte.test.ts` — validación de
orden/min/max, validación custom y foco de label via `ActiveDom`.
Pendiente: ampliar cobertura a `DateRangeField`, el provider interno de
fecha/hora de mayor tamano que sigue sin test directo. `table-core`,
`form-core` y el scorer de Command ya no viven dentro de Soma: se consumen
desde `$libs/datagrid`, `$libs/forms` y `$libs/strings`.
Pendiente: seguir ampliando cobertura por familias de alto riesgo fuera del
bloque fecha/hora. `table-core`, `form-core` y el scorer de Command ya no viven
dentro de Soma: se consumen desde `$libs/datagrid`, `$libs/forms` y
`$libs/strings`.
### Convencion

@ -0,0 +1,170 @@
// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from 'vitest';
import { createActiveDom } from '$adom';
import { CalendarDate } from '$libs/days';
import type {
DateOnInvalid,
DateRange,
DateRangeValidator,
DateValue,
EditableSegmentPart,
Granularity,
HourCycle
} from '$libs/days';
import { state } from '$libs/reactive';
import type { Morfo } from '$uix/morfo';
import { Soma } from '$soma/core/soma.svelte';
import { createSomaRuntime, type SomaRuntimeSources } from '$soma/runtime.svelte';
import type { Direction } from '../../types';
import { FieldProvider } from '../field/field-provider.svelte';
import {
DateRangeFieldLabelProvider,
DateRangeFieldProvider
} from './date-range-field-provider.svelte';
function withEffectRoot<T>(fn: () => T): { result: T; cleanup: () => void } {
let result!: T;
const cleanup = $effect.root(() => {
result = fn();
});
return { result, cleanup };
}
function installSomaHarness() {
const dom = createActiveDom();
const soma = {
dom,
langs: {
getLocale: () => 'en-US',
ts: (key: string) => key
},
runtime: (morfo: Morfo, sources: Omit<SomaRuntimeSources, 'dom' | 'eventEngine'>) =>
createSomaRuntime(morfo, {
dom,
translate: (key) => key,
...sources
})
} as unknown as Soma;
vi.spyOn(Soma, 'require').mockReturnValue(soma);
vi.spyOn(FieldProvider, 'get').mockReturnValue(undefined);
vi.spyOn(DateRangeFieldProvider.ctx, 'set').mockImplementation((value) => value);
return { dom };
}
function createDateRangeFieldOpts(root = document.createElement('div')) {
return {
id: state('date-range-field-root'),
ref: state<HTMLElement | null>(root),
value: state<DateRange>({ start: undefined, end: undefined }),
placeholder: state<DateValue>(new CalendarDate(2026, 5, 15)),
startValue: state<DateValue | undefined>(undefined),
endValue: state<DateValue | undefined>(undefined),
validate: state<DateRangeValidator | undefined>(undefined),
onInvalid: state<DateOnInvalid | undefined>(undefined),
minValue: state<DateValue | undefined>(undefined),
maxValue: state<DateValue | undefined>(undefined),
disabled: state(false),
readonly: state(false),
startReadonlySegments: state<EditableSegmentPart[]>([]),
endReadonlySegments: state<EditableSegmentPart[]>([]),
required: state(false),
granularity: state<Granularity | undefined>(undefined),
hideTimeZone: state(false),
hourCycle: state<HourCycle | undefined>(undefined),
locale: state<string | undefined>('en-US'),
dir: state<Direction>('ltr'),
errorMessageId: state<string | undefined>(undefined)
};
}
describe('DateRangeFieldProvider', () => {
afterEach(() => {
vi.restoreAllMocks();
document.body.innerHTML = '';
});
it('validates endpoint ordering and min/max bounds', () => {
const { dom } = installSomaHarness();
const opts = createDateRangeFieldOpts();
const { result: provider, cleanup } = withEffectRoot(() => DateRangeFieldProvider.create(opts));
opts.value.current = {
start: new CalendarDate(2026, 5, 20),
end: new CalendarDate(2026, 5, 10)
};
expect(provider.validationStatus).toEqual({ reason: 'invalid' });
expect(provider.isInvalid).toBe(true);
opts.value.current = {
start: new CalendarDate(2026, 4, 30),
end: new CalendarDate(2026, 5, 10)
};
opts.minValue.current = new CalendarDate(2026, 5, 1);
expect(provider.validationStatus).toEqual({ reason: 'min' });
opts.minValue.current = undefined;
opts.maxValue.current = new CalendarDate(2026, 5, 30);
opts.value.current = {
start: new CalendarDate(2026, 5, 10),
end: new CalendarDate(2026, 6, 1)
};
expect(provider.validationStatus).toEqual({ reason: 'max' });
cleanup();
dom.dispose();
});
it('prefers custom validation when both endpoints are present', () => {
const { dom } = installSomaHarness();
const opts = createDateRangeFieldOpts();
opts.value.current = {
start: new CalendarDate(2026, 5, 10),
end: new CalendarDate(2026, 5, 11)
};
opts.validate.current = () => 'Blocked range';
const { result: provider, cleanup } = withEffectRoot(() => DateRangeFieldProvider.create(opts));
expect(provider.validationStatus).toEqual({
reason: 'custom',
message: 'Blocked range'
});
expect(provider.props['aria-invalid']).toBe(true);
cleanup();
dom.dispose();
});
it('focuses the first start segment when the label is clicked', () => {
const { dom } = installSomaHarness();
const root = document.createElement('div');
root.innerHTML = '<div id="start-input"><span id="start-month" data-segment></span></div>';
document.body.appendChild(root);
const opts = createDateRangeFieldOpts(root);
const focus = vi.spyOn(dom, 'focus');
const { result: provider, cleanup } = withEffectRoot(() => {
const p = DateRangeFieldProvider.create(opts);
vi.spyOn(DateRangeFieldProvider.ctx, 'get').mockReturnValue(p);
const label = DateRangeFieldLabelProvider.create({
id: state('date-range-label'),
ref: state<HTMLElement | null>(document.createElement('label'))
});
p.startInputId.current = 'start-input';
label.onclick();
return p;
});
expect(provider.startInputId.current).toBe('start-input');
expect(focus).toHaveBeenCalledWith(root.querySelector('#start-month'));
cleanup();
dom.dispose();
});
});
Loading…
Cancel
Save

Powered by TurnKey Linux.