@aquera/nile-elements 2.0.20 → 2.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/floating-ui.dom-9df9f37b.cjs.js +2 -0
- package/dist/floating-ui.dom-9df9f37b.cjs.js.map +1 -0
- package/dist/floating-ui.dom-c4ea6a32.esm.js +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +598 -488
- package/dist/nile-auto-complete/index.cjs.js +1 -1
- package/dist/nile-auto-complete/index.esm.js +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.cjs.js +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.esm.js +1 -1
- package/dist/nile-auto-complete/portal-manager.cjs.js +1 -1
- package/dist/nile-auto-complete/portal-manager.esm.js +1 -1
- package/dist/nile-button/nile-button.cjs.js +1 -1
- package/dist/nile-button/nile-button.cjs.js.map +1 -1
- package/dist/nile-button/nile-button.css.cjs.js +1 -1
- package/dist/nile-button/nile-button.css.cjs.js.map +1 -1
- package/dist/nile-button/nile-button.css.esm.js +46 -9
- package/dist/nile-button/nile-button.esm.js +6 -6
- package/dist/nile-color-picker/index.cjs.js +1 -1
- package/dist/nile-color-picker/index.esm.js +1 -1
- package/dist/nile-color-picker/nile-color-picker.cjs.js +1 -1
- package/dist/nile-color-picker/nile-color-picker.esm.js +1 -1
- package/dist/nile-combobox/index.cjs.js +1 -1
- package/dist/nile-combobox/index.esm.js +1 -1
- package/dist/nile-combobox/nile-combobox.cjs.js +1 -1
- package/dist/nile-combobox/nile-combobox.esm.js +1 -1
- package/dist/nile-combobox/portal-manager.cjs.js +1 -1
- package/dist/nile-combobox/portal-manager.esm.js +1 -1
- package/dist/nile-dropdown/index.cjs.js +1 -1
- package/dist/nile-dropdown/index.esm.js +1 -1
- package/dist/nile-dropdown/nile-dropdown.cjs.js +1 -1
- package/dist/nile-dropdown/nile-dropdown.esm.js +1 -1
- package/dist/nile-dropdown/portal-manager.cjs.js +1 -1
- package/dist/nile-dropdown/portal-manager.esm.js +1 -1
- package/dist/nile-empty-state/nile-empty-state.cjs.js +1 -1
- package/dist/nile-empty-state/nile-empty-state.cjs.js.map +1 -1
- package/dist/nile-empty-state/nile-empty-state.esm.js +4 -4
- package/dist/nile-markdown-editor/index.cjs.js +1 -1
- package/dist/nile-markdown-editor/index.esm.js +1 -1
- package/dist/nile-markdown-editor/nile-markdown-editor.cjs.js +1 -1
- package/dist/nile-markdown-editor/nile-markdown-editor.esm.js +1 -1
- package/dist/nile-popover/index.cjs.js +1 -1
- package/dist/nile-popover/index.esm.js +1 -1
- package/dist/nile-popover/nile-popover.cjs.js +1 -1
- package/dist/nile-popover/nile-popover.esm.js +1 -1
- package/dist/nile-popover/portal-manager.cjs.js +1 -1
- package/dist/nile-popover/portal-manager.esm.js +1 -1
- package/dist/nile-popup/index.cjs.js +1 -1
- package/dist/nile-popup/index.esm.js +1 -1
- package/dist/nile-popup/nile-popup.cjs.js +1 -1
- package/dist/nile-popup/nile-popup.esm.js +1 -1
- package/dist/nile-select/index.cjs.js +1 -1
- package/dist/nile-select/index.esm.js +1 -1
- package/dist/nile-select/nile-select.cjs.js +1 -1
- package/dist/nile-select/nile-select.esm.js +1 -1
- package/dist/nile-select/portal-manager.cjs.js +1 -1
- package/dist/nile-select/portal-manager.esm.js +1 -1
- package/dist/nile-side-bar-action/index.cjs.js +1 -1
- package/dist/nile-side-bar-action/index.esm.js +1 -1
- package/dist/nile-side-bar-action/nile-side-bar-action.cjs.js +1 -1
- package/dist/nile-side-bar-action/nile-side-bar-action.esm.js +1 -1
- package/dist/nile-side-bar-action/portal-manager.cjs.js +1 -1
- package/dist/nile-side-bar-action/portal-manager.esm.js +1 -1
- package/dist/nile-tooltip/index.cjs.js +1 -1
- package/dist/nile-tooltip/index.esm.js +1 -1
- package/dist/nile-tooltip/nile-tooltip.cjs.js +1 -1
- package/dist/nile-tooltip/nile-tooltip.esm.js +1 -1
- package/dist/nile-virtual-select/index.cjs.js +1 -1
- package/dist/nile-virtual-select/index.esm.js +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.cjs.js +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.esm.js +1 -1
- package/dist/nile-virtual-select/portal-manager.cjs.js +1 -1
- package/dist/nile-virtual-select/portal-manager.esm.js +1 -1
- package/dist/nile-wysiwyg-editor/index.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/index.esm.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.cjs.js.map +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.css.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.css.cjs.js.map +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.css.esm.js +73 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-editor.esm.js +3 -2
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-toolbar/index.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-toolbar/index.esm.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-toolbar/nile-wysiwyg-toolbar.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/nile-wysiwyg-toolbar/nile-wysiwyg-toolbar.esm.js +1 -1
- package/dist/nile-wysiwyg-editor/types.cjs.js +1 -1
- package/dist/nile-wysiwyg-editor/types.cjs.js.map +1 -1
- package/dist/nile-wysiwyg-editor/types.esm.js +1 -1
- package/dist/src/nile-button/nile-button.css.js +46 -9
- package/dist/src/nile-button/nile-button.css.js.map +1 -1
- package/dist/src/nile-button/nile-button.d.ts +2 -2
- package/dist/src/nile-button/nile-button.js +13 -5
- package/dist/src/nile-button/nile-button.js.map +1 -1
- package/dist/src/nile-button/nile-button.test.js +140 -2
- package/dist/src/nile-button/nile-button.test.js.map +1 -1
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-1.test.d.ts +47 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-1.test.js +578 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-1.test.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-2.test.d.ts +3 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-2.test.js +109 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-2.test.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-3.test.d.ts +3 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-3.test.js +356 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-3.test.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-4.test.d.ts +4 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-4.test.js +339 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.phases-4.test.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.regressions.test.d.ts +3 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.regressions.test.js +1472 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.regressions.test.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test-helpers.d.ts +103 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test-helpers.js +331 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test-helpers.js.map +1 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test.d.ts +0 -140
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test.js +1 -4495
- package/dist/src/nile-date-time-picker/nile-date-time-picker.test.js.map +1 -1
- package/dist/src/nile-date-time-picker/nile-date-time-picker.year-handling.test.d.ts +3 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.year-handling.test.js +1440 -0
- package/dist/src/nile-date-time-picker/nile-date-time-picker.year-handling.test.js.map +1 -0
- package/dist/src/nile-empty-state/nile-empty-state.d.ts +5 -0
- package/dist/src/nile-empty-state/nile-empty-state.js +11 -2
- package/dist/src/nile-empty-state/nile-empty-state.js.map +1 -1
- package/dist/src/nile-empty-state/nile-empty-state.test.js +31 -0
- package/dist/src/nile-empty-state/nile-empty-state.test.js.map +1 -1
- package/dist/src/nile-wysiwyg-editor/index.d.ts +2 -1
- package/dist/src/nile-wysiwyg-editor/index.js +1 -1
- package/dist/src/nile-wysiwyg-editor/index.js.map +1 -1
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.css.js +75 -0
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.css.js.map +1 -1
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.d.ts +20 -0
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.js +37 -1
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.js.map +1 -1
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.test.js +108 -0
- package/dist/src/nile-wysiwyg-editor/nile-wysiwyg-editor.test.js.map +1 -1
- package/dist/src/nile-wysiwyg-editor/types.d.ts +8 -0
- package/dist/src/nile-wysiwyg-editor/types.js +50 -0
- package/dist/src/nile-wysiwyg-editor/types.js.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/rollup.config.js +1 -0
- package/scripts/component-metrics.mjs +145 -0
- package/scripts/merge-coverage.cjs +33 -0
- package/src/nile-button/nile-button.css.ts +46 -9
- package/src/nile-button/nile-button.test.ts +162 -2
- package/src/nile-button/nile-button.ts +13 -4
- package/src/nile-date-time-picker/nile-date-time-picker.phases-1.test.ts +607 -0
- package/src/nile-date-time-picker/nile-date-time-picker.phases-2.test.ts +112 -0
- package/src/nile-date-time-picker/nile-date-time-picker.phases-3.test.ts +389 -0
- package/src/nile-date-time-picker/nile-date-time-picker.phases-4.test.ts +329 -0
- package/src/nile-date-time-picker/nile-date-time-picker.regressions.test.ts +1618 -0
- package/src/nile-date-time-picker/nile-date-time-picker.test-helpers.ts +381 -0
- package/src/nile-date-time-picker/nile-date-time-picker.test.ts +1 -4771
- package/src/nile-date-time-picker/nile-date-time-picker.year-handling.test.ts +1499 -0
- package/src/nile-empty-state/nile-empty-state.test.ts +24 -0
- package/src/nile-empty-state/nile-empty-state.ts +12 -2
- package/src/nile-wysiwyg-editor/index.ts +2 -1
- package/src/nile-wysiwyg-editor/nile-wysiwyg-editor.css.ts +76 -0
- package/src/nile-wysiwyg-editor/nile-wysiwyg-editor.test.ts +132 -0
- package/src/nile-wysiwyg-editor/nile-wysiwyg-editor.ts +40 -1
- package/src/nile-wysiwyg-editor/types.ts +52 -0
- package/test-timings.json +41 -0
- package/vscode-html-custom-data.json +42 -3
- package/web-test-runner.config.mjs +72 -2
- package/dist/floating-ui.dom-007bbe96.cjs.js +0 -2
- package/dist/floating-ui.dom-007bbe96.cjs.js.map +0 -1
- package/dist/floating-ui.dom-cc9126da.esm.js +0 -1
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TIMEZONES, utcFromFields, localDateFromFields, formatYear4, isClockTime } from '../nile-calendar/timezones';
|
|
3
|
-
import { instantFromBracketedValue, wallClockFromOffsetLess } from '../nile-calendar/nile-calendar';
|
|
1
|
+
import { expect, fixture, html } from '@open-wc/testing';
|
|
4
2
|
import './nile-date-time-picker';
|
|
5
3
|
import '../nile-calendar';
|
|
6
4
|
import '../nile-input';
|
|
@@ -2782,4496 +2780,4 @@ describe('NileDateTimePicker (wrapper)', () => {
|
|
|
2782
2780
|
});
|
|
2783
2781
|
});
|
|
2784
2782
|
});
|
|
2785
|
-
/** Temporal, only if the runtime genuinely has it. Never faked. */
|
|
2786
|
-
export const TEMPORAL = typeof globalThis.Temporal !== 'undefined' ? globalThis.Temporal : null;
|
|
2787
|
-
/* ── B. epoch -> true UTC offset in a zone ────────────────────────────────── */
|
|
2788
|
-
const OFFSET_FMT_CACHE = new Map();
|
|
2789
|
-
/**
|
|
2790
|
-
* The zone's real offset at an instant, in ms, east-positive.
|
|
2791
|
-
* Independent mechanism: reads Intl's own printed offset string rather than
|
|
2792
|
-
* reconstructing it from formatted date parts.
|
|
2793
|
-
*/
|
|
2794
|
-
export function offsetAt(epochMs, zone) {
|
|
2795
|
-
let fmt = OFFSET_FMT_CACHE.get(zone);
|
|
2796
|
-
if (!fmt) {
|
|
2797
|
-
fmt = new Intl.DateTimeFormat('en-US', { timeZone: zone, timeZoneName: 'longOffset' });
|
|
2798
|
-
OFFSET_FMT_CACHE.set(zone, fmt);
|
|
2799
|
-
}
|
|
2800
|
-
const part = fmt.formatToParts(new Date(epochMs)).find(p => p.type === 'timeZoneName');
|
|
2801
|
-
if (!part)
|
|
2802
|
-
throw new Error(`no timeZoneName part for ${zone}`);
|
|
2803
|
-
const t = part.value.trim();
|
|
2804
|
-
// "GMT" (exactly) means +00:00; otherwise "GMT+05:30" / "GMT-03:30" / "GMT+14"
|
|
2805
|
-
if (t === 'GMT' || t === 'UTC')
|
|
2806
|
-
return 0;
|
|
2807
|
-
const m = /^(?:GMT|UTC)([+-])(\d{1,2})(?::(\d{2}))?(?::(\d{2}))?$/.exec(t);
|
|
2808
|
-
if (!m)
|
|
2809
|
-
throw new Error(`unparsable offset "${t}" for ${zone}`);
|
|
2810
|
-
const sign = m[1] === '-' ? -1 : 1;
|
|
2811
|
-
const h = Number(m[2]);
|
|
2812
|
-
const mi = Number(m[3] ?? 0);
|
|
2813
|
-
const s = Number(m[4] ?? 0);
|
|
2814
|
-
return sign * (h * 3600000 + mi * 60000 + s * 1000);
|
|
2815
|
-
}
|
|
2816
|
-
/* ── A. epoch -> wall clock in a zone ─────────────────────────────────────── */
|
|
2817
|
-
/**
|
|
2818
|
-
* Derived from the offset by pure UTC arithmetic — NOT by formatting the date
|
|
2819
|
-
* into y/m/d/h/m/s parts. Independent of the implementation's approach.
|
|
2820
|
-
*/
|
|
2821
|
-
export function wallAt(epochMs, zone) {
|
|
2822
|
-
const local = epochMs + offsetAt(epochMs, zone);
|
|
2823
|
-
const d = new Date(local);
|
|
2824
|
-
return {
|
|
2825
|
-
year: d.getUTCFullYear(), month: d.getUTCMonth() + 1, day: d.getUTCDate(),
|
|
2826
|
-
hours: d.getUTCHours(), minutes: d.getUTCMinutes(),
|
|
2827
|
-
seconds: d.getUTCSeconds(), ms: d.getUTCMilliseconds(),
|
|
2828
|
-
};
|
|
2829
|
-
}
|
|
2830
|
-
/* ── C. wall clock + zone -> candidate instant(s) ─────────────────────────── */
|
|
2831
|
-
/** Wall clock as a "UTC-pretending" epoch — the anchor both sides agree on. */
|
|
2832
|
-
export function wallToUTCms(w) {
|
|
2833
|
-
return utcFromFields(w.year, w.month - 1, w.day, w.hours, w.minutes, w.seconds, w.ms);
|
|
2834
|
-
}
|
|
2835
|
-
export function wallEquals(a, b) {
|
|
2836
|
-
return a.year === b.year && a.month === b.month && a.day === b.day &&
|
|
2837
|
-
a.hours === b.hours && a.minutes === b.minutes &&
|
|
2838
|
-
a.seconds === b.seconds && a.ms === b.ms;
|
|
2839
|
-
}
|
|
2840
|
-
/**
|
|
2841
|
-
* EVERY instant the zone displays as exactly `w`.
|
|
2842
|
-
* [] -> the wall clock does not exist (spring-forward gap)
|
|
2843
|
-
* [t] -> unambiguous
|
|
2844
|
-
* [t1, t2] -> ambiguous (fall-back overlap), ascending
|
|
2845
|
-
*
|
|
2846
|
-
* Method: the true offset is within ±26h of any guess, so probing the offsets
|
|
2847
|
-
* reported at guess-26h .. guess+26h yields every candidate; each is then
|
|
2848
|
-
* CONFIRMED by reading it back. No reliance on a correction-pass converging.
|
|
2849
|
-
*/
|
|
2850
|
-
export function instantsFor(w, zone) {
|
|
2851
|
-
const guess = wallToUTCms(w);
|
|
2852
|
-
const probes = new Set();
|
|
2853
|
-
for (let h = -26; h <= 26; h++)
|
|
2854
|
-
probes.add(offsetAt(guess + h * 3600000, zone));
|
|
2855
|
-
const out = [];
|
|
2856
|
-
for (const off of probes) {
|
|
2857
|
-
const cand = guess - off;
|
|
2858
|
-
if (out.indexOf(cand) !== -1)
|
|
2859
|
-
continue;
|
|
2860
|
-
if (wallEquals(wallAt(cand, zone), w))
|
|
2861
|
-
out.push(cand);
|
|
2862
|
-
}
|
|
2863
|
-
return out.sort((a, b) => a - b);
|
|
2864
|
-
}
|
|
2865
|
-
/* ── D. independent parsers ───────────────────────────────────────────────── */
|
|
2866
|
-
/** `...Z` / `...±HH:MM` -> exact instant. Built by hand, not via `new Date`. */
|
|
2867
|
-
export function parseInstantString(raw) {
|
|
2868
|
-
const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?(?:\.(\d{1,3}))?(Z|[+-]\d{2}:?\d{2})$/
|
|
2869
|
-
.exec(raw.trim());
|
|
2870
|
-
if (!m)
|
|
2871
|
-
return null;
|
|
2872
|
-
const [, y, mo, d, h, mi, s, frac, zulu] = m;
|
|
2873
|
-
const ms = frac === undefined ? 0 : Number(frac.padEnd(3, '0'));
|
|
2874
|
-
const base = utcFromFields(Number(y), Number(mo) - 1, Number(d), Number(h), Number(mi), Number(s ?? 0), ms);
|
|
2875
|
-
if (zulu === 'Z')
|
|
2876
|
-
return base;
|
|
2877
|
-
const om = /^([+-])(\d{2}):?(\d{2})$/.exec(zulu);
|
|
2878
|
-
const off = (om[1] === '-' ? -1 : 1) * (Number(om[2]) * 3600000 + Number(om[3]) * 60000);
|
|
2879
|
-
return base - off;
|
|
2880
|
-
}
|
|
2881
|
-
/** Offset-less datetime -> wall clock digits only (no zone applied). */
|
|
2882
|
-
export function parseOffsetLess(raw) {
|
|
2883
|
-
const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?(?:\.(\d{1,3}))?$/.exec(raw.trim());
|
|
2884
|
-
if (!m)
|
|
2885
|
-
return null;
|
|
2886
|
-
const [, y, mo, d, h, mi, s, frac] = m;
|
|
2887
|
-
return {
|
|
2888
|
-
year: Number(y), month: Number(mo), day: Number(d),
|
|
2889
|
-
hours: Number(h), minutes: Number(mi), seconds: Number(s ?? 0),
|
|
2890
|
-
// NOTE: read as written, NOT scaled — ".25" is 25ms. Records current intent.
|
|
2891
|
-
ms: frac === undefined ? 0 : Number(frac),
|
|
2892
|
-
};
|
|
2893
|
-
}
|
|
2894
|
-
/** Nile bracketed form -> its parts. Independent regex. */
|
|
2895
|
-
export function parseBracketed(raw) {
|
|
2896
|
-
const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,3}))?\[GMT([+-])(\d{2}):(\d{2})\s+([^\]]+)\]$/
|
|
2897
|
-
.exec(raw.trim());
|
|
2898
|
-
if (!m)
|
|
2899
|
-
return null;
|
|
2900
|
-
const [, y, mo, d, h, mi, s, frac, sign, oh, om, zone] = m;
|
|
2901
|
-
return {
|
|
2902
|
-
wall: {
|
|
2903
|
-
year: Number(y), month: Number(mo), day: Number(d),
|
|
2904
|
-
hours: Number(h), minutes: Number(mi), seconds: Number(s),
|
|
2905
|
-
ms: frac === undefined ? 0 : Number(frac.padEnd(3, '0')),
|
|
2906
|
-
},
|
|
2907
|
-
offsetMs: (sign === '-' ? -1 : 1) * (Number(oh) * 3600000 + Number(om) * 60000),
|
|
2908
|
-
zone: zone.trim(),
|
|
2909
|
-
};
|
|
2910
|
-
}
|
|
2911
|
-
/* ── DST transition discovery (PHASE 4) ──────────────────────────────────── */
|
|
2912
|
-
/** Every offset change in [from, to), found by coarse scan + binary search. */
|
|
2913
|
-
export function findTransitions(zone, from, to) {
|
|
2914
|
-
const STEP = 6 * 3600000;
|
|
2915
|
-
const hits = [];
|
|
2916
|
-
let prev = offsetAt(from, zone);
|
|
2917
|
-
for (let t = from + STEP; t < to; t += STEP) {
|
|
2918
|
-
const cur = offsetAt(t, zone);
|
|
2919
|
-
if (cur !== prev) {
|
|
2920
|
-
let lo = t - STEP, hi = t;
|
|
2921
|
-
// 1ms precision: at 1s precision offsetAt(t-1) can already read the NEW
|
|
2922
|
-
// offset, which silently classifies a forward transition as delta=0.
|
|
2923
|
-
while (hi - lo > 1) {
|
|
2924
|
-
const mid = lo + Math.floor((hi - lo) / 2);
|
|
2925
|
-
if (offsetAt(mid, zone) === prev)
|
|
2926
|
-
lo = mid;
|
|
2927
|
-
else
|
|
2928
|
-
hi = mid;
|
|
2929
|
-
}
|
|
2930
|
-
hits.push(hi);
|
|
2931
|
-
prev = cur;
|
|
2932
|
-
}
|
|
2933
|
-
}
|
|
2934
|
-
return hits;
|
|
2935
|
-
}
|
|
2936
|
-
/** Zones the runtime itself offers — the same source the component's list uses. */
|
|
2937
|
-
export function runtimeZones() {
|
|
2938
|
-
const anyIntl = Intl;
|
|
2939
|
-
return typeof anyIntl.supportedValuesOf === 'function'
|
|
2940
|
-
? anyIntl.supportedValuesOf('timeZone')
|
|
2941
|
-
: [];
|
|
2942
|
-
}
|
|
2943
|
-
export function isResolvable(zone) {
|
|
2944
|
-
try {
|
|
2945
|
-
new Intl.DateTimeFormat('en-US', { timeZone: zone });
|
|
2946
|
-
return true;
|
|
2947
|
-
}
|
|
2948
|
-
catch {
|
|
2949
|
-
return false;
|
|
2950
|
-
}
|
|
2951
|
-
}
|
|
2952
|
-
/* ── deterministic RNG (PHASE 12) ─────────────────────────────────────────── */
|
|
2953
|
-
export function mulberry32(seed) {
|
|
2954
|
-
let a = seed >>> 0;
|
|
2955
|
-
return () => {
|
|
2956
|
-
a = (a + 0x6D2B79F5) >>> 0;
|
|
2957
|
-
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
2958
|
-
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
2959
|
-
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
2960
|
-
};
|
|
2961
|
-
}
|
|
2962
|
-
export const fmtWall = (w) => `${String(w.year).padStart(4, '0')}-${String(w.month).padStart(2, '0')}-${String(w.day).padStart(2, '0')}` +
|
|
2963
|
-
`T${String(w.hours).padStart(2, '0')}:${String(w.minutes).padStart(2, '0')}:${String(w.seconds).padStart(2, '0')}` +
|
|
2964
|
-
`.${String(w.ms).padStart(3, '0')}`;
|
|
2965
|
-
/** Inverse of wallToUTCms — read a "UTC-pretending" epoch back as wall digits. */
|
|
2966
|
-
export function wallFromUTCms(ms) {
|
|
2967
|
-
const d = new Date(ms);
|
|
2968
|
-
return {
|
|
2969
|
-
year: d.getUTCFullYear(), month: d.getUTCMonth() + 1, day: d.getUTCDate(),
|
|
2970
|
-
hours: d.getUTCHours(), minutes: d.getUTCMinutes(),
|
|
2971
|
-
seconds: d.getUTCSeconds(), ms: d.getUTCMilliseconds(),
|
|
2972
|
-
};
|
|
2973
|
-
}
|
|
2974
|
-
/** Classify a transition and give a wall clock strictly inside the gap/overlap. */
|
|
2975
|
-
export function transitionShape(t, zone) {
|
|
2976
|
-
const offBefore = offsetAt(t - 1, zone);
|
|
2977
|
-
const offAfter = offsetAt(t, zone);
|
|
2978
|
-
const deltaMs = offAfter - offBefore;
|
|
2979
|
-
// wall clocks in [t+offBefore, t+offAfter) are skipped (forward) or repeated
|
|
2980
|
-
// (backward, with the interval reversed). Take the midpoint either way.
|
|
2981
|
-
const lo = Math.min(t + offBefore, t + offAfter);
|
|
2982
|
-
const hi = Math.max(t + offBefore, t + offAfter);
|
|
2983
|
-
return {
|
|
2984
|
-
kind: deltaMs > 0 ? 'forward' : 'backward',
|
|
2985
|
-
deltaMs,
|
|
2986
|
-
insideWall: wallFromUTCms(lo + Math.floor((hi - lo) / 2)),
|
|
2987
|
-
offBefore, offAfter,
|
|
2988
|
-
};
|
|
2989
|
-
}
|
|
2990
|
-
/* ── driving the real component ───────────────────────────────────────────── */
|
|
2991
|
-
export async function makePicker(attrs) {
|
|
2992
|
-
const el = attrs.value === undefined || attrs.value === null
|
|
2993
|
-
? await fixture(html `<nile-date-time-picker .timezone=${attrs.timezone ?? 'UTC'}></nile-date-time-picker>`)
|
|
2994
|
-
: await fixture(html `<nile-date-time-picker
|
|
2995
|
-
value=${attrs.value} .timezone=${attrs.timezone ?? 'UTC'}></nile-date-time-picker>`);
|
|
2996
|
-
await settle2(el);
|
|
2997
|
-
return el;
|
|
2998
|
-
}
|
|
2999
|
-
export async function settle(el) {
|
|
3000
|
-
await el.updateComplete;
|
|
3001
|
-
const cal = el.calendarElement;
|
|
3002
|
-
if (cal)
|
|
3003
|
-
await cal.updateComplete;
|
|
3004
|
-
return cal;
|
|
3005
|
-
}
|
|
3006
|
-
/** A preset value may adopt a zone, scheduling a second update. Settle twice. */
|
|
3007
|
-
export async function settle2(el) {
|
|
3008
|
-
await settle(el);
|
|
3009
|
-
return settle(el);
|
|
3010
|
-
}
|
|
3011
|
-
export let LAST_EMIT_COUNT = 0;
|
|
3012
|
-
export const applyButton = (cal) => cal.shadowRoot.querySelector('.apply-button');
|
|
3013
|
-
/** Click the real Apply button and capture the single committed payload. */
|
|
3014
|
-
export async function apply(el) {
|
|
3015
|
-
const cal = await settle(el);
|
|
3016
|
-
let detail = null;
|
|
3017
|
-
let count = 0;
|
|
3018
|
-
const onChange = (e) => { detail = e.detail; count += 1; };
|
|
3019
|
-
el.addEventListener('nile-change', onChange);
|
|
3020
|
-
applyButton(cal).click();
|
|
3021
|
-
await settle(el);
|
|
3022
|
-
el.removeEventListener('nile-change', onChange);
|
|
3023
|
-
// Apply legitimately emits nothing when there is no selection — record the
|
|
3024
|
-
// count without assuming a payload exists.
|
|
3025
|
-
LAST_EMIT_COUNT = count;
|
|
3026
|
-
if (detail)
|
|
3027
|
-
detail.__emitCount = count;
|
|
3028
|
-
return detail;
|
|
3029
|
-
}
|
|
3030
|
-
/** Seed a wall clock directly into the panel, then Apply. */
|
|
3031
|
-
export async function selectAndApply(el, w, zone) {
|
|
3032
|
-
const cal = await settle(el);
|
|
3033
|
-
cal.timezone = zone;
|
|
3034
|
-
await settle(el);
|
|
3035
|
-
// the day is read field-wise from `value`; noon anchor keeps the DAY stable
|
|
3036
|
-
cal.value = localDateFromFields(w.year, w.month - 1, w.day, 12, 0, 0, 0);
|
|
3037
|
-
cal.currentMonth = w.month - 1;
|
|
3038
|
-
cal.currentYear = w.year;
|
|
3039
|
-
cal.tpHours = w.hours;
|
|
3040
|
-
cal.tpMinutes = w.minutes;
|
|
3041
|
-
cal.tpSeconds = w.seconds;
|
|
3042
|
-
cal.tpMilliseconds = w.ms;
|
|
3043
|
-
await settle(el);
|
|
3044
|
-
return apply(el);
|
|
3045
|
-
}
|
|
3046
|
-
/* ── PHASE 16: the invariant checker ─────────────────────────────────────── */
|
|
3047
|
-
/**
|
|
3048
|
-
* Every assertion is made against the ORACLE, never against component helpers.
|
|
3049
|
-
* Returns [] when the payload is internally consistent.
|
|
3050
|
-
*/
|
|
3051
|
-
export function checkPayload(p, intendedZone) {
|
|
3052
|
-
const v = [];
|
|
3053
|
-
if (!p)
|
|
3054
|
-
return [{ code: 'NO_PAYLOAD', detail: 'Apply emitted nothing' }];
|
|
3055
|
-
if (p.unixEpoch === null) {
|
|
3056
|
-
if (p.value !== null)
|
|
3057
|
-
v.push({ code: 'NULL_EPOCH_WITH_VALUE', detail: `value=${p.value}` });
|
|
3058
|
-
return v;
|
|
3059
|
-
}
|
|
3060
|
-
// A. localTimezoneValue mirrors the epoch
|
|
3061
|
-
if (!p.localTimezoneValue || p.localTimezoneValue.getTime() !== p.unixEpoch) {
|
|
3062
|
-
v.push({
|
|
3063
|
-
code: 'A_LTV_NE_EPOCH',
|
|
3064
|
-
detail: `localTimezoneValue=${p.localTimezoneValue && p.localTimezoneValue.getTime()} epoch=${p.unixEpoch}`,
|
|
3065
|
-
});
|
|
3066
|
-
}
|
|
3067
|
-
// E. timezone is the intended one
|
|
3068
|
-
if (intendedZone !== undefined && p.timezone !== intendedZone) {
|
|
3069
|
-
v.push({ code: 'E_TZ_MISMATCH', detail: `payload tz=${p.timezone} intended=${intendedZone}` });
|
|
3070
|
-
}
|
|
3071
|
-
if (p.value === null) {
|
|
3072
|
-
v.push({ code: 'EPOCH_WITHOUT_VALUE', detail: `epoch=${p.unixEpoch}` });
|
|
3073
|
-
return v;
|
|
3074
|
-
}
|
|
3075
|
-
const parsed = parseBracketed(p.value);
|
|
3076
|
-
if (!parsed) {
|
|
3077
|
-
v.push({ code: 'VALUE_UNPARSABLE', detail: `value=${p.value}` });
|
|
3078
|
-
return v;
|
|
3079
|
-
}
|
|
3080
|
-
// D. printed offset == zone's ACTUAL offset at the epoch
|
|
3081
|
-
let trueOff = null;
|
|
3082
|
-
try {
|
|
3083
|
-
trueOff = offsetAt(p.unixEpoch, p.timezone);
|
|
3084
|
-
}
|
|
3085
|
-
catch { /* unresolvable */ }
|
|
3086
|
-
if (trueOff !== null && parsed.offsetMs !== trueOff) {
|
|
3087
|
-
v.push({
|
|
3088
|
-
code: 'D_OFFSET_WRONG',
|
|
3089
|
-
detail: `printed=${parsed.offsetMs / 60000}min true=${trueOff / 60000}min at epoch=${p.unixEpoch} tz=${p.timezone}`,
|
|
3090
|
-
});
|
|
3091
|
-
}
|
|
3092
|
-
// C. printed digits == the zone's reading of the epoch
|
|
3093
|
-
if (trueOff !== null) {
|
|
3094
|
-
const expected = wallAt(p.unixEpoch, p.timezone);
|
|
3095
|
-
if (!wallEquals(parsed.wall, expected)) {
|
|
3096
|
-
v.push({
|
|
3097
|
-
code: 'C_DIGITS_WRONG',
|
|
3098
|
-
detail: `printed=${fmtWall(parsed.wall)} expected=${fmtWall(expected)} tz=${p.timezone} epoch=${p.unixEpoch}`,
|
|
3099
|
-
});
|
|
3100
|
-
}
|
|
3101
|
-
}
|
|
3102
|
-
// B. the value, resolved independently, is the same instant as unixEpoch
|
|
3103
|
-
// (digits - printed offset must equal the epoch)
|
|
3104
|
-
const fromValue = utcFromFields(parsed.wall.year, parsed.wall.month - 1, parsed.wall.day, parsed.wall.hours, parsed.wall.minutes, parsed.wall.seconds, parsed.wall.ms) - parsed.offsetMs;
|
|
3105
|
-
if (fromValue !== p.unixEpoch) {
|
|
3106
|
-
v.push({
|
|
3107
|
-
code: 'B_VALUE_NE_EPOCH',
|
|
3108
|
-
detail: `value resolves to ${fromValue} but unixEpoch=${p.unixEpoch} (delta ${fromValue - p.unixEpoch}ms) value=${p.value}`,
|
|
3109
|
-
});
|
|
3110
|
-
}
|
|
3111
|
-
return v;
|
|
3112
|
-
}
|
|
3113
|
-
/** F. emit -> reload -> Apply preserves the epoch exactly. */
|
|
3114
|
-
export async function roundTrip(p) {
|
|
3115
|
-
const el2 = await makePicker({ value: p.value, timezone: p.timezone });
|
|
3116
|
-
const second = await apply(el2);
|
|
3117
|
-
const violations = checkPayload(second, undefined);
|
|
3118
|
-
if (second && second.unixEpoch !== p.unixEpoch) {
|
|
3119
|
-
violations.push({
|
|
3120
|
-
code: 'F_EPOCH_DRIFT',
|
|
3121
|
-
detail: `first=${p.unixEpoch} second=${second.unixEpoch} delta=${(second.unixEpoch ?? 0) - (p.unixEpoch ?? 0)}ms value=${p.value}`,
|
|
3122
|
-
});
|
|
3123
|
-
}
|
|
3124
|
-
return { second, violations };
|
|
3125
|
-
}
|
|
3126
|
-
export const HOST_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
3127
|
-
/** Collects failures so a sweep reports ALL of them, not just the first. */
|
|
3128
|
-
export class Failures {
|
|
3129
|
-
constructor() {
|
|
3130
|
-
this.rows = [];
|
|
3131
|
-
}
|
|
3132
|
-
add(ctx, vs) {
|
|
3133
|
-
for (const x of vs)
|
|
3134
|
-
this.rows.push(`[${x.code}] ${ctx} :: ${x.detail}`);
|
|
3135
|
-
}
|
|
3136
|
-
get count() { return this.rows.length; }
|
|
3137
|
-
report(limit = 25) {
|
|
3138
|
-
if (!this.rows.length)
|
|
3139
|
-
return '';
|
|
3140
|
-
const head = this.rows.slice(0, limit).join('\n ');
|
|
3141
|
-
return `\n ${head}${this.rows.length > limit ? `\n ...and ${this.rows.length - limit} more` : ''}`;
|
|
3142
|
-
}
|
|
3143
|
-
}
|
|
3144
|
-
/* ==========================================================================
|
|
3145
|
-
PART 3 — PHASE 1: oracle validation + driver smoke test
|
|
3146
|
-
(was p1-oracle.test.ts)
|
|
3147
|
-
========================================================================== */
|
|
3148
|
-
describe('PHASE 1 — oracle validation', () => {
|
|
3149
|
-
it('P1.0 reports the environment (host zone, Temporal, zone count)', () => {
|
|
3150
|
-
const zones = runtimeZones();
|
|
3151
|
-
// eslint-disable-next-line no-console
|
|
3152
|
-
console.warn(`[audit-env] hostTZ=${HOST_TZ} temporal=${TEMPORAL ? 'YES' : 'NO'} ` +
|
|
3153
|
-
`zones=${zones.length} ua=${navigator.userAgent.slice(0, 60)}`);
|
|
3154
|
-
expect(zones.length, 'runtime must expose a timezone list').to.be.greaterThan(100);
|
|
3155
|
-
});
|
|
3156
|
-
it('P1.1 offsetAt matches known fixed offsets', () => {
|
|
3157
|
-
const t = Date.UTC(2026, 5, 15, 12, 0, 0);
|
|
3158
|
-
expect(offsetAt(t, 'UTC')).to.equal(0);
|
|
3159
|
-
expect(offsetAt(t, 'Asia/Kolkata')).to.equal(5.5 * 3600000);
|
|
3160
|
-
expect(offsetAt(t, 'Asia/Kathmandu')).to.equal(5.75 * 3600000);
|
|
3161
|
-
expect(offsetAt(t, 'Australia/Eucla')).to.equal(8.75 * 3600000);
|
|
3162
|
-
expect(offsetAt(t, 'Pacific/Kiritimati')).to.equal(14 * 3600000);
|
|
3163
|
-
expect(offsetAt(t, 'Pacific/Marquesas')).to.equal(-9.5 * 3600000);
|
|
3164
|
-
expect(offsetAt(t, 'America/St_Johns')).to.equal(-2.5 * 3600000); // NDT in June
|
|
3165
|
-
});
|
|
3166
|
-
it('P1.2 wallAt round-trips against instantsFor on unambiguous times', () => {
|
|
3167
|
-
const zones = ['UTC', 'Asia/Kolkata', 'America/New_York', 'Pacific/Auckland', 'Australia/Lord_Howe'];
|
|
3168
|
-
for (const z of zones) {
|
|
3169
|
-
for (const t of [Date.UTC(2026, 0, 15, 3, 7, 11, 123), Date.UTC(2026, 6, 15, 18, 44, 2, 9)]) {
|
|
3170
|
-
const w = wallAt(t, z);
|
|
3171
|
-
const back = instantsFor(w, z);
|
|
3172
|
-
expect(back, `${z} ${fmtWall(w)}`).to.include(t);
|
|
3173
|
-
}
|
|
3174
|
-
}
|
|
3175
|
-
});
|
|
3176
|
-
it('P1.3 instantsFor returns 0 for a gap and 2 for an overlap (New York 2026)', () => {
|
|
3177
|
-
const gap = instantsFor({ year: 2026, month: 3, day: 8, hours: 2, minutes: 30, seconds: 0, ms: 0 }, 'America/New_York');
|
|
3178
|
-
expect(gap, 'spring-forward 02:30 must not exist').to.have.lengthOf(0);
|
|
3179
|
-
const dup = instantsFor({ year: 2026, month: 11, day: 1, hours: 1, minutes: 30, seconds: 0, ms: 0 }, 'America/New_York');
|
|
3180
|
-
expect(dup, 'fall-back 01:30 occurs twice').to.have.lengthOf(2);
|
|
3181
|
-
expect(dup[1] - dup[0], 'occurrences are 1h apart').to.equal(3600000);
|
|
3182
|
-
});
|
|
3183
|
-
it('P1.4 Temporal agrees with the oracle — or is explicitly absent (never silent)', () => {
|
|
3184
|
-
if (!TEMPORAL) {
|
|
3185
|
-
// eslint-disable-next-line no-console
|
|
3186
|
-
console.warn('[audit-env] TEMPORAL UNAVAILABLE — P1.4 cross-check NOT PERFORMED. ' +
|
|
3187
|
-
'Oracle rests on Intl longOffset + UTC arithmetic alone.');
|
|
3188
|
-
expect(TEMPORAL, 'recorded as not-tested, not as passed').to.equal(null);
|
|
3189
|
-
return;
|
|
3190
|
-
}
|
|
3191
|
-
// Current Temporal: Temporal.TimeZone was removed; zones are plain strings
|
|
3192
|
-
// reached through ZonedDateTime. Probe the shape rather than assume it.
|
|
3193
|
-
const probe = TEMPORAL.Instant && TEMPORAL.Instant.fromEpochMilliseconds;
|
|
3194
|
-
if (!probe) {
|
|
3195
|
-
// eslint-disable-next-line no-console
|
|
3196
|
-
console.warn('[audit-env] Temporal present but Instant.fromEpochMilliseconds missing — NOT TESTED');
|
|
3197
|
-
expect.fail('Temporal present but unusable — investigate rather than silently pass');
|
|
3198
|
-
}
|
|
3199
|
-
let checked = 0;
|
|
3200
|
-
for (const z of ['UTC', 'Asia/Kolkata', 'Asia/Kathmandu', 'America/New_York',
|
|
3201
|
-
'Australia/Lord_Howe', 'Pacific/Chatham', 'Pacific/Kiritimati', 'America/St_Johns']) {
|
|
3202
|
-
for (const t of [Date.UTC(2026, 0, 15, 12, 0, 0), Date.UTC(2026, 6, 15, 12, 0, 0)]) {
|
|
3203
|
-
const zdt = TEMPORAL.Instant.fromEpochMilliseconds(t).toZonedDateTimeISO(z);
|
|
3204
|
-
expect(Number(zdt.offsetNanoseconds) / 1e6, `Temporal vs oracle ${z} @${t}`)
|
|
3205
|
-
.to.equal(offsetAt(t, z));
|
|
3206
|
-
const w = wallAt(t, z);
|
|
3207
|
-
expect(zdt.year, `Temporal year ${z}`).to.equal(w.year);
|
|
3208
|
-
expect(zdt.month, `Temporal month ${z}`).to.equal(w.month);
|
|
3209
|
-
expect(zdt.day, `Temporal day ${z}`).to.equal(w.day);
|
|
3210
|
-
expect(zdt.hour, `Temporal hour ${z}`).to.equal(w.hours);
|
|
3211
|
-
expect(zdt.minute, `Temporal minute ${z}`).to.equal(w.minutes);
|
|
3212
|
-
checked += 1;
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
// eslint-disable-next-line no-console
|
|
3216
|
-
console.warn(`[audit-env] Temporal cross-check PERFORMED on ${checked} zone/date pairs`);
|
|
3217
|
-
});
|
|
3218
|
-
it('P1.5 findTransitions locates the two US 2026 transitions', () => {
|
|
3219
|
-
const ts = findTransitions('America/New_York', Date.UTC(2026, 0, 1), Date.UTC(2027, 0, 1));
|
|
3220
|
-
expect(ts, 'two transitions in 2026').to.have.lengthOf(2);
|
|
3221
|
-
expect(wallAt(ts[0], 'America/New_York').month).to.equal(3);
|
|
3222
|
-
expect(wallAt(ts[1], 'America/New_York').month).to.equal(11);
|
|
3223
|
-
});
|
|
3224
|
-
it('P1.6 independent parsers agree with hand-computed instants', () => {
|
|
3225
|
-
expect(parseInstantString('2026-06-15T09:00:00.000Z')).to.equal(Date.UTC(2026, 5, 15, 9, 0, 0, 0));
|
|
3226
|
-
expect(parseInstantString('2026-06-15T14:30:00.000+05:30')).to.equal(Date.UTC(2026, 5, 15, 9, 0, 0, 0));
|
|
3227
|
-
expect(parseInstantString('2026-06-15T14:30:00.000')).to.equal(null);
|
|
3228
|
-
const b = parseBracketed('2026-06-15T14:30:00.000[GMT+05:30 Asia/Kolkata]');
|
|
3229
|
-
expect(b.zone).to.equal('Asia/Kolkata');
|
|
3230
|
-
expect(b.offsetMs).to.equal(5.5 * 3600000);
|
|
3231
|
-
const o = parseOffsetLess('2026-06-15T14:30:00.250');
|
|
3232
|
-
expect(o.ms, 'fractional read as written').to.equal(250);
|
|
3233
|
-
});
|
|
3234
|
-
});
|
|
3235
|
-
describe('PHASE 1 — driver smoke test (real component, real Apply)', () => {
|
|
3236
|
-
it('P1.7 a Z value applies and yields a self-consistent payload', async () => {
|
|
3237
|
-
const el = await makePicker({ value: '2026-06-15T09:00:00.000Z', timezone: 'Asia/Kolkata' });
|
|
3238
|
-
const p = await apply(el);
|
|
3239
|
-
// eslint-disable-next-line no-console
|
|
3240
|
-
console.warn(`[audit-drive] payload=${JSON.stringify({
|
|
3241
|
-
value: p.value, unixEpoch: p.unixEpoch, timezone: p.timezone,
|
|
3242
|
-
})}`);
|
|
3243
|
-
expect(p, 'Apply emitted a payload').to.exist;
|
|
3244
|
-
expect(p.unixEpoch, 'instant preserved').to.equal(Date.UTC(2026, 5, 15, 9, 0, 0, 0));
|
|
3245
|
-
expect(checkPayload(p, 'Asia/Kolkata'), 'invariant violations').to.deep.equal([]);
|
|
3246
|
-
});
|
|
3247
|
-
});
|
|
3248
|
-
/* ==========================================================================
|
|
3249
|
-
PART 4 — PHASE 2: year range and calendar arithmetic
|
|
3250
|
-
(was p2-years.test.ts)
|
|
3251
|
-
========================================================================== */
|
|
3252
|
-
/** An offset a real tzdb zone could have: |offset| <= 26h, whole minutes. */
|
|
3253
|
-
function offsetIsSane(offsetMs) {
|
|
3254
|
-
return Number.isFinite(offsetMs) && Math.abs(offsetMs) <= 26 * 3600000 && offsetMs % 60000 === 0;
|
|
3255
|
-
}
|
|
3256
|
-
const RE_BRACKET = /\[GMT([+-])(\d+):(\d{2})\s+([^\]]+)\]$/;
|
|
3257
|
-
function printedOffsetMs(value) {
|
|
3258
|
-
const m = RE_BRACKET.exec(value);
|
|
3259
|
-
if (!m)
|
|
3260
|
-
return null;
|
|
3261
|
-
return (m[1] === '-' ? -1 : 1) * (Number(m[2]) * 3600000 + Number(m[3]) * 60000);
|
|
3262
|
-
}
|
|
3263
|
-
describe('PHASE 2 — year range and calendar arithmetic', () => {
|
|
3264
|
-
it('P2.0 finds the lowest year whose emitted offset is still sane (UTC)', async () => {
|
|
3265
|
-
const rows = [];
|
|
3266
|
-
let firstBad = null;
|
|
3267
|
-
for (const y of [1, 50, 100, 200, 500, 1000, 1500, 1600, 1700, 1800, 1850,
|
|
3268
|
-
1875, 1880, 1890, 1900, 1901, 1910, 1950, 2000, 2026, 2100]) {
|
|
3269
|
-
const el = await makePicker({});
|
|
3270
|
-
const w = { year: y, month: 6, day: 15, hours: 12, minutes: 0, seconds: 0, ms: 0 };
|
|
3271
|
-
const p = await selectAndApply(el, w, 'UTC');
|
|
3272
|
-
const off = p && p.value ? printedOffsetMs(p.value) : null;
|
|
3273
|
-
const sane = off !== null && offsetIsSane(off);
|
|
3274
|
-
if (!sane && firstBad === null)
|
|
3275
|
-
firstBad = y;
|
|
3276
|
-
rows.push(`year=${String(y).padStart(4)} sane=${sane ? 'YES' : 'NO '} ` +
|
|
3277
|
-
`printedOffset=${off === null ? 'unparsable' : off / 3600000 + 'h'} ` +
|
|
3278
|
-
`epoch=${p && p.unixEpoch} value=${p && p.value}`);
|
|
3279
|
-
}
|
|
3280
|
-
// eslint-disable-next-line no-console
|
|
3281
|
-
console.warn(`[audit-p2] host=${HOST_TZ} emitted-offset sanity by year:\n ${rows.join('\n ')}`);
|
|
3282
|
-
expect(rows.length).to.be.greaterThan(0);
|
|
3283
|
-
}).timeout(600000);
|
|
3284
|
-
it('P2.1 1900-2100 (every year, mid-month) emits sane offsets and round-trips', async () => {
|
|
3285
|
-
const f = new Failures();
|
|
3286
|
-
let n = 0;
|
|
3287
|
-
const subMinute = [];
|
|
3288
|
-
for (let y = 1900; y <= 2100; y++) {
|
|
3289
|
-
for (const z of ['UTC', 'Asia/Kolkata', 'America/New_York']) {
|
|
3290
|
-
const w = { year: y, month: 6, day: 15, hours: 12, minutes: 30, seconds: 15, ms: 250 };
|
|
3291
|
-
const insts = instantsFor(w, z);
|
|
3292
|
-
if (insts.length !== 1)
|
|
3293
|
-
continue;
|
|
3294
|
-
// The bracket is `[GMT±hh:mm]`: it cannot carry a historical sub-minute (LMT) offset, so a value in such
|
|
3295
|
-
// an era is rounded by design (see FA.1). Skip only those, and pin below that they are all pre-1972.
|
|
3296
|
-
if (offsetAt(insts[0], z) % 60000 !== 0) {
|
|
3297
|
-
subMinute.push({ y, z });
|
|
3298
|
-
continue;
|
|
3299
|
-
}
|
|
3300
|
-
const el = await makePicker({});
|
|
3301
|
-
const p = await selectAndApply(el, w, z);
|
|
3302
|
-
const ctx = `year=${y} tz=${z}`;
|
|
3303
|
-
f.add(ctx, checkPayload(p, z));
|
|
3304
|
-
if (p && p.value) {
|
|
3305
|
-
const off = printedOffsetMs(p.value);
|
|
3306
|
-
if (off === null || !offsetIsSane(off)) {
|
|
3307
|
-
f.add(ctx, [{ code: 'P2_INSANE_OFFSET', detail: `value=${p.value}` }]);
|
|
3308
|
-
}
|
|
3309
|
-
}
|
|
3310
|
-
if (p && p.unixEpoch !== null)
|
|
3311
|
-
f.add(ctx, (await roundTrip(p)).violations);
|
|
3312
|
-
n += 1;
|
|
3313
|
-
}
|
|
3314
|
-
}
|
|
3315
|
-
// eslint-disable-next-line no-console
|
|
3316
|
-
console.warn(`[audit-p2] 1900-2100 probes=${n} skipped(sub-minute offset)=${subMinute.length} violations=${f.count}`);
|
|
3317
|
-
expect(f.count, `year-range violations:${f.report()}`).to.equal(0);
|
|
3318
|
-
expect(subMinute.every((x) => x.y < 1972), 'only pre-1972 LMT-era instants are exempt').to.be.true;
|
|
3319
|
-
expect(n, 'the sweep still covers (nearly) every modern year').to.be.greaterThan(500);
|
|
3320
|
-
}).timeout(2400000);
|
|
3321
|
-
it('P2.2 month lengths, leap rules, 1900/2000/2100, Jan<->Dec edges', async () => {
|
|
3322
|
-
const f = new Failures();
|
|
3323
|
-
const cases = [
|
|
3324
|
-
[2024, 2, 29, 'leap 2024 valid'], [2000, 2, 29, 'century leap 2000 valid'],
|
|
3325
|
-
[2026, 1, 31, '31-day'], [2026, 4, 30, '30-day'], [2026, 2, 28, '28-day'],
|
|
3326
|
-
[2026, 12, 31, 'Dec 31'], [2026, 1, 1, 'Jan 1'],
|
|
3327
|
-
[1900, 3, 1, '1900 non-leap: Mar 1'], [2100, 3, 1, '2100 non-leap: Mar 1'],
|
|
3328
|
-
];
|
|
3329
|
-
for (const [y, mo, d, label] of cases) {
|
|
3330
|
-
for (const z of ['UTC', 'Asia/Kolkata']) {
|
|
3331
|
-
const w = { year: y, month: mo, day: d, hours: 10, minutes: 0, seconds: 0, ms: 0 };
|
|
3332
|
-
const insts = instantsFor(w, z);
|
|
3333
|
-
if (insts.length !== 1)
|
|
3334
|
-
continue;
|
|
3335
|
-
// 1900 Asia/Kolkata is +05:21:10 (LMT): not representable in `[GMT±hh:mm]` (rounded by design, see FA.1).
|
|
3336
|
-
// UTC covers the 1900 non-leap case; the Kolkata 1900 row is exempt only for that sub-minute reason.
|
|
3337
|
-
if (offsetAt(insts[0], z) % 60000 !== 0) {
|
|
3338
|
-
expect(y, 'exempt only for LMT-era years').to.be.lessThan(1972);
|
|
3339
|
-
continue;
|
|
3340
|
-
}
|
|
3341
|
-
const el = await makePicker({});
|
|
3342
|
-
const p = await selectAndApply(el, w, z);
|
|
3343
|
-
const ctx = `${label} tz=${z} ${fmtWall(w)}`;
|
|
3344
|
-
f.add(ctx, checkPayload(p, z));
|
|
3345
|
-
if (p && p.unixEpoch !== null) {
|
|
3346
|
-
const back = wallAt(p.unixEpoch, z);
|
|
3347
|
-
if (back.year !== y || back.month !== mo || back.day !== d) {
|
|
3348
|
-
f.add(ctx, [{ code: 'P2_DATE_CHANGED', detail: `got ${back.year}-${back.month}-${back.day}` }]);
|
|
3349
|
-
}
|
|
3350
|
-
}
|
|
3351
|
-
}
|
|
3352
|
-
}
|
|
3353
|
-
expect(f.count, `calendar violations:${f.report()}`).to.equal(0);
|
|
3354
|
-
}).timeout(600000);
|
|
3355
|
-
it('P2.3 classifies impossible dates supplied as a value (REJECT/CLAMP/NORMALIZE)', async () => {
|
|
3356
|
-
const notes = [];
|
|
3357
|
-
for (const raw of ['2026-02-31T10:00:00.000', '2026-02-30', '2025-02-29T10:00:00.000',
|
|
3358
|
-
'2026-04-31T10:00:00.000', '2026-00-10T10:00:00.000', '2026-06-00T10:00:00.000']) {
|
|
3359
|
-
const el = await makePicker({ value: raw, timezone: 'UTC' });
|
|
3360
|
-
const p = await apply(el);
|
|
3361
|
-
let cls = 'REJECT(no payload)';
|
|
3362
|
-
if (p && p.unixEpoch !== null) {
|
|
3363
|
-
const w = wallAt(p.unixEpoch, 'UTC');
|
|
3364
|
-
const askedDay = Number(raw.slice(8, 10));
|
|
3365
|
-
cls = w.day === askedDay ? 'PRESERVE' : `CLAMP/NORMALIZE -> day ${w.day}`;
|
|
3366
|
-
}
|
|
3367
|
-
else if (p)
|
|
3368
|
-
cls = 'REJECT(null epoch)';
|
|
3369
|
-
notes.push(`${raw.padEnd(26)} ${cls.padEnd(28)} value=${p && p.value}`);
|
|
3370
|
-
}
|
|
3371
|
-
// eslint-disable-next-line no-console
|
|
3372
|
-
console.warn(`[audit-p2] impossible-date classification:\n ${notes.join('\n ')}`);
|
|
3373
|
-
expect(notes.length).to.equal(6);
|
|
3374
|
-
}).timeout(300000);
|
|
3375
|
-
});
|
|
3376
|
-
/* ==========================================================================
|
|
3377
|
-
PART 4b — focused: sub-minute offsets and extreme years
|
|
3378
|
-
(was p2b-suboffset.test.ts)
|
|
3379
|
-
========================================================================== */
|
|
3380
|
-
describe('FOCUS A — sub-minute zone offsets', () => {
|
|
3381
|
-
it('FA.0 measures how many zones have sub-minute offsets, and until when', () => {
|
|
3382
|
-
const zones = runtimeZones();
|
|
3383
|
-
const offenders = [];
|
|
3384
|
-
let latestSubMinute = -Infinity;
|
|
3385
|
-
for (const z of zones) {
|
|
3386
|
-
// probe one instant per decade 1880..2100
|
|
3387
|
-
for (let y = 1880; y <= 2100; y += 10) {
|
|
3388
|
-
const t = Date.UTC(y, 5, 15, 12, 0, 0);
|
|
3389
|
-
const off = offsetAt(t, z);
|
|
3390
|
-
if (off % 60000 !== 0) {
|
|
3391
|
-
if (offenders.indexOf(z) === -1)
|
|
3392
|
-
offenders.push(z);
|
|
3393
|
-
if (t > latestSubMinute)
|
|
3394
|
-
latestSubMinute = t;
|
|
3395
|
-
}
|
|
3396
|
-
}
|
|
3397
|
-
}
|
|
3398
|
-
// eslint-disable-next-line no-console
|
|
3399
|
-
console.warn(`[audit-focusA] zonesWithSubMinuteOffset=${offenders.length}/${zones.length} ` +
|
|
3400
|
-
`latestSubMinuteInstant=${latestSubMinute === -Infinity ? 'none' : new Date(latestSubMinute).toISOString()} ` +
|
|
3401
|
-
`sample=${offenders.slice(0, 15).join(',')}`);
|
|
3402
|
-
expect(zones.length).to.be.greaterThan(0);
|
|
3403
|
-
}).timeout(600000);
|
|
3404
|
-
it('FA.1 REPRODUCTION: Asia/Kolkata 1900-06-15 12:30:15.250 — value != its own epoch', async () => {
|
|
3405
|
-
const z = 'Asia/Kolkata';
|
|
3406
|
-
const w = { year: 1900, month: 6, day: 15, hours: 12, minutes: 30, seconds: 15, ms: 250 };
|
|
3407
|
-
const el = await makePicker({});
|
|
3408
|
-
const p = await selectAndApply(el, w, z);
|
|
3409
|
-
expect(p, 'payload').to.exist;
|
|
3410
|
-
const epoch = p.unixEpoch;
|
|
3411
|
-
const trueOff = offsetAt(epoch, z);
|
|
3412
|
-
const viol = checkPayload(p, z);
|
|
3413
|
-
// parse the printed bracket independently
|
|
3414
|
-
const m = /\[GMT([+-])(\d{2}):(\d{2})\s+([^\]]+)\]$/.exec(p.value);
|
|
3415
|
-
const printed = (m[1] === '-' ? -1 : 1) * (Number(m[2]) * 3600000 + Number(m[3]) * 60000);
|
|
3416
|
-
const digits = p.value.slice(0, 23);
|
|
3417
|
-
const fromValue = Date.parse(digits + 'Z') - printed;
|
|
3418
|
-
// does a RELOAD still land on the same epoch?
|
|
3419
|
-
const rt = await roundTrip(p);
|
|
3420
|
-
// eslint-disable-next-line no-console
|
|
3421
|
-
console.warn(`[audit-focusA] REPRO host=${HOST_TZ} tz=${z}\n` +
|
|
3422
|
-
` selected = ${fmtWall(w)}\n` +
|
|
3423
|
-
` unixEpoch = ${epoch}\n` +
|
|
3424
|
-
` true offset = ${trueOff}ms (${trueOff / 60000} min, i.e. ${trueOff / 1000}s)\n` +
|
|
3425
|
-
` printed offset= ${printed}ms (${printed / 60000} min)\n` +
|
|
3426
|
-
` offset lost = ${trueOff - printed}ms\n` +
|
|
3427
|
-
` emitted value = ${p.value}\n` +
|
|
3428
|
-
` value resolves to ${fromValue} (delta vs epoch = ${fromValue - epoch}ms)\n` +
|
|
3429
|
-
` reload epoch = ${rt.second && rt.second.unixEpoch} ` +
|
|
3430
|
-
`(${rt.second && rt.second.unixEpoch === epoch ? 'PRESERVED' : 'DRIFTED'})\n` +
|
|
3431
|
-
` violations = ${viol.map(v => v.code).join(',') || 'none'}`);
|
|
3432
|
-
expect(trueOff % 60000, 'this zone/date genuinely has a sub-minute offset').to.not.equal(0);
|
|
3433
|
-
expect(fromValue - epoch, 'the emitted value does NOT describe its own epoch').to.not.equal(0);
|
|
3434
|
-
}).timeout(300000);
|
|
3435
|
-
// Start at 1972: Africa/Monrovia genuinely used -00:44:30 until 1972-01-07, so 1970-71 is not 'modern' (tzdata history).
|
|
3436
|
-
it('FA.2 modern era (1972-2100) has NO sub-minute offsets in any zone', () => {
|
|
3437
|
-
const zones = runtimeZones();
|
|
3438
|
-
const bad = [];
|
|
3439
|
-
for (const z of zones) {
|
|
3440
|
-
for (let y = 1972; y <= 2100; y += 5) {
|
|
3441
|
-
for (const mo of [0, 6]) {
|
|
3442
|
-
const off = offsetAt(Date.UTC(y, mo, 15, 12), z);
|
|
3443
|
-
if (off % 60000 !== 0)
|
|
3444
|
-
bad.push(`${z}@${y}-${mo + 1}`);
|
|
3445
|
-
}
|
|
3446
|
-
}
|
|
3447
|
-
}
|
|
3448
|
-
// eslint-disable-next-line no-console
|
|
3449
|
-
console.warn(`[audit-focusA] modern-era sub-minute offsets=${bad.length} ${bad.slice(0, 10).join(',')}`);
|
|
3450
|
-
expect(bad, 'no modern zone has a sub-minute offset').to.deep.equal([]);
|
|
3451
|
-
}).timeout(600000);
|
|
3452
|
-
});
|
|
3453
|
-
describe('FOCUS B — extreme years through the Z-instant path', () => {
|
|
3454
|
-
it('FB.1 records emitted offset sanity for extreme years (no harness Date() involved)', async () => {
|
|
3455
|
-
const rows = [];
|
|
3456
|
-
for (const raw of [
|
|
3457
|
-
'0001-01-01T00:00:00.000Z', '0100-06-15T12:00:00.000Z', '1000-06-15T12:00:00.000Z',
|
|
3458
|
-
'1700-06-15T12:00:00.000Z', '1900-06-15T12:00:00.000Z', '2026-06-15T12:00:00.000Z',
|
|
3459
|
-
'2100-06-15T12:00:00.000Z', '9999-12-31T23:59:59.999Z',
|
|
3460
|
-
]) {
|
|
3461
|
-
const el = await makePicker({ value: raw, timezone: 'UTC' });
|
|
3462
|
-
const p = await apply(el);
|
|
3463
|
-
const m = p && p.value ? /\[GMT([+-])(\d+):(\d{2})/.exec(p.value) : null;
|
|
3464
|
-
const hours = m ? Number(m[2]) : NaN;
|
|
3465
|
-
rows.push(`${raw} -> epoch=${p && p.unixEpoch} offsetHours=${m ? (m[1] + String(hours)) : 'n/a'} ` +
|
|
3466
|
-
`${Number.isFinite(hours) && hours > 26 ? '<<< INSANE' : ''} value=${p && p.value}`);
|
|
3467
|
-
}
|
|
3468
|
-
// eslint-disable-next-line no-console
|
|
3469
|
-
console.warn(`[audit-focusB] extreme-year Z inputs:\n ${rows.join('\n ')}`);
|
|
3470
|
-
expect(rows.length).to.equal(8);
|
|
3471
|
-
}).timeout(300000);
|
|
3472
|
-
it('FB.2 records the component date-only path for 2-digit-looking years', async () => {
|
|
3473
|
-
const rows = [];
|
|
3474
|
-
for (const raw of ['0050-06-15', '0099-06-15', '0100-06-15', '1950-06-15']) {
|
|
3475
|
-
const el = await makePicker({ value: raw, timezone: 'UTC' });
|
|
3476
|
-
const p = await apply(el);
|
|
3477
|
-
const w = p && p.unixEpoch !== null ? wallAt(p.unixEpoch, 'UTC') : null;
|
|
3478
|
-
rows.push(`${raw} -> epoch=${p && p.unixEpoch} readsBackAsYear=${w && w.year} value=${p && p.value}`);
|
|
3479
|
-
}
|
|
3480
|
-
// eslint-disable-next-line no-console
|
|
3481
|
-
console.warn(`[audit-focusB] date-only low years (component path):\n ${rows.join('\n ')}`);
|
|
3482
|
-
expect(rows.length).to.equal(4);
|
|
3483
|
-
}).timeout(300000);
|
|
3484
|
-
});
|
|
3485
|
-
/* ==========================================================================
|
|
3486
|
-
PART 5 — PHASE 3: timezone sweep
|
|
3487
|
-
(was p3-zones.test.ts)
|
|
3488
|
-
========================================================================== */
|
|
3489
|
-
const NAMED = [
|
|
3490
|
-
'UTC', 'Asia/Kolkata', 'Asia/Calcutta', 'Asia/Kathmandu', 'Australia/Eucla',
|
|
3491
|
-
'Australia/Lord_Howe', 'America/St_Johns', 'America/New_York', 'Europe/London',
|
|
3492
|
-
'Pacific/Auckland', 'Pacific/Kiritimati', 'Pacific/Marquesas',
|
|
3493
|
-
];
|
|
3494
|
-
// Representative wall clocks across the year, with awkward ms/seconds.
|
|
3495
|
-
const PROBES = [
|
|
3496
|
-
{ year: 2026, month: 1, day: 15, hours: 9, minutes: 30, seconds: 0, ms: 0 },
|
|
3497
|
-
{ year: 2026, month: 7, day: 15, hours: 14, minutes: 45, seconds: 7, ms: 123 },
|
|
3498
|
-
{ year: 2026, month: 10, day: 31, hours: 23, minutes: 59, seconds: 59, ms: 999 },
|
|
3499
|
-
];
|
|
3500
|
-
async function probeZone(zone, w, f) {
|
|
3501
|
-
const el = await makePicker({});
|
|
3502
|
-
const p = await selectAndApply(el, w, zone);
|
|
3503
|
-
const ctx = `tz=${zone} want=${fmtWall(w)} host=${HOST_TZ}`;
|
|
3504
|
-
f.add(ctx, checkPayload(p, zone));
|
|
3505
|
-
if (!p || p.unixEpoch === null) {
|
|
3506
|
-
f.add(ctx, [{ code: 'NO_EPOCH', detail: 'apply produced none' }]);
|
|
3507
|
-
return;
|
|
3508
|
-
}
|
|
3509
|
-
const rt = await roundTrip(p);
|
|
3510
|
-
f.add(`${ctx} value=${p.value}`, rt.violations);
|
|
3511
|
-
}
|
|
3512
|
-
describe('PHASE 3 — timezone sweep', () => {
|
|
3513
|
-
it('P3.0 records both zone sources and their divergence (diagnostic, no spelling assumed)', () => {
|
|
3514
|
-
const runtime = runtimeZones();
|
|
3515
|
-
const onlyRuntime = runtime.filter(z => TIMEZONES.indexOf(z) === -1);
|
|
3516
|
-
const onlyStatic = TIMEZONES.filter(z => runtime.indexOf(z) === -1);
|
|
3517
|
-
const unresolvableStatic = TIMEZONES.filter(z => !isResolvable(z));
|
|
3518
|
-
// eslint-disable-next-line no-console
|
|
3519
|
-
console.warn(`[audit-p3] host=${HOST_TZ} runtimeZones=${runtime.length} staticList=${TIMEZONES.length} ` +
|
|
3520
|
-
`onlyRuntime=${onlyRuntime.length} onlyStatic=${onlyStatic.length} ` +
|
|
3521
|
-
`staticUnresolvableByIntl=${unresolvableStatic.length} ` +
|
|
3522
|
-
`india(runtime)=${runtime.filter(z => /Kolkata|Calcutta/.test(z)).join('|')} ` +
|
|
3523
|
-
`india(static)=${TIMEZONES.filter(z => /Kolkata|Calcutta/.test(z)).join('|')}`);
|
|
3524
|
-
expect(runtime.length, 'runtime exposes a zone list').to.be.greaterThan(100);
|
|
3525
|
-
// Any static-list entry Intl cannot resolve would be offered by the legacy
|
|
3526
|
-
// fallback dropdown yet rejected by isValidTimezone — record it explicitly.
|
|
3527
|
-
expect(unresolvableStatic, 'static fallback entries Intl rejects').to.deep.equal([]);
|
|
3528
|
-
});
|
|
3529
|
-
it('P3.1 explicitly named zones round-trip with no invariant violation', async () => {
|
|
3530
|
-
const f = new Failures();
|
|
3531
|
-
for (const z of NAMED)
|
|
3532
|
-
for (const w of PROBES)
|
|
3533
|
-
await probeZone(z, w, f);
|
|
3534
|
-
expect(f.count, `named-zone violations:${f.report()}`).to.equal(0);
|
|
3535
|
-
}).timeout(180000);
|
|
3536
|
-
it('P3.2 EVERY runtime zone round-trips (one probe each)', async () => {
|
|
3537
|
-
const f = new Failures();
|
|
3538
|
-
const zones = runtimeZones();
|
|
3539
|
-
let n = 0;
|
|
3540
|
-
for (const z of zones) {
|
|
3541
|
-
await probeZone(z, PROBES[1], f);
|
|
3542
|
-
n += 1;
|
|
3543
|
-
}
|
|
3544
|
-
// eslint-disable-next-line no-console
|
|
3545
|
-
console.warn(`[audit-p3] swept ${n} zones, violations=${f.count}`);
|
|
3546
|
-
expect(f.count, `all-zone violations:${f.report()}`).to.equal(0);
|
|
3547
|
-
}).timeout(900000);
|
|
3548
|
-
it('P3.3 a valid alias is never silently downgraded to UTC', async () => {
|
|
3549
|
-
const f = new Failures();
|
|
3550
|
-
const aliases = [
|
|
3551
|
-
['Asia/Calcutta', 'Asia/Kolkata'], ['Asia/Saigon', 'Asia/Ho_Chi_Minh'],
|
|
3552
|
-
['Europe/Kiev', 'Europe/Kyiv'], ['America/Godthab', 'America/Nuuk'],
|
|
3553
|
-
['Asia/Rangoon', 'Asia/Yangon'], ['Pacific/Ponape', 'Pacific/Pohnpei'],
|
|
3554
|
-
];
|
|
3555
|
-
for (const [alias, canonical] of aliases) {
|
|
3556
|
-
let resolvable = true;
|
|
3557
|
-
try {
|
|
3558
|
-
new Intl.DateTimeFormat('en-US', { timeZone: alias });
|
|
3559
|
-
}
|
|
3560
|
-
catch {
|
|
3561
|
-
resolvable = false;
|
|
3562
|
-
}
|
|
3563
|
-
if (!resolvable)
|
|
3564
|
-
continue;
|
|
3565
|
-
const w = PROBES[1];
|
|
3566
|
-
const el = await makePicker({});
|
|
3567
|
-
const p = await selectAndApply(el, w, alias);
|
|
3568
|
-
const ctx = `alias=${alias} canonical=${canonical}`;
|
|
3569
|
-
f.add(ctx, checkPayload(p));
|
|
3570
|
-
if (p && p.unixEpoch !== null) {
|
|
3571
|
-
// the epoch must match the canonical zone's resolution, never UTC's
|
|
3572
|
-
const el2 = await makePicker({});
|
|
3573
|
-
const pc = await selectAndApply(el2, w, canonical);
|
|
3574
|
-
if (pc && pc.unixEpoch !== p.unixEpoch) {
|
|
3575
|
-
f.add(ctx, [{ code: 'ALIAS_EPOCH_DIVERGES', detail: `alias=${p.unixEpoch} canonical=${pc.unixEpoch}` }]);
|
|
3576
|
-
}
|
|
3577
|
-
if (offsetAt(p.unixEpoch, alias) === 0 && offsetAt(p.unixEpoch, canonical) !== 0) {
|
|
3578
|
-
f.add(ctx, [{ code: 'ALIAS_DOWNGRADED_TO_UTC', detail: `value=${p.value}` }]);
|
|
3579
|
-
}
|
|
3580
|
-
}
|
|
3581
|
-
}
|
|
3582
|
-
expect(f.count, `alias violations:${f.report()}`).to.equal(0);
|
|
3583
|
-
}).timeout(180000);
|
|
3584
|
-
it('P3.5 EVERY static-fallback zone round-trips (legacy dropdown path)', async () => {
|
|
3585
|
-
const f = new Failures();
|
|
3586
|
-
let n = 0;
|
|
3587
|
-
for (const z of TIMEZONES) {
|
|
3588
|
-
if (!isResolvable(z))
|
|
3589
|
-
continue;
|
|
3590
|
-
await probeZone(z, PROBES[1], f);
|
|
3591
|
-
n += 1;
|
|
3592
|
-
}
|
|
3593
|
-
// eslint-disable-next-line no-console
|
|
3594
|
-
console.warn(`[audit-p3] swept ${n} static-fallback zones, violations=${f.count}`);
|
|
3595
|
-
expect(f.count, `static-list violations:${f.report()}`).to.equal(0);
|
|
3596
|
-
}).timeout(900000);
|
|
3597
|
-
it('P3.4 sub-hour zones (:30 / :45 / :15) keep exact offsets', async () => {
|
|
3598
|
-
const f = new Failures();
|
|
3599
|
-
for (const z of ['Asia/Kolkata', 'Asia/Kathmandu', 'Australia/Eucla',
|
|
3600
|
-
'America/St_Johns', 'Pacific/Chatham', 'Pacific/Marquesas', 'Australia/Lord_Howe']) {
|
|
3601
|
-
for (const w of PROBES) {
|
|
3602
|
-
const el = await makePicker({});
|
|
3603
|
-
const p = await selectAndApply(el, w, z);
|
|
3604
|
-
const ctx = `subhour tz=${z} want=${fmtWall(w)}`;
|
|
3605
|
-
f.add(ctx, checkPayload(p, z));
|
|
3606
|
-
if (p && p.unixEpoch !== null) {
|
|
3607
|
-
const off = offsetAt(p.unixEpoch, z);
|
|
3608
|
-
if (off % 3600000 === 0 && ['Asia/Kolkata', 'Asia/Kathmandu'].indexOf(z) !== -1) {
|
|
3609
|
-
f.add(ctx, [{ code: 'SUBHOUR_LOST', detail: `offset became whole hours: ${off}` }]);
|
|
3610
|
-
}
|
|
3611
|
-
const rt = await roundTrip(p);
|
|
3612
|
-
f.add(ctx, rt.violations);
|
|
3613
|
-
}
|
|
3614
|
-
}
|
|
3615
|
-
}
|
|
3616
|
-
expect(f.count, `sub-hour violations:${f.report()}`).to.equal(0);
|
|
3617
|
-
}).timeout(300000);
|
|
3618
|
-
});
|
|
3619
|
-
/* ==========================================================================
|
|
3620
|
-
PART 6 — PHASE 4/5: DST transitions, gaps, overlaps
|
|
3621
|
-
(was p4-dst.test.ts)
|
|
3622
|
-
========================================================================== */
|
|
3623
|
-
const YEAR_FROM = Date.UTC(2026, 0, 1);
|
|
3624
|
-
const YEAR_TO = Date.UTC(2027, 0, 1);
|
|
3625
|
-
function allTransitions(zones) {
|
|
3626
|
-
const out = [];
|
|
3627
|
-
for (const z of zones) {
|
|
3628
|
-
for (const t of findTransitions(z, YEAR_FROM, YEAR_TO))
|
|
3629
|
-
out.push({ zone: z, t });
|
|
3630
|
-
}
|
|
3631
|
-
return out;
|
|
3632
|
-
}
|
|
3633
|
-
describe('PHASE 4 — every DST transition, found programmatically', () => {
|
|
3634
|
-
let transitions = [];
|
|
3635
|
-
let zonesWithDst = [];
|
|
3636
|
-
it('P4.0 discovers transitions across every runtime zone (2026)', () => {
|
|
3637
|
-
const zones = runtimeZones();
|
|
3638
|
-
transitions = allTransitions(zones);
|
|
3639
|
-
zonesWithDst = Array.from(new Set(transitions.map(t => t.zone)));
|
|
3640
|
-
const fwd = transitions.filter(x => transitionShape(x.t, x.zone).kind === 'forward').length;
|
|
3641
|
-
// eslint-disable-next-line no-console
|
|
3642
|
-
console.warn(`[audit-p4] host=${HOST_TZ} zonesScanned=${zones.length} ` +
|
|
3643
|
-
`zonesWithTransitions=${zonesWithDst.length} transitions=${transitions.length} ` +
|
|
3644
|
-
`forward=${fwd} backward=${transitions.length - fwd}`);
|
|
3645
|
-
expect(transitions.length, 'must find real transitions').to.be.greaterThan(50);
|
|
3646
|
-
}).timeout(300000);
|
|
3647
|
-
it('P4.1 times around EVERY transition stay self-consistent and round-trip', async () => {
|
|
3648
|
-
const f = new Failures();
|
|
3649
|
-
let probes = 0;
|
|
3650
|
-
for (const { zone, t } of transitions) {
|
|
3651
|
-
// instants around the transition -> the zone's own wall clock -> select
|
|
3652
|
-
for (const dt of [-2 * 3600000, -60000, 0, 60000, 2 * 3600000]) {
|
|
3653
|
-
const inst = t + dt;
|
|
3654
|
-
const w = wallAt(inst, zone);
|
|
3655
|
-
// skip if these digits are ambiguous — covered deliberately in PHASE 5
|
|
3656
|
-
if (instantsFor(w, zone).length !== 1)
|
|
3657
|
-
continue;
|
|
3658
|
-
const el = await makePicker({});
|
|
3659
|
-
const p = await selectAndApply(el, w, zone);
|
|
3660
|
-
const ctx = `tz=${zone} t=${t} dt=${dt / 1000}s want=${fmtWall(w)}`;
|
|
3661
|
-
f.add(ctx, checkPayload(p, zone));
|
|
3662
|
-
if (p && p.unixEpoch !== null) {
|
|
3663
|
-
if (p.unixEpoch !== inst) {
|
|
3664
|
-
f.add(ctx, [{ code: 'P4_EPOCH_NE_INTENT', detail: `want=${inst} got=${p.unixEpoch} delta=${p.unixEpoch - inst}ms` }]);
|
|
3665
|
-
}
|
|
3666
|
-
f.add(ctx, (await roundTrip(p)).violations);
|
|
3667
|
-
}
|
|
3668
|
-
probes += 1;
|
|
3669
|
-
}
|
|
3670
|
-
}
|
|
3671
|
-
// eslint-disable-next-line no-console
|
|
3672
|
-
console.warn(`[audit-p4] around-transition probes=${probes} violations=${f.count}`);
|
|
3673
|
-
expect(f.count, `transition violations:${f.report()}`).to.equal(0);
|
|
3674
|
-
}).timeout(1800000);
|
|
3675
|
-
it('P4.2 GAP: a nonexistent wall clock still emits a payload describing its own epoch', async () => {
|
|
3676
|
-
const f = new Failures();
|
|
3677
|
-
const notes = [];
|
|
3678
|
-
let n = 0;
|
|
3679
|
-
let before = 0;
|
|
3680
|
-
let after = 0;
|
|
3681
|
-
const afterZones = [];
|
|
3682
|
-
let posButBefore = 0;
|
|
3683
|
-
let negButAfter = 0;
|
|
3684
|
-
for (const { zone, t } of transitions) {
|
|
3685
|
-
const sh = transitionShape(t, zone);
|
|
3686
|
-
if (sh.kind !== 'forward')
|
|
3687
|
-
continue;
|
|
3688
|
-
const w = sh.insideWall;
|
|
3689
|
-
if (instantsFor(w, zone).length !== 0)
|
|
3690
|
-
continue; // must truly be a gap
|
|
3691
|
-
const el = await makePicker({});
|
|
3692
|
-
const p = await selectAndApply(el, w, zone);
|
|
3693
|
-
const ctx = `GAP tz=${zone} want=${fmtWall(w)} delta=${sh.deltaMs / 60000}min`;
|
|
3694
|
-
// THE critical invariant: whatever it resolves to, the payload must be
|
|
3695
|
-
// internally truthful about its own epoch.
|
|
3696
|
-
f.add(ctx, checkPayload(p, zone));
|
|
3697
|
-
if (p && p.unixEpoch !== null) {
|
|
3698
|
-
f.add(ctx, (await roundTrip(p)).violations);
|
|
3699
|
-
if (p.unixEpoch < t) {
|
|
3700
|
-
before += 1;
|
|
3701
|
-
if (sh.offBefore >= 0)
|
|
3702
|
-
posButBefore += 1;
|
|
3703
|
-
}
|
|
3704
|
-
else {
|
|
3705
|
-
after += 1;
|
|
3706
|
-
afterZones.push(zone);
|
|
3707
|
-
if (sh.offBefore < 0)
|
|
3708
|
-
negButAfter += 1;
|
|
3709
|
-
}
|
|
3710
|
-
if (n < 6) {
|
|
3711
|
-
notes.push(`${zone}: ${fmtWall(w)} -> epoch=${p.unixEpoch} value=${p.value} ` +
|
|
3712
|
-
`(lands ${p.unixEpoch < t ? 'BEFORE' : 'AFTER'} the gap)`);
|
|
3713
|
-
}
|
|
3714
|
-
}
|
|
3715
|
-
n += 1;
|
|
3716
|
-
}
|
|
3717
|
-
// eslint-disable-next-line no-console
|
|
3718
|
-
console.warn(`[audit-p4] gap probes=${n} violations=${f.count} ` +
|
|
3719
|
-
`LANDS_BEFORE=${before} LANDS_AFTER=${after} ` +
|
|
3720
|
-
`afterZonesSample=${afterZones.slice(0, 12).join(',')} ` +
|
|
3721
|
-
`SIGN_CORRELATION: positiveOffsetYetBefore=${posButBefore} negativeOffsetYetAfter=${negButAfter} ` +
|
|
3722
|
-
`(0/0 => direction is exactly the sign of the zone offset)` +
|
|
3723
|
-
`\n ${notes.join('\n ')}`);
|
|
3724
|
-
expect(f.count, `gap violations:${f.report()}`).to.equal(0);
|
|
3725
|
-
}).timeout(1800000);
|
|
3726
|
-
});
|
|
3727
|
-
describe('PHASE 5 — DST overlap: both occurrences must be reachable and distinct', () => {
|
|
3728
|
-
it('P5.1 an ambiguous wall clock resolves to a stated occurrence, consistently', async () => {
|
|
3729
|
-
const f = new Failures();
|
|
3730
|
-
const zones = runtimeZones();
|
|
3731
|
-
const trs = allTransitions(zones).filter(x => transitionShape(x.t, x.zone).kind === 'backward');
|
|
3732
|
-
const notes = [];
|
|
3733
|
-
let n = 0;
|
|
3734
|
-
let pickFirst = 0;
|
|
3735
|
-
let pickSecond = 0;
|
|
3736
|
-
const secondZones = [];
|
|
3737
|
-
for (const { zone, t } of trs) {
|
|
3738
|
-
const sh = transitionShape(t, zone);
|
|
3739
|
-
const w = sh.insideWall;
|
|
3740
|
-
const both = instantsFor(w, zone);
|
|
3741
|
-
if (both.length !== 2)
|
|
3742
|
-
continue; // must truly be ambiguous
|
|
3743
|
-
// (a) plain wall-clock selection picks ONE of them, and says so truthfully
|
|
3744
|
-
const el = await makePicker({});
|
|
3745
|
-
const p = await selectAndApply(el, w, zone);
|
|
3746
|
-
const ctx = `OVERLAP tz=${zone} want=${fmtWall(w)}`;
|
|
3747
|
-
f.add(ctx, checkPayload(p, zone));
|
|
3748
|
-
if (p && p.unixEpoch !== null) {
|
|
3749
|
-
if (both.indexOf(p.unixEpoch) === -1) {
|
|
3750
|
-
f.add(ctx, [{
|
|
3751
|
-
code: 'P5_NOT_AN_OCCURRENCE',
|
|
3752
|
-
detail: `epoch=${p.unixEpoch} is neither ${both[0]} nor ${both[1]}`,
|
|
3753
|
-
}]);
|
|
3754
|
-
}
|
|
3755
|
-
f.add(ctx, (await roundTrip(p)).violations);
|
|
3756
|
-
}
|
|
3757
|
-
// (b) the bracketed form with an EXPLICIT offset must select the intended
|
|
3758
|
-
// occurrence — the two must not collapse onto one epoch.
|
|
3759
|
-
const mk = (epoch) => {
|
|
3760
|
-
const ww = wallAt(epoch, zone);
|
|
3761
|
-
const off = offsetAt(epoch, zone);
|
|
3762
|
-
const sign = off < 0 ? '-' : '+';
|
|
3763
|
-
const a = Math.abs(off);
|
|
3764
|
-
const hh = String(Math.floor(a / 3600000)).padStart(2, '0');
|
|
3765
|
-
const mm = String(Math.floor((a % 3600000) / 60000)).padStart(2, '0');
|
|
3766
|
-
return `${fmtWall(ww)}[GMT${sign}${hh}:${mm} ${zone}]`;
|
|
3767
|
-
};
|
|
3768
|
-
const v1 = mk(both[0]);
|
|
3769
|
-
const v2 = mk(both[1]);
|
|
3770
|
-
const e1 = await apply(await makePicker({ value: v1, timezone: zone }));
|
|
3771
|
-
const e2 = await apply(await makePicker({ value: v2, timezone: zone }));
|
|
3772
|
-
f.add(`${ctx} first`, checkPayload(e1));
|
|
3773
|
-
f.add(`${ctx} second`, checkPayload(e2));
|
|
3774
|
-
if (e1 && e2 && e1.unixEpoch !== null && e2.unixEpoch !== null) {
|
|
3775
|
-
if (e1.unixEpoch !== both[0]) {
|
|
3776
|
-
f.add(ctx, [{ code: 'P5_FIRST_OCCURRENCE_LOST', detail: `want=${both[0]} got=${e1.unixEpoch} from ${v1}` }]);
|
|
3777
|
-
}
|
|
3778
|
-
if (e2.unixEpoch !== both[1]) {
|
|
3779
|
-
f.add(ctx, [{ code: 'P5_SECOND_OCCURRENCE_LOST', detail: `want=${both[1]} got=${e2.unixEpoch} from ${v2}` }]);
|
|
3780
|
-
}
|
|
3781
|
-
if (e1.unixEpoch === e2.unixEpoch) {
|
|
3782
|
-
f.add(ctx, [{ code: 'P5_OCCURRENCES_COLLAPSED', detail: `both -> ${e1.unixEpoch}` }]);
|
|
3783
|
-
}
|
|
3784
|
-
}
|
|
3785
|
-
if (p && p.unixEpoch !== null) {
|
|
3786
|
-
if (p.unixEpoch === both[0])
|
|
3787
|
-
pickFirst += 1;
|
|
3788
|
-
else if (p.unixEpoch === both[1]) {
|
|
3789
|
-
pickSecond += 1;
|
|
3790
|
-
secondZones.push(zone);
|
|
3791
|
-
}
|
|
3792
|
-
}
|
|
3793
|
-
if (n < 5 && p) {
|
|
3794
|
-
notes.push(`${zone}: ${fmtWall(w)} occurrences=[${both}] plainSelect=${p.unixEpoch} ` +
|
|
3795
|
-
`(${p.unixEpoch === both[0] ? 'FIRST' : p.unixEpoch === both[1] ? 'SECOND' : 'NEITHER'})`);
|
|
3796
|
-
}
|
|
3797
|
-
n += 1;
|
|
3798
|
-
}
|
|
3799
|
-
// eslint-disable-next-line no-console
|
|
3800
|
-
console.warn(`[audit-p5] overlap probed=${n} violations=${f.count} ` +
|
|
3801
|
-
`PICKS_FIRST=${pickFirst} PICKS_SECOND=${pickSecond} ` +
|
|
3802
|
-
`secondZonesSample=${secondZones.slice(0, 12).join(',')}\n ${notes.join('\n ')}`);
|
|
3803
|
-
expect(n, 'must actually find overlaps to test').to.be.greaterThan(10);
|
|
3804
|
-
expect(f.count, `overlap violations:${f.report()}`).to.equal(0);
|
|
3805
|
-
}).timeout(1800000);
|
|
3806
|
-
});
|
|
3807
|
-
const W = (year, month, day, hours, minutes, seconds, ms) => ({ year, month, day, hours, minutes, seconds, ms });
|
|
3808
|
-
const CASES = [
|
|
3809
|
-
// ── instant-bearing: epoch MUST be identical on every host ──────────────
|
|
3810
|
-
{ label: 'Z-utc', value: '2026-06-15T09:00:00.000Z', tz: 'UTC' },
|
|
3811
|
-
{ label: 'Z-kolkata', value: '2026-06-15T09:00:00.000Z', tz: 'Asia/Kolkata' },
|
|
3812
|
-
{ label: 'Z-ny', value: '2026-06-15T09:00:00.000Z', tz: 'America/New_York' },
|
|
3813
|
-
{ label: 'Z-ms999', value: '2026-06-15T09:00:00.999Z', tz: 'Pacific/Chatham' },
|
|
3814
|
-
{ label: 'off+0530', value: '2026-06-15T14:30:00.000+05:30', tz: 'Asia/Kolkata' },
|
|
3815
|
-
{ label: 'off-0400', value: '2026-06-15T05:00:00.000-04:00', tz: 'America/New_York' },
|
|
3816
|
-
{ label: 'off+1400', value: '2026-06-15T23:00:00.000+14:00', tz: 'Pacific/Kiritimati' },
|
|
3817
|
-
{ label: 'brk-kolkata', value: '2026-06-15T14:30:00.000[GMT+05:30 Asia/Kolkata]', tz: 'Asia/Kolkata' },
|
|
3818
|
-
{ label: 'brk-alias', value: '2026-06-15T14:30:00.000[GMT+05:30 Asia/Calcutta]', tz: 'Asia/Calcutta' },
|
|
3819
|
-
{ label: 'brk-dst-1st', value: '2026-11-01T01:30:00.000[GMT-04:00 America/New_York]', tz: 'America/New_York' },
|
|
3820
|
-
{ label: 'brk-dst-2nd', value: '2026-11-01T01:30:00.000[GMT-05:00 America/New_York]', tz: 'America/New_York' },
|
|
3821
|
-
{ label: 'brk-lordhowe', value: '2026-06-15T14:30:00.000[GMT+10:30 Australia/Lord_Howe]', tz: 'Australia/Lord_Howe' },
|
|
3822
|
-
// ── offset-less + date-only: component-zone semantics, also host-free ────
|
|
3823
|
-
{ label: 'offless-kolkata', value: '2026-06-15T14:30:00.000', tz: 'Asia/Kolkata' },
|
|
3824
|
-
{ label: 'offless-ny', value: '2026-06-15T14:30:00.000', tz: 'America/New_York' },
|
|
3825
|
-
{ label: 'offless-gap-ny', value: '2026-03-08T02:30:00.000', tz: 'America/New_York' },
|
|
3826
|
-
{ label: 'offless-overlap-ny', value: '2026-11-01T01:30:00.000', tz: 'America/New_York' },
|
|
3827
|
-
{ label: 'dateonly-kolkata', value: '2026-06-15', tz: 'Asia/Kolkata' },
|
|
3828
|
-
{ label: 'dateonly-kiritimati', value: '2026-06-15', tz: 'Pacific/Kiritimati' },
|
|
3829
|
-
// ── UI-selected wall clocks in awkward zones ────────────────────────────
|
|
3830
|
-
{ label: 'sel-chatham', wall: W(2026, 9, 27, 3, 30, 0, 0), tz: 'Pacific/Chatham' },
|
|
3831
|
-
{ label: 'sel-lordhowe', wall: W(2026, 4, 5, 1, 30, 0, 0), tz: 'Australia/Lord_Howe' },
|
|
3832
|
-
{ label: 'sel-kathmandu', wall: W(2026, 6, 15, 14, 45, 7, 123), tz: 'Asia/Kathmandu' },
|
|
3833
|
-
{ label: 'sel-stjohns', wall: W(2026, 3, 8, 0, 30, 0, 0), tz: 'America/St_Johns' },
|
|
3834
|
-
{ label: 'sel-eucla', wall: W(2026, 12, 31, 23, 59, 59, 999), tz: 'Australia/Eucla' },
|
|
3835
|
-
{ label: 'sel-marquesas', wall: W(2026, 1, 1, 0, 0, 0, 1), tz: 'Pacific/Marquesas' },
|
|
3836
|
-
];
|
|
3837
|
-
describe('PHASE 6 — host-timezone independence', () => {
|
|
3838
|
-
it('P6.1 emits the cross-host digest and checks payload invariants locally', async () => {
|
|
3839
|
-
const f = new Failures();
|
|
3840
|
-
const lines = [];
|
|
3841
|
-
for (const c of CASES) {
|
|
3842
|
-
let p;
|
|
3843
|
-
if (c.wall) {
|
|
3844
|
-
const el = await makePicker({});
|
|
3845
|
-
p = await selectAndApply(el, c.wall, c.tz);
|
|
3846
|
-
}
|
|
3847
|
-
else {
|
|
3848
|
-
const el = await makePicker({ value: c.value, timezone: c.tz });
|
|
3849
|
-
p = await apply(el);
|
|
3850
|
-
}
|
|
3851
|
-
f.add(`${c.label} host=${HOST_TZ}`, checkPayload(p));
|
|
3852
|
-
lines.push(`P6|${c.label}|${p ? p.unixEpoch : 'NONE'}|${p ? p.timezone : 'NONE'}|${p ? p.value : 'NONE'}`);
|
|
3853
|
-
}
|
|
3854
|
-
// eslint-disable-next-line no-console
|
|
3855
|
-
console.warn(`[audit-p6] host=${HOST_TZ}\n${lines.join('\n')}`);
|
|
3856
|
-
expect(f.count, `host=${HOST_TZ} payload violations:${f.report()}`).to.equal(0);
|
|
3857
|
-
}).timeout(900000);
|
|
3858
|
-
it('P6.2 the oracle itself is host-independent (sanity on the measuring stick)', () => {
|
|
3859
|
-
// If these differed by host, every other comparison would be meaningless.
|
|
3860
|
-
const t = Date.UTC(2026, 5, 15, 9, 0, 0, 0);
|
|
3861
|
-
const probe = [
|
|
3862
|
-
instantsFor(W(2026, 6, 15, 14, 30, 0, 0), 'Asia/Kolkata').join(','),
|
|
3863
|
-
instantsFor(W(2026, 3, 8, 2, 30, 0, 0), 'America/New_York').length,
|
|
3864
|
-
instantsFor(W(2026, 11, 1, 1, 30, 0, 0), 'America/New_York').length,
|
|
3865
|
-
fmtWall(W(2026, 6, 15, 14, 30, 0, 0)),
|
|
3866
|
-
t,
|
|
3867
|
-
].join('|');
|
|
3868
|
-
// eslint-disable-next-line no-console
|
|
3869
|
-
console.warn(`[audit-p6-oracle] host=${HOST_TZ} digest=${probe}`);
|
|
3870
|
-
expect(probe, 'Asia/Kolkata 14:30 == 09:00Z').to.contain('1781514000000');
|
|
3871
|
-
});
|
|
3872
|
-
});
|
|
3873
|
-
/* ==========================================================================
|
|
3874
|
-
PART 7 — PHASE 7/8/9/11/12: ms, boundaries, formats, round-trips, fuzzing
|
|
3875
|
-
(was p7912-formats.test.ts)
|
|
3876
|
-
========================================================================== */
|
|
3877
|
-
const ZONES = ['UTC', 'Asia/Kolkata', 'Asia/Kathmandu', 'America/New_York',
|
|
3878
|
-
'Australia/Lord_Howe', 'Pacific/Chatham', 'Pacific/Kiritimati', 'America/St_Johns'];
|
|
3879
|
-
describe('PHASE 7 — milliseconds and precision', () => {
|
|
3880
|
-
const MS = [0, 1, 9, 10, 99, 100, 250, 500, 999];
|
|
3881
|
-
it('P7.1 every millisecond value survives select -> Apply -> reload -> Apply', async () => {
|
|
3882
|
-
const f = new Failures();
|
|
3883
|
-
for (const z of ZONES) {
|
|
3884
|
-
for (const ms of MS) {
|
|
3885
|
-
const w = { year: 2026, month: 6, day: 15, hours: 14, minutes: 30, seconds: 45, ms };
|
|
3886
|
-
const el = await makePicker({});
|
|
3887
|
-
const p = await selectAndApply(el, w, z);
|
|
3888
|
-
const ctx = `tz=${z} ms=${ms}`;
|
|
3889
|
-
f.add(ctx, checkPayload(p, z));
|
|
3890
|
-
if (p && p.unixEpoch !== null) {
|
|
3891
|
-
if (p.unixEpoch % 1000 !== ms) {
|
|
3892
|
-
f.add(ctx, [{ code: 'P7_MS_LOST', detail: `epoch%1000=${p.unixEpoch % 1000} want=${ms} value=${p.value}` }]);
|
|
3893
|
-
}
|
|
3894
|
-
// ms must NOT contaminate the offset: +05:30 must never become +05:29
|
|
3895
|
-
const off = offsetAt(p.unixEpoch, z);
|
|
3896
|
-
if (off % 60000 !== 0) {
|
|
3897
|
-
f.add(ctx, [{ code: 'P7_OFFSET_NOT_WHOLE_MINUTES', detail: `offset=${off}ms` }]);
|
|
3898
|
-
}
|
|
3899
|
-
const parsed = parseBracketed(p.value);
|
|
3900
|
-
if (parsed && parsed.offsetMs !== off) {
|
|
3901
|
-
f.add(ctx, [{ code: 'P7_OFFSET_CONTAMINATED', detail: `printed=${parsed.offsetMs} true=${off}` }]);
|
|
3902
|
-
}
|
|
3903
|
-
f.add(ctx, (await roundTrip(p)).violations);
|
|
3904
|
-
}
|
|
3905
|
-
}
|
|
3906
|
-
}
|
|
3907
|
-
expect(f.count, `ms violations:${f.report()}`).to.equal(0);
|
|
3908
|
-
}).timeout(600000);
|
|
3909
|
-
it('P7.2 records CURRENT behaviour of 1- and 2-digit fractional seconds', async () => {
|
|
3910
|
-
const notes = [];
|
|
3911
|
-
for (const raw of ['2026-06-15T14:30:00.2', '2026-06-15T14:30:00.25',
|
|
3912
|
-
'2026-06-15T14:30:00.250', '2026-06-15T14:30:00.2Z', '2026-06-15T14:30:00.25Z']) {
|
|
3913
|
-
const el = await makePicker({ value: raw, timezone: 'Asia/Kolkata' });
|
|
3914
|
-
const p = await apply(el);
|
|
3915
|
-
notes.push(`${raw} -> epoch=${p && p.unixEpoch} ms=${p && p.unixEpoch !== null ? p.unixEpoch % 1000 : 'n/a'} value=${p && p.value}`);
|
|
3916
|
-
}
|
|
3917
|
-
// eslint-disable-next-line no-console
|
|
3918
|
-
console.warn(`[audit-p7] fractional-second CURRENT behaviour:\n ${notes.join('\n ')}`);
|
|
3919
|
-
expect(notes.length).to.equal(5);
|
|
3920
|
-
}).timeout(120000);
|
|
3921
|
-
});
|
|
3922
|
-
describe('PHASE 8 — time boundaries, no accidental day rollover', () => {
|
|
3923
|
-
const TIMES = [
|
|
3924
|
-
[0, 0, 0, 0], [0, 0, 0, 1], [11, 59, 59, 999], [12, 0, 0, 0],
|
|
3925
|
-
[23, 59, 59, 998], [23, 59, 59, 999],
|
|
3926
|
-
];
|
|
3927
|
-
const DAYS = [
|
|
3928
|
-
[2026, 6, 15, 'normal'], [2026, 1, 31, 'month-end'], [2026, 12, 31, 'year-end'],
|
|
3929
|
-
[2024, 2, 29, 'leap-day'], [2026, 3, 8, 'US DST day'], [2026, 11, 1, 'US fall-back day'],
|
|
3930
|
-
];
|
|
3931
|
-
it('P8.1 boundary times keep their calendar day (or truthfully report the shift)', async () => {
|
|
3932
|
-
const f = new Failures();
|
|
3933
|
-
for (const z of ['UTC', 'Asia/Kolkata', 'America/New_York', 'Pacific/Kiritimati']) {
|
|
3934
|
-
for (const [y, mo, d, label] of DAYS) {
|
|
3935
|
-
for (const [h, mi, s, ms] of TIMES) {
|
|
3936
|
-
const w = { year: y, month: mo, day: d, hours: h, minutes: mi, seconds: s, ms };
|
|
3937
|
-
const exists = instantsFor(w, z).length > 0;
|
|
3938
|
-
const el = await makePicker({});
|
|
3939
|
-
const p = await selectAndApply(el, w, z);
|
|
3940
|
-
const ctx = `tz=${z} ${label} ${fmtWall(w)}`;
|
|
3941
|
-
f.add(ctx, checkPayload(p, z));
|
|
3942
|
-
if (p && p.unixEpoch !== null && exists) {
|
|
3943
|
-
const back = wallAt(p.unixEpoch, z);
|
|
3944
|
-
if (back.day !== d || back.month !== mo || back.year !== y) {
|
|
3945
|
-
f.add(ctx, [{
|
|
3946
|
-
code: 'P8_DAY_ROLLOVER',
|
|
3947
|
-
detail: `selected ${y}-${mo}-${d} but epoch reads ${back.year}-${back.month}-${back.day} in ${z}`,
|
|
3948
|
-
}]);
|
|
3949
|
-
}
|
|
3950
|
-
if (back.hours !== h || back.minutes !== mi || back.seconds !== s || back.ms !== ms) {
|
|
3951
|
-
f.add(ctx, [{ code: 'P8_TIME_DRIFT', detail: `got ${fmtWall(back)}` }]);
|
|
3952
|
-
}
|
|
3953
|
-
}
|
|
3954
|
-
}
|
|
3955
|
-
}
|
|
3956
|
-
}
|
|
3957
|
-
expect(f.count, `boundary violations:${f.report()}`).to.equal(0);
|
|
3958
|
-
}).timeout(900000);
|
|
3959
|
-
});
|
|
3960
|
-
describe('PHASE 9 — input format matrix', () => {
|
|
3961
|
-
it('P9.1 valid inputs preserve their instant through reload', async () => {
|
|
3962
|
-
const f = new Failures();
|
|
3963
|
-
const rows = [
|
|
3964
|
-
{ label: 'Z', value: '2026-06-15T09:00:00.000Z', tz: 'Asia/Kolkata', validInstant: Date.UTC(2026, 5, 15, 9) },
|
|
3965
|
-
{ label: '+offset', value: '2026-06-15T14:30:00.000+05:30', tz: 'Asia/Kolkata', validInstant: Date.UTC(2026, 5, 15, 9) },
|
|
3966
|
-
{ label: '-offset', value: '2026-06-15T05:00:00.000-04:00', tz: 'America/New_York', validInstant: Date.UTC(2026, 5, 15, 9) },
|
|
3967
|
-
{ label: 'bracketed UTC', value: '2026-06-15T09:00:00.000[GMT+00:00 UTC]', tz: 'UTC' },
|
|
3968
|
-
{ label: 'bracketed +', value: '2026-06-15T14:30:00.000[GMT+05:30 Asia/Kolkata]', tz: 'Asia/Kolkata' },
|
|
3969
|
-
{ label: 'bracketed -', value: '2026-06-15T05:00:00.000[GMT-04:00 America/New_York]', tz: 'America/New_York' },
|
|
3970
|
-
{ label: 'alias', value: '2026-06-15T14:30:00.000[GMT+05:30 Asia/Calcutta]', tz: 'Asia/Calcutta' },
|
|
3971
|
-
{ label: 'offset-less', value: '2026-06-15T14:30:00.000', tz: 'Asia/Kolkata' },
|
|
3972
|
-
{ label: 'date-only', value: '2026-06-15', tz: 'Asia/Kolkata' },
|
|
3973
|
-
{ label: 'DST 1st occ', value: '2026-11-01T01:30:00.000[GMT-04:00 America/New_York]', tz: 'America/New_York' },
|
|
3974
|
-
{ label: 'DST 2nd occ', value: '2026-11-01T01:30:00.000[GMT-05:00 America/New_York]', tz: 'America/New_York' },
|
|
3975
|
-
];
|
|
3976
|
-
const notes = [];
|
|
3977
|
-
for (const r of rows) {
|
|
3978
|
-
const el = await makePicker({ value: r.value, timezone: r.tz });
|
|
3979
|
-
const p = await apply(el);
|
|
3980
|
-
const ctx = `${r.label} value=${r.value}`;
|
|
3981
|
-
f.add(ctx, checkPayload(p));
|
|
3982
|
-
if (r.validInstant !== undefined && p && p.unixEpoch !== r.validInstant) {
|
|
3983
|
-
f.add(ctx, [{ code: 'P9_INSTANT_CHANGED', detail: `want=${r.validInstant} got=${p.unixEpoch}` }]);
|
|
3984
|
-
}
|
|
3985
|
-
if (p && p.unixEpoch !== null)
|
|
3986
|
-
f.add(ctx, (await roundTrip(p)).violations);
|
|
3987
|
-
notes.push(`${r.label.padEnd(14)} -> epoch=${p && p.unixEpoch} tz=${p && p.timezone} value=${p && p.value}`);
|
|
3988
|
-
}
|
|
3989
|
-
// eslint-disable-next-line no-console
|
|
3990
|
-
console.warn(`[audit-p9] valid-input matrix:\n ${notes.join('\n ')}`);
|
|
3991
|
-
expect(f.count, `format-matrix violations:${f.report()}`).to.equal(0);
|
|
3992
|
-
}).timeout(600000);
|
|
3993
|
-
it('P9.2 classifies INVALID / edge inputs (REJECT / FALLBACK / CLAMP / NORMALIZE)', async () => {
|
|
3994
|
-
const rows = [
|
|
3995
|
-
{ label: 'null', value: null, tz: 'Asia/Kolkata' },
|
|
3996
|
-
{ label: 'empty string', value: '', tz: 'Asia/Kolkata' },
|
|
3997
|
-
{ label: 'malformed', value: 'not-a-date', tz: 'Asia/Kolkata' },
|
|
3998
|
-
{ label: 'impossible date', value: '2026-02-31T10:00:00.000', tz: 'Asia/Kolkata' },
|
|
3999
|
-
{ label: 'impossible date-only', value: '2026-02-31', tz: 'Asia/Kolkata' },
|
|
4000
|
-
{ label: 'invalid tz in bracket', value: '2026-06-15T14:30:00.000[GMT+05:30 Mars/Phobos]', tz: 'UTC' },
|
|
4001
|
-
{ label: 'wrong offset for zone', value: '2026-06-15T14:30:00.000[GMT+09:00 Asia/Kolkata]', tz: 'Asia/Kolkata' },
|
|
4002
|
-
{ label: 'gap wall clock', value: '2026-03-08T02:30:00.000', tz: 'America/New_York' },
|
|
4003
|
-
{ label: 'hour 24', value: '2026-06-15T24:00:00.000', tz: 'UTC' },
|
|
4004
|
-
{ label: 'month 13', value: '2026-13-15T10:00:00.000', tz: 'UTC' },
|
|
4005
|
-
{ label: 'year 0001', value: '0001-01-01T00:00:00.000Z', tz: 'UTC' },
|
|
4006
|
-
{ label: 'year 9999', value: '9999-12-31T23:59:59.999Z', tz: 'UTC' },
|
|
4007
|
-
];
|
|
4008
|
-
const notes = [];
|
|
4009
|
-
const f = new Failures();
|
|
4010
|
-
// An empty / unparseable value leaves NO selection, and Apply is a no-op without a selection (handleApply →
|
|
4011
|
-
// hasSelection()), so these must emit NOTHING. Every other row resolves to an instant and must emit a payload.
|
|
4012
|
-
const EMITS_NOTHING = new Set(['null', 'empty string', 'malformed', 'month 13']);
|
|
4013
|
-
for (const r of rows) {
|
|
4014
|
-
const el = await makePicker({ value: r.value, timezone: r.tz });
|
|
4015
|
-
const p = await apply(el);
|
|
4016
|
-
if (EMITS_NOTHING.has(r.label)) {
|
|
4017
|
-
if (p !== null)
|
|
4018
|
-
f.add(`${r.label} value=${r.value}`, [{ code: 'P9_EMITTED_FOR_NO_SELECTION', detail: `emitted ${JSON.stringify(p)}` }]);
|
|
4019
|
-
notes.push(`${r.label.padEnd(22)} NO_PAYLOAD (expected)`);
|
|
4020
|
-
continue;
|
|
4021
|
-
}
|
|
4022
|
-
// Whatever it does, the payload must never LIE about its own epoch.
|
|
4023
|
-
f.add(`${r.label} value=${r.value}`, checkPayload(p));
|
|
4024
|
-
const cls = p === null ? 'NO_PAYLOAD'
|
|
4025
|
-
: p.unixEpoch === null ? 'REJECT(null epoch)'
|
|
4026
|
-
: 'ACCEPTED';
|
|
4027
|
-
notes.push(`${r.label.padEnd(22)} ${cls.padEnd(20)} epoch=${p && p.unixEpoch} tz=${p && p.timezone} value=${p && p.value}`);
|
|
4028
|
-
}
|
|
4029
|
-
// eslint-disable-next-line no-console
|
|
4030
|
-
console.warn(`[audit-p9] invalid/edge input classification:\n ${notes.join('\n ')}`);
|
|
4031
|
-
expect(f.count, `invalid-input payload lies:${f.report()}`).to.equal(0);
|
|
4032
|
-
}).timeout(600000);
|
|
4033
|
-
});
|
|
4034
|
-
describe('PHASE 11 — repeated round trips must not drift', () => {
|
|
4035
|
-
it('P11.1 100 consecutive emit->reload->Apply cycles hold the epoch to the ms', async () => {
|
|
4036
|
-
const f = new Failures();
|
|
4037
|
-
const seeds = [
|
|
4038
|
-
{ label: 'ms=999 half-hour zone', value: '2026-06-15T14:30:45.999[GMT+05:30 Asia/Kolkata]', tz: 'Asia/Kolkata' },
|
|
4039
|
-
{ label: 'quarter-hour zone', value: '2026-06-15T14:30:45.001[GMT+05:45 Asia/Kathmandu]', tz: 'Asia/Kathmandu' },
|
|
4040
|
-
{ label: 'alias', value: '2026-06-15T14:30:45.123[GMT+05:30 Asia/Calcutta]', tz: 'Asia/Calcutta' },
|
|
4041
|
-
{ label: 'DST overlap 2nd', value: '2026-11-01T01:30:00.000[GMT-05:00 America/New_York]', tz: 'America/New_York' },
|
|
4042
|
-
{ label: 'DST gap resolved', value: '2026-03-08T03:30:00.000[GMT-04:00 America/New_York]', tz: 'America/New_York' },
|
|
4043
|
-
{ label: '+14 extreme', value: '2026-06-15T14:30:45.500[GMT+14:00 Pacific/Kiritimati]', tz: 'Pacific/Kiritimati' },
|
|
4044
|
-
{ label: 'negative extreme', value: '2026-06-15T14:30:45.500[GMT-11:00 Pacific/Niue]', tz: 'Pacific/Niue' },
|
|
4045
|
-
{ label: 'Lord Howe :30', value: '2026-06-15T14:30:45.250[GMT+10:30 Australia/Lord_Howe]', tz: 'Australia/Lord_Howe' },
|
|
4046
|
-
];
|
|
4047
|
-
for (const s of seeds) {
|
|
4048
|
-
let cur = await apply(await makePicker({ value: s.value, timezone: s.tz }));
|
|
4049
|
-
if (!cur || cur.unixEpoch === null) {
|
|
4050
|
-
f.add(s.label, [{ code: 'P11_NO_SEED', detail: s.value }]);
|
|
4051
|
-
continue;
|
|
4052
|
-
}
|
|
4053
|
-
const first = cur.unixEpoch;
|
|
4054
|
-
for (let i = 0; i < 100; i++) {
|
|
4055
|
-
const next = await apply(await makePicker({ value: cur.value, timezone: cur.timezone }));
|
|
4056
|
-
f.add(`${s.label} iter=${i}`, checkPayload(next));
|
|
4057
|
-
if (!next || next.unixEpoch !== first) {
|
|
4058
|
-
f.add(s.label, [{
|
|
4059
|
-
code: 'P11_DRIFT',
|
|
4060
|
-
detail: `iter=${i} first=${first} now=${next && next.unixEpoch} delta=${next && next.unixEpoch !== null ? next.unixEpoch - first : 'n/a'}ms`,
|
|
4061
|
-
}]);
|
|
4062
|
-
break;
|
|
4063
|
-
}
|
|
4064
|
-
cur = next;
|
|
4065
|
-
}
|
|
4066
|
-
}
|
|
4067
|
-
// eslint-disable-next-line no-console
|
|
4068
|
-
console.warn(`[audit-p11] 8 seeds x 100 cycles, violations=${f.count}`);
|
|
4069
|
-
expect(f.count, `round-trip drift:${f.report()}`).to.equal(0);
|
|
4070
|
-
}).timeout(1800000);
|
|
4071
|
-
});
|
|
4072
|
-
describe('PHASE 12 — randomized property testing (deterministic seed)', () => {
|
|
4073
|
-
it('P12.1 random wall clock x zone reproduces its own digits unless it is a gap', async () => {
|
|
4074
|
-
const SEED = 20260913;
|
|
4075
|
-
const rnd = mulberry32(SEED);
|
|
4076
|
-
const zones = runtimeZones();
|
|
4077
|
-
const f = new Failures();
|
|
4078
|
-
const N = 1500;
|
|
4079
|
-
let gaps = 0;
|
|
4080
|
-
let checked = 0;
|
|
4081
|
-
for (let i = 0; i < N; i++) {
|
|
4082
|
-
const z = zones[Math.floor(rnd() * zones.length)];
|
|
4083
|
-
const w = {
|
|
4084
|
-
year: 1990 + Math.floor(rnd() * 80),
|
|
4085
|
-
month: 1 + Math.floor(rnd() * 12),
|
|
4086
|
-
day: 1 + Math.floor(rnd() * 28),
|
|
4087
|
-
hours: Math.floor(rnd() * 24),
|
|
4088
|
-
minutes: Math.floor(rnd() * 60),
|
|
4089
|
-
seconds: Math.floor(rnd() * 60),
|
|
4090
|
-
ms: Math.floor(rnd() * 1000),
|
|
4091
|
-
};
|
|
4092
|
-
const occ = instantsFor(w, z);
|
|
4093
|
-
const el = await makePicker({});
|
|
4094
|
-
const p = await selectAndApply(el, w, z);
|
|
4095
|
-
const ctx = `seed=${SEED} i=${i} host=${HOST_TZ} tz=${z} want=${fmtWall(w)}`;
|
|
4096
|
-
f.add(ctx, checkPayload(p, z));
|
|
4097
|
-
if (p && p.unixEpoch !== null) {
|
|
4098
|
-
if (occ.length === 0) {
|
|
4099
|
-
gaps += 1; // gap: digits legitimately differ
|
|
4100
|
-
}
|
|
4101
|
-
else {
|
|
4102
|
-
const back = wallAt(p.unixEpoch, z);
|
|
4103
|
-
if (fmtWall(back) !== fmtWall(w)) {
|
|
4104
|
-
f.add(ctx, [{
|
|
4105
|
-
code: 'P12_DIGITS_NOT_REPRODUCED',
|
|
4106
|
-
detail: `expectedWall=${fmtWall(w)} actualWall=${fmtWall(back)} ` +
|
|
4107
|
-
`expectedEpochOneOf=[${occ.join(',')}] actualEpoch=${p.unixEpoch} ` +
|
|
4108
|
-
`offset=${offsetAt(p.unixEpoch, z) / 60000}min value=${p.value}`,
|
|
4109
|
-
}]);
|
|
4110
|
-
}
|
|
4111
|
-
if (occ.indexOf(p.unixEpoch) === -1) {
|
|
4112
|
-
f.add(ctx, [{
|
|
4113
|
-
code: 'P12_EPOCH_NOT_AN_OCCURRENCE',
|
|
4114
|
-
detail: `actualEpoch=${p.unixEpoch} validOccurrences=[${occ.join(',')}] value=${p.value}`,
|
|
4115
|
-
}]);
|
|
4116
|
-
}
|
|
4117
|
-
checked += 1;
|
|
4118
|
-
}
|
|
4119
|
-
}
|
|
4120
|
-
}
|
|
4121
|
-
// eslint-disable-next-line no-console
|
|
4122
|
-
console.warn(`[audit-p12] seed=${SEED} cases=${N} verified=${checked} gapsSkipped=${gaps} violations=${f.count}`);
|
|
4123
|
-
expect(f.count, `random property violations:${f.report()}`).to.equal(0);
|
|
4124
|
-
}).timeout(1800000);
|
|
4125
|
-
});
|
|
4126
|
-
/* ==========================================================================
|
|
4127
|
-
PART 9 — PHASE 10/14/15: UI sequences, Set to now, Apply semantics
|
|
4128
|
-
(was p1045-ui.test.ts)
|
|
4129
|
-
========================================================================== */
|
|
4130
|
-
const days = (cal) => Array.from(cal.shadowRoot.querySelectorAll('.day_date:not(.filler)'));
|
|
4131
|
-
const nowBtn = (cal) => cal.shadowRoot.querySelector('.tp-set-to-now-button');
|
|
4132
|
-
const localLink = (cal) => cal.shadowRoot.querySelector('.tp-timezone-local-link');
|
|
4133
|
-
const resetBtn = (cal) => cal.shadowRoot.querySelector('.clear-button');
|
|
4134
|
-
const steppers = (cal) => Array.from(cal.shadowRoot.querySelectorAll('.tp-stepper-btn'));
|
|
4135
|
-
async function clickDay(el, i = 3) {
|
|
4136
|
-
const cal = await settle(el);
|
|
4137
|
-
const d = days(cal);
|
|
4138
|
-
if (d.length > i) {
|
|
4139
|
-
d[i].click();
|
|
4140
|
-
await settle(el);
|
|
4141
|
-
}
|
|
4142
|
-
}
|
|
4143
|
-
async function setZone(el, z) {
|
|
4144
|
-
const cal = await settle(el);
|
|
4145
|
-
cal.timezone = z;
|
|
4146
|
-
await settle(el);
|
|
4147
|
-
}
|
|
4148
|
-
async function setTime(el, h, mi, s = 0, ms = 0) {
|
|
4149
|
-
const cal = await settle(el);
|
|
4150
|
-
cal.tpHours = h;
|
|
4151
|
-
cal.tpMinutes = mi;
|
|
4152
|
-
cal.tpSeconds = s;
|
|
4153
|
-
cal.tpMilliseconds = ms;
|
|
4154
|
-
await settle(el);
|
|
4155
|
-
}
|
|
4156
|
-
describe('PHASE 10 — UI sequence fuzzing', () => {
|
|
4157
|
-
const SEQUENCES = [
|
|
4158
|
-
['date', 'time', 'zone'],
|
|
4159
|
-
['zone', 'date', 'time'],
|
|
4160
|
-
['time', 'date', 'zone'],
|
|
4161
|
-
['date', 'zone', 'time'],
|
|
4162
|
-
['zone', 'time', 'date'],
|
|
4163
|
-
['time', 'zone', 'date'],
|
|
4164
|
-
['nav-month', 'date', 'time'],
|
|
4165
|
-
['nav-year', 'date', 'time'],
|
|
4166
|
-
['date', 'time', 'zone', 'reset', 'date', 'time'],
|
|
4167
|
-
['date', 'zone', 'time', 'zone', 'date'],
|
|
4168
|
-
];
|
|
4169
|
-
it('P10.1 every ordering yields a payload consistent with its own final state', async () => {
|
|
4170
|
-
const f = new Failures();
|
|
4171
|
-
const zones = ['Asia/Kolkata', 'America/New_York', 'Pacific/Chatham'];
|
|
4172
|
-
let n = 0;
|
|
4173
|
-
for (const seq of SEQUENCES) {
|
|
4174
|
-
for (const z of zones) {
|
|
4175
|
-
const el = await makePicker({});
|
|
4176
|
-
for (const step of seq) {
|
|
4177
|
-
if (step === 'date')
|
|
4178
|
-
await clickDay(el, 3);
|
|
4179
|
-
else if (step === 'time')
|
|
4180
|
-
await setTime(el, 14, 45, 7, 123);
|
|
4181
|
-
else if (step === 'zone')
|
|
4182
|
-
await setZone(el, z);
|
|
4183
|
-
else if (step === 'reset') {
|
|
4184
|
-
const c = await settle(el);
|
|
4185
|
-
resetBtn(c) && resetBtn(c).click();
|
|
4186
|
-
await settle(el);
|
|
4187
|
-
}
|
|
4188
|
-
else if (step === 'nav-month') {
|
|
4189
|
-
const c = await settle(el);
|
|
4190
|
-
c.currentMonth = (c.currentMonth + 1) % 12;
|
|
4191
|
-
await settle(el);
|
|
4192
|
-
}
|
|
4193
|
-
else if (step === 'nav-year') {
|
|
4194
|
-
const c = await settle(el);
|
|
4195
|
-
c.currentYear = c.currentYear + 1;
|
|
4196
|
-
await settle(el);
|
|
4197
|
-
}
|
|
4198
|
-
}
|
|
4199
|
-
const p = await apply(el);
|
|
4200
|
-
const ctx = `seq=[${seq.join('>')}] tz=${z} host=${HOST_TZ}`;
|
|
4201
|
-
// The payload must be self-consistent regardless of interaction order.
|
|
4202
|
-
f.add(ctx, checkPayload(p));
|
|
4203
|
-
if (p && p.unixEpoch !== null)
|
|
4204
|
-
f.add(ctx, (await roundTrip(p)).violations);
|
|
4205
|
-
n += 1;
|
|
4206
|
-
}
|
|
4207
|
-
}
|
|
4208
|
-
// eslint-disable-next-line no-console
|
|
4209
|
-
console.warn(`[audit-p10] sequences run=${n} violations=${f.count}`);
|
|
4210
|
-
expect(f.count, `UI-sequence violations:${f.report()}`).to.equal(0);
|
|
4211
|
-
}).timeout(1800000);
|
|
4212
|
-
it('P10.2 changing zone AFTER selecting keeps wall-clock digits and moves the epoch', async () => {
|
|
4213
|
-
const f = new Failures();
|
|
4214
|
-
const el = await makePicker({});
|
|
4215
|
-
await clickDay(el, 3);
|
|
4216
|
-
await setTime(el, 14, 30, 0, 0);
|
|
4217
|
-
await setZone(el, 'Asia/Kolkata');
|
|
4218
|
-
const p1 = await apply(el);
|
|
4219
|
-
await setZone(el, 'America/New_York');
|
|
4220
|
-
const p2 = await apply(el);
|
|
4221
|
-
f.add('zone-change p1', checkPayload(p1, 'Asia/Kolkata'));
|
|
4222
|
-
f.add('zone-change p2', checkPayload(p2, 'America/New_York'));
|
|
4223
|
-
if (p1 && p2 && p1.unixEpoch !== null && p2.unixEpoch !== null) {
|
|
4224
|
-
const w1 = wallAt(p1.unixEpoch, 'Asia/Kolkata');
|
|
4225
|
-
const w2 = wallAt(p2.unixEpoch, 'America/New_York');
|
|
4226
|
-
// documented: a wall clock FOLLOWS the zone (digits kept, epoch re-derived)
|
|
4227
|
-
if (fmtWall(w1) !== fmtWall(w2)) {
|
|
4228
|
-
f.add('zone-change', [{
|
|
4229
|
-
code: 'P10_DIGITS_NOT_KEPT',
|
|
4230
|
-
detail: `kolkata=${fmtWall(w1)} ny=${fmtWall(w2)} (documented behaviour is digits-kept)`,
|
|
4231
|
-
}]);
|
|
4232
|
-
}
|
|
4233
|
-
if (p1.unixEpoch === p2.unixEpoch) {
|
|
4234
|
-
f.add('zone-change', [{ code: 'P10_EPOCH_DID_NOT_MOVE', detail: `both=${p1.unixEpoch}` }]);
|
|
4235
|
-
}
|
|
4236
|
-
}
|
|
4237
|
-
expect(f.count, `zone-change violations:${f.report()}`).to.equal(0);
|
|
4238
|
-
}).timeout(300000);
|
|
4239
|
-
});
|
|
4240
|
-
describe('PHASE 14 — Set to now (frozen clock)', () => {
|
|
4241
|
-
// Contract (nile-calendar handleSetToNow, unchanged since the variant was introduced): "Set to now" reads the
|
|
4242
|
-
// HOST-local clock fields and adopts the HOST timezone, so the committed instant is exactly "now" and the
|
|
4243
|
-
// payload is presented in the host zone — whatever zone was selected before. (P14.2 covers the explicit
|
|
4244
|
-
// "Use local timezone" link.) The clock is frozen by replacing the global Date class: `new Date()` does not go
|
|
4245
|
-
// through `Date.now`, so stubbing only `Date.now` (as this test used to) leaves the component on the real clock.
|
|
4246
|
-
it('P14.1 Set to now commits the frozen instant, presented in the HOST zone (selected zone is replaced)', async () => {
|
|
4247
|
-
const f = new Failures();
|
|
4248
|
-
const FROZEN = Date.UTC(2026, 5, 15, 18, 42, 37, 456);
|
|
4249
|
-
const RealDate = Date;
|
|
4250
|
-
class FrozenDate extends RealDate {
|
|
4251
|
-
constructor(...args) {
|
|
4252
|
-
if (args.length === 0)
|
|
4253
|
-
super(FROZEN);
|
|
4254
|
-
else
|
|
4255
|
-
super(...args);
|
|
4256
|
-
}
|
|
4257
|
-
static now() { return FROZEN; }
|
|
4258
|
-
}
|
|
4259
|
-
try {
|
|
4260
|
-
for (const z of ['UTC', 'Asia/Kolkata', 'America/New_York', 'Pacific/Kiritimati']) {
|
|
4261
|
-
const el = await makePicker({});
|
|
4262
|
-
await setZone(el, z);
|
|
4263
|
-
const cal = await settle(el);
|
|
4264
|
-
const btn = nowBtn(cal);
|
|
4265
|
-
if (!btn) {
|
|
4266
|
-
f.add(z, [{ code: 'P14_NO_BUTTON', detail: 'set-to-now control not found' }]);
|
|
4267
|
-
continue;
|
|
4268
|
-
}
|
|
4269
|
-
globalThis.Date = FrozenDate;
|
|
4270
|
-
try {
|
|
4271
|
-
btn.click();
|
|
4272
|
-
}
|
|
4273
|
-
finally {
|
|
4274
|
-
globalThis.Date = RealDate;
|
|
4275
|
-
}
|
|
4276
|
-
await settle(el);
|
|
4277
|
-
const p = await apply(el);
|
|
4278
|
-
const ctx = `set-to-now (selected tz=${z}) frozen=${FROZEN} host=${HOST_TZ}`;
|
|
4279
|
-
// the payload must be internally consistent in the HOST zone
|
|
4280
|
-
f.add(ctx, checkPayload(p, HOST_TZ));
|
|
4281
|
-
if (p && p.unixEpoch !== null) {
|
|
4282
|
-
const drift = p.unixEpoch - FROZEN;
|
|
4283
|
-
// eslint-disable-next-line no-console
|
|
4284
|
-
console.warn(`[audit-p14] selected=${z} frozenEpoch=${FROZEN} appliedEpoch=${p.unixEpoch} ` +
|
|
4285
|
-
`drift=${drift}ms value=${p.value}`);
|
|
4286
|
-
if (Math.abs(drift) > 1000) {
|
|
4287
|
-
f.add(ctx, [{ code: 'P14_NOW_DRIFT', detail: `drift=${drift}ms (>1s from frozen now)` }]);
|
|
4288
|
-
}
|
|
4289
|
-
if (p.timezone !== HOST_TZ) {
|
|
4290
|
-
f.add(ctx, [{ code: 'P14_ZONE_NOT_HOST', detail: `payload tz=${p.timezone} host=${HOST_TZ}` }]);
|
|
4291
|
-
}
|
|
4292
|
-
}
|
|
4293
|
-
}
|
|
4294
|
-
}
|
|
4295
|
-
finally {
|
|
4296
|
-
globalThis.Date = RealDate;
|
|
4297
|
-
}
|
|
4298
|
-
expect(f.count, `set-to-now violations:${f.report()}`).to.equal(0);
|
|
4299
|
-
}).timeout(600000);
|
|
4300
|
-
it('P14.2 "Use local timezone" adopts the HOST zone deliberately, not by accident', async () => {
|
|
4301
|
-
const el = await makePicker({});
|
|
4302
|
-
await setZone(el, 'Pacific/Kiritimati');
|
|
4303
|
-
const cal = await settle(el);
|
|
4304
|
-
const link = localLink(cal);
|
|
4305
|
-
const before = cal.timezone;
|
|
4306
|
-
if (link) {
|
|
4307
|
-
link.click();
|
|
4308
|
-
await settle(el);
|
|
4309
|
-
}
|
|
4310
|
-
// eslint-disable-next-line no-console
|
|
4311
|
-
console.warn(`[audit-p14] use-local-timezone: before=${before} after=${(await settle(el)).timezone} host=${HOST_TZ}`);
|
|
4312
|
-
expect(link, 'the local-timezone control exists').to.exist;
|
|
4313
|
-
}).timeout(300000);
|
|
4314
|
-
});
|
|
4315
|
-
describe('PHASE 15 — Apply semantics / commit boundary', () => {
|
|
4316
|
-
// ROOT CAUSE (verified with a probe): the picker's panel content is parked in a detached popper while the panel
|
|
4317
|
-
// is closed, so the calendar's <nile-input> time fields are NOT connected (isConnected=false, hasUpdated=false,
|
|
4318
|
-
// no shadow root, `.input` null). A stepper click called `nile-input.focus()` -> `this.input.focus` -> TypeError.
|
|
4319
|
-
// A user can only click a stepper once the panel is open (connected), so this only hit programmatic clicks.
|
|
4320
|
-
// The calendar's step() now skips focusing an input that has not rendered; see also calendar test S2.
|
|
4321
|
-
it('P15.1 editing before Apply does not publish a committed instant', async () => {
|
|
4322
|
-
const el = await makePicker({});
|
|
4323
|
-
let emissions = 0;
|
|
4324
|
-
el.addEventListener('nile-change', () => { emissions += 1; });
|
|
4325
|
-
await clickDay(el, 3);
|
|
4326
|
-
await setTime(el, 9, 15, 0, 0);
|
|
4327
|
-
await setZone(el, 'Asia/Kolkata');
|
|
4328
|
-
const cal = await settle(el);
|
|
4329
|
-
const sts = steppers(cal);
|
|
4330
|
-
if (sts.length) {
|
|
4331
|
-
sts[0].click();
|
|
4332
|
-
await settle(el);
|
|
4333
|
-
}
|
|
4334
|
-
const beforeApply = emissions;
|
|
4335
|
-
applyButton(cal).click();
|
|
4336
|
-
await settle(el);
|
|
4337
|
-
// eslint-disable-next-line no-console
|
|
4338
|
-
console.warn(`[audit-p15] emissions before Apply=${beforeApply}, after Apply=${emissions}`);
|
|
4339
|
-
expect(beforeApply, 'no nile-change before Apply').to.equal(0);
|
|
4340
|
-
expect(emissions, 'exactly one commit on Apply').to.equal(1);
|
|
4341
|
-
}).timeout(300000);
|
|
4342
|
-
it('P15.2 Apply emits exactly one payload per click across zones', async () => {
|
|
4343
|
-
const f = new Failures();
|
|
4344
|
-
for (const z of ['UTC', 'Asia/Kolkata', 'America/New_York']) {
|
|
4345
|
-
const el = await makePicker({});
|
|
4346
|
-
await clickDay(el, 3);
|
|
4347
|
-
await setTime(el, 10, 0, 0, 0);
|
|
4348
|
-
await setZone(el, z);
|
|
4349
|
-
const p = await apply(el);
|
|
4350
|
-
const count = p ? p.__emitCount : 0;
|
|
4351
|
-
if (count !== 1) {
|
|
4352
|
-
f.add(`tz=${z}`, [{ code: 'P15_EMIT_COUNT', detail: `nile-change fired ${count} times for one Apply` }]);
|
|
4353
|
-
}
|
|
4354
|
-
}
|
|
4355
|
-
expect(f.count, `apply-emission violations:${f.report()}`).to.equal(0);
|
|
4356
|
-
}).timeout(300000);
|
|
4357
|
-
it('P15.3 Reset then reselect produces a fresh, consistent payload', async () => {
|
|
4358
|
-
const f = new Failures();
|
|
4359
|
-
const el = await makePicker({ value: '2026-06-15T09:00:00.000Z', timezone: 'Asia/Kolkata' });
|
|
4360
|
-
const p1 = await apply(el);
|
|
4361
|
-
const cal = await settle(el);
|
|
4362
|
-
if (resetBtn(cal)) {
|
|
4363
|
-
resetBtn(cal).click();
|
|
4364
|
-
await settle(el);
|
|
4365
|
-
}
|
|
4366
|
-
await clickDay(el, 4);
|
|
4367
|
-
await setTime(el, 23, 59, 59, 999);
|
|
4368
|
-
const p2 = await apply(el);
|
|
4369
|
-
f.add('after-reset', checkPayload(p2, 'Asia/Kolkata'));
|
|
4370
|
-
if (p1 && p2 && p1.unixEpoch === p2.unixEpoch) {
|
|
4371
|
-
f.add('after-reset', [{ code: 'P15_STALE_EPOCH', detail: `reset did not clear retained instant: ${p1.unixEpoch}` }]);
|
|
4372
|
-
}
|
|
4373
|
-
if (p2 && p2.unixEpoch !== null)
|
|
4374
|
-
f.add('after-reset', (await roundTrip(p2)).violations);
|
|
4375
|
-
expect(f.count, `reset violations:${f.report()}`).to.equal(0);
|
|
4376
|
-
}).timeout(300000);
|
|
4377
|
-
});
|
|
4378
|
-
// ============================================================================
|
|
4379
|
-
// NOTE ON TEST-RUNNER PICKUP
|
|
4380
|
-
// Section K is an exhaustive sweep (hundreds of zones, every DST transition,
|
|
4381
|
-
// thousands of randomised cases) and takes minutes, not seconds. It now lives
|
|
4382
|
-
// in this file, so a plain `yarn test` runs it alongside the unit suites and
|
|
4383
|
-
// the default run is correspondingly slower.
|
|
4384
|
-
//
|
|
4385
|
-
// Section K's own `it`s carry explicit `.timeout(...)` calls, so they are not
|
|
4386
|
-
// bound by the 15s default in web-test-runner.config.mjs. The runner-level
|
|
4387
|
-
// `testsFinishTimeout` (300000 = 5 min) still applies to the whole run; raise
|
|
4388
|
-
// it there if the suite outgrows it.
|
|
4389
|
-
// ============================================================================
|
|
4390
|
-
/**
|
|
4391
|
-
* ── R. REGRESSIONS (code-review findings #1, #2a, #3, #6) ───────────────────
|
|
4392
|
-
*/
|
|
4393
|
-
describe('NileDateTimePicker regressions', () => {
|
|
4394
|
-
const VALUE = '2026-03-15T10:30:00';
|
|
4395
|
-
const inputOf = (el) => el.shadowRoot.querySelector('nile-input');
|
|
4396
|
-
const textOf = (el) => inputOf(el).input.value;
|
|
4397
|
-
const openPanel = async (el) => {
|
|
4398
|
-
el.open = true;
|
|
4399
|
-
await settle2(el);
|
|
4400
|
-
await aTimeout(50);
|
|
4401
|
-
return el.calendarElement;
|
|
4402
|
-
};
|
|
4403
|
-
const days = (cal) => [...cal.shadowRoot.querySelectorAll('.day_date:not(.filler)')];
|
|
4404
|
-
const pad = (n) => String(n).padStart(2, '0');
|
|
4405
|
-
it('R1. setting value to null clears the trigger text (#1)', async () => {
|
|
4406
|
-
const el = await fixture(html `<nile-date-time-picker .dateFormat=${'YYYY-MM-DD'} .value=${VALUE}></nile-date-time-picker>`);
|
|
4407
|
-
await settle2(el);
|
|
4408
|
-
expect(textOf(el), 'precondition').to.contain('2026-03-15');
|
|
4409
|
-
el.value = null;
|
|
4410
|
-
await settle2(el);
|
|
4411
|
-
expect(textOf(el)).to.equal('');
|
|
4412
|
-
// a later value still seeds normally
|
|
4413
|
-
el.value = '2026-04-01T08:00:00';
|
|
4414
|
-
await settle2(el);
|
|
4415
|
-
expect(textOf(el)).to.contain('2026-04-01');
|
|
4416
|
-
});
|
|
4417
|
-
it('R2. the typing mask still works after the picker is moved in the DOM (#2a)', async () => {
|
|
4418
|
-
const el = await fixture(html `<nile-date-time-picker .dateFormat=${'DD/MM/YY'}></nile-date-time-picker>`);
|
|
4419
|
-
await settle2(el);
|
|
4420
|
-
const host = el.parentNode;
|
|
4421
|
-
el.remove();
|
|
4422
|
-
host.appendChild(el);
|
|
4423
|
-
await settle2(el);
|
|
4424
|
-
await inputOf(el).updateComplete;
|
|
4425
|
-
for (const key of '23') {
|
|
4426
|
-
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, composed: true, cancelable: true }));
|
|
4427
|
-
}
|
|
4428
|
-
expect(textOf(el)).to.equal('23/');
|
|
4429
|
-
});
|
|
4430
|
-
it('R3a. a relative range is rendered in the zone it is labelled with, not the host zone (#3)', async () => {
|
|
4431
|
-
const el = await fixture(html `<nile-date-time-picker type="relative" .dateFormat=${'YYYY-MM-DD'}></nile-date-time-picker>`);
|
|
4432
|
-
await settle2(el);
|
|
4433
|
-
const cal = el.calendarElement;
|
|
4434
|
-
cal.dispatchEvent(new CustomEvent('nile-change', {
|
|
4435
|
-
bubbles: true, composed: true,
|
|
4436
|
-
detail: {
|
|
4437
|
-
startDate: new Date(Date.UTC(2026, 5, 15, 3, 0, 0)),
|
|
4438
|
-
endDate: new Date(Date.UTC(2026, 5, 15, 5, 0, 0)),
|
|
4439
|
-
timezone: 'Asia/Kolkata',
|
|
4440
|
-
},
|
|
4441
|
-
}));
|
|
4442
|
-
await settle2(el);
|
|
4443
|
-
// 03:00Z / 05:00Z are 08:30 / 10:30 in Kolkata, whatever zone the browser runs in
|
|
4444
|
-
expect(textOf(el)).to.contain('2026-06-15 - 08:30');
|
|
4445
|
-
expect(textOf(el)).to.contain('2026-06-15 - 10:30');
|
|
4446
|
-
expect(textOf(el)).to.match(/ - Asia\/Kolkata$/);
|
|
4447
|
-
});
|
|
4448
|
-
it('R3b. a relative Apply shows the UTC wall-clock it is labelled with (#3)', async () => {
|
|
4449
|
-
const el = await fixture(html `<nile-date-time-picker type="relative" .dateFormat=${'YYYY-MM-DD'}></nile-date-time-picker>`);
|
|
4450
|
-
await settle2(el);
|
|
4451
|
-
const cal = await openPanel(el);
|
|
4452
|
-
let detail = null;
|
|
4453
|
-
el.addEventListener('nile-change', ((e) => { detail = e.detail; }));
|
|
4454
|
-
cal.handleTimeValueClick('hours', 2, new Event('click'));
|
|
4455
|
-
await settle2(el);
|
|
4456
|
-
applyButton(cal).click();
|
|
4457
|
-
await settle2(el);
|
|
4458
|
-
const end = new Date(detail.endDate);
|
|
4459
|
-
expect(detail.timezone).to.equal('UTC');
|
|
4460
|
-
expect(textOf(el)).to.contain(`${pad(end.getUTCHours())}:${pad(end.getUTCMinutes())}`);
|
|
4461
|
-
expect(textOf(el)).to.match(/ - UTC$/);
|
|
4462
|
-
expect(el.value, 'a relative apply does not write value').to.be.null;
|
|
4463
|
-
});
|
|
4464
|
-
it('R3c. with the timezone label hidden, a relative range keeps the host wall-clock (unchanged)', async () => {
|
|
4465
|
-
const el = await fixture(html `<nile-date-time-picker type="relative" .dateFormat=${'YYYY-MM-DD'}
|
|
4466
|
-
.hideTimeFields=${['timezone']}></nile-date-time-picker>`);
|
|
4467
|
-
await settle2(el);
|
|
4468
|
-
const start = new Date(Date.UTC(2026, 5, 15, 3, 0, 0));
|
|
4469
|
-
const cal = el.calendarElement;
|
|
4470
|
-
cal.dispatchEvent(new CustomEvent('nile-change', {
|
|
4471
|
-
bubbles: true, composed: true,
|
|
4472
|
-
detail: { startDate: start, endDate: new Date(Date.UTC(2026, 5, 15, 5, 0, 0)), timezone: 'Asia/Kolkata' },
|
|
4473
|
-
}));
|
|
4474
|
-
await settle2(el);
|
|
4475
|
-
expect(textOf(el)).to.contain(`${pad(start.getHours())}:${pad(start.getMinutes())}`);
|
|
4476
|
-
expect(textOf(el)).to.not.contain('Asia/Kolkata');
|
|
4477
|
-
});
|
|
4478
|
-
it('R6. Apply updates value, and a later timezone change keeps the applied pick (#6)', async () => {
|
|
4479
|
-
const el = await fixture(html `<nile-date-time-picker .dateFormat=${'YYYY-MM-DD'} .value=${VALUE}></nile-date-time-picker>`);
|
|
4480
|
-
await settle2(el);
|
|
4481
|
-
const cal = await openPanel(el);
|
|
4482
|
-
days(cal)[20].click();
|
|
4483
|
-
await settle2(el);
|
|
4484
|
-
let detail = null;
|
|
4485
|
-
el.addEventListener('nile-change', ((e) => { detail = e.detail; }));
|
|
4486
|
-
applyButton(cal).click();
|
|
4487
|
-
await settle2(el);
|
|
4488
|
-
const pickedDay = detail.value.slice(0, 10);
|
|
4489
|
-
expect(pickedDay, 'precondition: a different day was applied').to.not.equal('2026-03-15');
|
|
4490
|
-
expect(el.value).to.equal(detail.value);
|
|
4491
|
-
expect(textOf(el)).to.contain(pickedDay);
|
|
4492
|
-
el.timezone = 'Asia/Kolkata';
|
|
4493
|
-
await settle2(el);
|
|
4494
|
-
expect(textOf(el)).to.contain(pickedDay);
|
|
4495
|
-
expect(textOf(el)).to.not.contain('2026-03-15');
|
|
4496
|
-
});
|
|
4497
|
-
});
|
|
4498
|
-
// ── M. review fixes: type sync, Clear keeps the configured zone, non-keydown mask input ──
|
|
4499
|
-
describe('NileDateTimePicker — type sync, timezone on Clear, paste / beforeinput', () => {
|
|
4500
|
-
const dtpFixture = () => fixture(html `<nile-date-time-picker></nile-date-time-picker>`);
|
|
4501
|
-
const innerCalendar = (el) => el.calendarElement;
|
|
4502
|
-
const triggerInput = (el) => el.shadowRoot.querySelector('nile-input');
|
|
4503
|
-
const settle = async (el) => {
|
|
4504
|
-
await el.updateComplete;
|
|
4505
|
-
const cal = innerCalendar(el);
|
|
4506
|
-
if (cal)
|
|
4507
|
-
await cal.updateComplete;
|
|
4508
|
-
return cal;
|
|
4509
|
-
};
|
|
4510
|
-
const settle2 = async (el) => { await settle(el); return settle(el); };
|
|
4511
|
-
const dayCells = (cal) => cal.shadowRoot.querySelectorAll('.day_date:not(.filler)');
|
|
4512
|
-
const clickDay = (cal, i = 5) => dayCells(cal)[i].click();
|
|
4513
|
-
const resetBtn = (cal) => cal.shadowRoot.querySelector('.clear-button');
|
|
4514
|
-
const switchTab = async (el, value) => {
|
|
4515
|
-
const cal = await settle(el);
|
|
4516
|
-
cal.shadowRoot.querySelector(`nile-tab[panel="${value}"]`).dispatchEvent(new CustomEvent('nile-tab-show', { detail: { value }, bubbles: true, composed: true }));
|
|
4517
|
-
await cal.updateComplete;
|
|
4518
|
-
await el.updateComplete;
|
|
4519
|
-
};
|
|
4520
|
-
const maskFixture = () => fixture(html `<nile-date-time-picker></nile-date-time-picker>`);
|
|
4521
|
-
const nativeOf = (el) => triggerInput(el).input;
|
|
4522
|
-
const ready = async (el) => { await el.updateComplete; await triggerInput(el).updateComplete; };
|
|
4523
|
-
const paste = (el, text) => {
|
|
4524
|
-
const dt = new DataTransfer();
|
|
4525
|
-
dt.setData('text', text);
|
|
4526
|
-
const ev = new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, composed: true, cancelable: true });
|
|
4527
|
-
triggerInput(el).dispatchEvent(ev);
|
|
4528
|
-
return ev;
|
|
4529
|
-
};
|
|
4530
|
-
it('M1. switching the calendar to Relative updates the picker type (and attribute)', async () => {
|
|
4531
|
-
const el = await dtpFixture();
|
|
4532
|
-
expect(el.type).to.equal('absolute');
|
|
4533
|
-
await switchTab(el, 'relative');
|
|
4534
|
-
expect(el.type).to.equal('relative');
|
|
4535
|
-
expect(el.getAttribute('type')).to.equal('relative');
|
|
4536
|
-
});
|
|
4537
|
-
it('M2. switching back to Absolute restores type', async () => {
|
|
4538
|
-
const el = await dtpFixture();
|
|
4539
|
-
await switchTab(el, 'relative');
|
|
4540
|
-
await switchTab(el, 'absolute');
|
|
4541
|
-
expect(el.type).to.equal('absolute');
|
|
4542
|
-
});
|
|
4543
|
-
it('M3. nile-type-change is still forwarded after the type is synced', async () => {
|
|
4544
|
-
const el = await dtpFixture();
|
|
4545
|
-
let detail = null;
|
|
4546
|
-
el.addEventListener('nile-type-change', ((e) => { detail = e.detail; }));
|
|
4547
|
-
await switchTab(el, 'relative');
|
|
4548
|
-
expect(detail?.value).to.equal('relative');
|
|
4549
|
-
});
|
|
4550
|
-
it('M4. Reset in the calendar keeps the consumer-configured timezone', async () => {
|
|
4551
|
-
const el = await fixture(html `<nile-date-time-picker timezone="America/New_York"></nile-date-time-picker>`);
|
|
4552
|
-
const cal = await settle2(el);
|
|
4553
|
-
clickDay(cal, 5);
|
|
4554
|
-
await cal.updateComplete;
|
|
4555
|
-
resetBtn(cal).click();
|
|
4556
|
-
await settle2(el);
|
|
4557
|
-
expect(el.timezone).to.equal('America/New_York');
|
|
4558
|
-
expect(cal.timezone).to.equal('America/New_York');
|
|
4559
|
-
});
|
|
4560
|
-
it('M5. handleClear keeps the configured timezone and empties value', async () => {
|
|
4561
|
-
const el = await fixture(html `<nile-date-time-picker timezone="Asia/Kolkata"></nile-date-time-picker>`);
|
|
4562
|
-
await settle2(el);
|
|
4563
|
-
el.handleClear();
|
|
4564
|
-
await settle2(el);
|
|
4565
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
4566
|
-
expect(el.value == null).to.be.true;
|
|
4567
|
-
});
|
|
4568
|
-
it('M6. with no configured timezone, Clear still lands on UTC', async () => {
|
|
4569
|
-
const el = await dtpFixture();
|
|
4570
|
-
await settle2(el);
|
|
4571
|
-
el.handleClear();
|
|
4572
|
-
await settle2(el);
|
|
4573
|
-
expect(el.timezone).to.equal('UTC');
|
|
4574
|
-
});
|
|
4575
|
-
it('M8. a zone picked in the calendar dropdown is undone by Reset: wrapper and calendar both land on the configured zone', async () => {
|
|
4576
|
-
const el = await fixture(html `<nile-date-time-picker timezone="Europe/London"></nile-date-time-picker>`);
|
|
4577
|
-
const cal = await settle2(el);
|
|
4578
|
-
cal.handleTimezoneChange(new CustomEvent('nile-change', { detail: { value: 'Asia/Tokyo' } }));
|
|
4579
|
-
await cal.updateComplete;
|
|
4580
|
-
resetBtn(cal).click();
|
|
4581
|
-
await settle2(el);
|
|
4582
|
-
expect(cal.timezone).to.equal('Europe/London');
|
|
4583
|
-
expect(el.timezone).to.equal('Europe/London');
|
|
4584
|
-
});
|
|
4585
|
-
it('M9. a dynamic consumer timezone change is what Reset restores, in the wrapper and the calendar', async () => {
|
|
4586
|
-
const el = await fixture(html `<nile-date-time-picker timezone="Europe/London"></nile-date-time-picker>`);
|
|
4587
|
-
const cal = await settle2(el);
|
|
4588
|
-
el.timezone = 'Asia/Kolkata';
|
|
4589
|
-
await settle2(el);
|
|
4590
|
-
cal.handleTimezoneChange(new CustomEvent('nile-change', { detail: { value: 'UTC' } }));
|
|
4591
|
-
await cal.updateComplete;
|
|
4592
|
-
resetBtn(cal).click();
|
|
4593
|
-
await settle2(el);
|
|
4594
|
-
expect(cal.timezone).to.equal('Asia/Kolkata');
|
|
4595
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
4596
|
-
});
|
|
4597
|
-
it('M10. with the timezone field hidden, Reset after Set to now restores the configured zone; Set to now still adopts the host zone', async () => {
|
|
4598
|
-
const el = await fixture(html `<nile-date-time-picker timezone="Europe/London" .hideTimeFields=${['timezone']}></nile-date-time-picker>`);
|
|
4599
|
-
const cal = await settle2(el);
|
|
4600
|
-
const host = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
4601
|
-
cal.shadowRoot.querySelector('.tp-set-to-now-button').click();
|
|
4602
|
-
await cal.updateComplete;
|
|
4603
|
-
expect(cal.timezone).to.equal(host);
|
|
4604
|
-
resetBtn(cal).click();
|
|
4605
|
-
await settle2(el);
|
|
4606
|
-
expect(cal.timezone).to.equal('Europe/London');
|
|
4607
|
-
expect(el.timezone).to.equal('Europe/London');
|
|
4608
|
-
});
|
|
4609
|
-
it('M7. a date-only range seeded into the calendar keeps its days, and Reset still keeps the configured zone (default stays UTC)', async () => {
|
|
4610
|
-
const el = await fixture(html `<nile-date-time-picker timezone="Asia/Kolkata"></nile-date-time-picker>`);
|
|
4611
|
-
const cal = await settle2(el);
|
|
4612
|
-
cal.range = true;
|
|
4613
|
-
cal.valueAttribute = '{"startDate":"2025-12-31","endDate":"2026-01-02"}';
|
|
4614
|
-
await settle2(el);
|
|
4615
|
-
const ymd = (d) => [d.getFullYear(), d.getMonth() + 1, d.getDate()];
|
|
4616
|
-
expect(ymd(cal.startDate)).to.deep.equal([2025, 12, 31]);
|
|
4617
|
-
expect(ymd(cal.endDate)).to.deep.equal([2026, 1, 2]);
|
|
4618
|
-
resetBtn(cal).click();
|
|
4619
|
-
await settle2(el);
|
|
4620
|
-
expect(cal.startDate).to.equal(null);
|
|
4621
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
4622
|
-
expect(cal.timezone).to.equal('Asia/Kolkata');
|
|
4623
|
-
const plain = await dtpFixture();
|
|
4624
|
-
expect(plain.timezone, 'unconfigured default').to.equal('UTC');
|
|
4625
|
-
});
|
|
4626
|
-
it('M6b. a timezone set by the consumer AFTER first render is what Clear restores', async () => {
|
|
4627
|
-
const el = await dtpFixture();
|
|
4628
|
-
await settle2(el);
|
|
4629
|
-
el.timezone = 'Asia/Tokyo';
|
|
4630
|
-
await settle2(el);
|
|
4631
|
-
el.handleClear();
|
|
4632
|
-
await settle2(el);
|
|
4633
|
-
expect(el.timezone).to.equal('Asia/Tokyo');
|
|
4634
|
-
expect(innerCalendar(el).timezone).to.equal('Asia/Tokyo');
|
|
4635
|
-
});
|
|
4636
|
-
it('M6c. calendar Reset after a later consumer zone change keeps that zone (picker + calendar agree)', async () => {
|
|
4637
|
-
const el = await dtpFixture();
|
|
4638
|
-
await settle2(el);
|
|
4639
|
-
el.timezone = 'Europe/Paris';
|
|
4640
|
-
await settle2(el);
|
|
4641
|
-
const cal = innerCalendar(el);
|
|
4642
|
-
clickDay(cal, 5);
|
|
4643
|
-
await cal.updateComplete;
|
|
4644
|
-
resetBtn(cal).click();
|
|
4645
|
-
await settle2(el);
|
|
4646
|
-
expect(el.timezone).to.equal('Europe/Paris');
|
|
4647
|
-
expect(cal.timezone).to.equal('Europe/Paris');
|
|
4648
|
-
});
|
|
4649
|
-
it('M6d. a zone picked in the calendar dropdown is NOT adopted as the default; Reset returns to the configured zone', async () => {
|
|
4650
|
-
const el = await fixture(html `<nile-date-time-picker timezone="Asia/Kolkata"></nile-date-time-picker>`);
|
|
4651
|
-
const cal = await settle2(el);
|
|
4652
|
-
cal.handleTimezoneChange(new CustomEvent('nile-change', { detail: { value: 'America/Chicago' } }));
|
|
4653
|
-
await settle2(el);
|
|
4654
|
-
expect(cal.timezone).to.equal('America/Chicago');
|
|
4655
|
-
resetBtn(cal).click();
|
|
4656
|
-
await settle2(el);
|
|
4657
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
4658
|
-
expect(cal.timezone).to.equal('Asia/Kolkata');
|
|
4659
|
-
});
|
|
4660
|
-
it('M6e. a zone adopted from a bracketed value is not mistaken for the configured default', async () => {
|
|
4661
|
-
const el = await dtpFixture();
|
|
4662
|
-
await settle2(el);
|
|
4663
|
-
el.value = '2026-03-01T10:00:00.000[GMT+05:30 Asia/Kolkata]';
|
|
4664
|
-
await settle2(el);
|
|
4665
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
4666
|
-
el.handleClear();
|
|
4667
|
-
await settle2(el);
|
|
4668
|
-
expect(el.timezone).to.equal('UTC');
|
|
4669
|
-
});
|
|
4670
|
-
it('M7. pasting a full datetime fills the mask like typing it', async () => {
|
|
4671
|
-
const el = await maskFixture();
|
|
4672
|
-
await ready(el);
|
|
4673
|
-
const ev = paste(el, '230326172456426');
|
|
4674
|
-
expect(ev.defaultPrevented).to.be.true;
|
|
4675
|
-
expect(nativeOf(el).value).to.equal('23/03/26 - 17:24:56.426');
|
|
4676
|
-
});
|
|
4677
|
-
it('M8. pasting separator-formatted text uses only its digits', async () => {
|
|
4678
|
-
const el = await maskFixture();
|
|
4679
|
-
await ready(el);
|
|
4680
|
-
paste(el, '23/03/26 - 17:24');
|
|
4681
|
-
expect(nativeOf(el).value.startsWith('23/03/26 - 17:24')).to.be.true;
|
|
4682
|
-
});
|
|
4683
|
-
it('M9. pasting with no digits leaves the mask unchanged', async () => {
|
|
4684
|
-
const el = await maskFixture();
|
|
4685
|
-
await ready(el);
|
|
4686
|
-
paste(el, 'hello');
|
|
4687
|
-
expect(nativeOf(el).value).to.equal('');
|
|
4688
|
-
});
|
|
4689
|
-
it('M10. pasted out-of-range segments are clamped', async () => {
|
|
4690
|
-
const el = await maskFixture();
|
|
4691
|
-
await ready(el);
|
|
4692
|
-
paste(el, '992026');
|
|
4693
|
-
expect(nativeOf(el).value).to.not.contain('99');
|
|
4694
|
-
});
|
|
4695
|
-
it('M11. soft-keyboard style insertText (no usable keydown) is picked up by the mask', async () => {
|
|
4696
|
-
const el = await maskFixture();
|
|
4697
|
-
await ready(el);
|
|
4698
|
-
const native = nativeOf(el);
|
|
4699
|
-
native.value = '2303';
|
|
4700
|
-
triggerInput(el).dispatchEvent(new InputEvent('beforeinput', { inputType: 'insertText', data: '3', bubbles: true, composed: true }));
|
|
4701
|
-
await aTimeout(20);
|
|
4702
|
-
expect(native.value).to.equal('23/03/');
|
|
4703
|
-
});
|
|
4704
|
-
it('M12. a cut (deleteByCut) rebuilds the slots from the remaining text', async () => {
|
|
4705
|
-
const el = await maskFixture();
|
|
4706
|
-
await ready(el);
|
|
4707
|
-
paste(el, '230326');
|
|
4708
|
-
await ready(el); // let the input's own re-render land before simulating the cut
|
|
4709
|
-
const native = nativeOf(el);
|
|
4710
|
-
native.value = '23/03/';
|
|
4711
|
-
triggerInput(el).dispatchEvent(new InputEvent('beforeinput', { inputType: 'deleteByCut', bubbles: true, composed: true }));
|
|
4712
|
-
await aTimeout(20);
|
|
4713
|
-
expect(native.value).to.equal('23/03/');
|
|
4714
|
-
});
|
|
4715
|
-
it('M13. paste is ignored in Relative mode', async () => {
|
|
4716
|
-
const el = await maskFixture();
|
|
4717
|
-
await ready(el);
|
|
4718
|
-
await switchTab(el, 'relative');
|
|
4719
|
-
const ev = paste(el, '230326');
|
|
4720
|
-
expect(ev.defaultPrevented).to.be.false;
|
|
4721
|
-
});
|
|
4722
|
-
});
|
|
4723
|
-
/**
|
|
4724
|
-
* ── Y. YEARS 0-99 (Date.UTC remap regression) ───────────────────────────────
|
|
4725
|
-
* `Date.UTC(y, …)` treats years 0-99 as 1900-1999, so year 0001 used to become 1901: the bracketed offset was
|
|
4726
|
-
* computed for the wrong year (`[GMT+16655040:00 UTC]`) and offset-less / bracketed values re-parsed a century off.
|
|
4727
|
-
* Epochs here are built with setUTCFullYear — never Date.UTC — so the oracle does not share the bug.
|
|
4728
|
-
*/
|
|
4729
|
-
describe('Y. years 0-99 keep their literal year', () => {
|
|
4730
|
-
const epochOf = (y, mo1, d, h = 0, mi = 0, s = 0, ms = 0) => {
|
|
4731
|
-
const dt = new Date(0);
|
|
4732
|
-
dt.setUTCFullYear(y, mo1 - 1, d);
|
|
4733
|
-
dt.setUTCHours(h, mi, s, ms);
|
|
4734
|
-
return dt.getTime();
|
|
4735
|
-
};
|
|
4736
|
-
const pad4 = (y) => String(y).padStart(4, '0');
|
|
4737
|
-
const YEARS = [1, 99, 100];
|
|
4738
|
-
it('Y1. utcFromFields equals Date.UTC for years >= 100 (incl. overflowing fields)', () => {
|
|
4739
|
-
for (const args of [
|
|
4740
|
-
[2026, 5, 15, 12, 30, 15, 250], [100, 0, 1], [1900, 2, 1], [2100, 1, 29], [2024, 12, 32, 25, 61, 61, 1001],
|
|
4741
|
-
[2026, 2, 0],
|
|
4742
|
-
]) {
|
|
4743
|
-
expect(utcFromFields(args[0], args[1], args[2], args[3], args[4], args[5], args[6]), JSON.stringify(args)).to.equal(Date.UTC(args[0], args[1], args[2], args[3] ?? 0, args[4] ?? 0, args[5] ?? 0, args[6] ?? 0));
|
|
4744
|
-
}
|
|
4745
|
-
});
|
|
4746
|
-
it('Y2. utcFromFields keeps years 0-99 literal and returns NaN for NaN input', () => {
|
|
4747
|
-
expect(new Date(utcFromFields(1, 0, 1)).getUTCFullYear()).to.equal(1);
|
|
4748
|
-
expect(new Date(utcFromFields(99, 11, 31, 23, 59, 59, 999)).getUTCFullYear()).to.equal(99);
|
|
4749
|
-
expect(new Date(utcFromFields(0, 1, 29)).getUTCDate()).to.equal(29); // year 0 is a leap year
|
|
4750
|
-
expect(utcFromFields(1, 0, 1)).to.equal(epochOf(1, 1, 1));
|
|
4751
|
-
expect(utcFromFields(NaN, 0, 1)).to.be.NaN;
|
|
4752
|
-
});
|
|
4753
|
-
it('Y3. wallClockFromOffsetLess keeps the literal year, month length and digits', () => {
|
|
4754
|
-
for (const y of YEARS) {
|
|
4755
|
-
const w = wallClockFromOffsetLess(`${pad4(y)}-06-15T12:30:15.250`);
|
|
4756
|
-
expect(w, `year ${y}`).to.deep.equal({ year: y, month: 6, day: 15, hours: 12, minutes: 30, seconds: 15, ms: 250 });
|
|
4757
|
-
}
|
|
4758
|
-
// year 0 is leap (400 | 0); the 1900 remap would clamp Feb 29 to 28
|
|
4759
|
-
expect(wallClockFromOffsetLess('0000-02-29T10:00:00').day).to.equal(29);
|
|
4760
|
-
// year 1 is not leap: Feb 29 clamps to 28
|
|
4761
|
-
expect(wallClockFromOffsetLess('0001-02-29T10:00:00').day).to.equal(28);
|
|
4762
|
-
});
|
|
4763
|
-
it('Y4. instantFromBracketedValue returns the true epoch for years 0001, 0099 and 0100', () => {
|
|
4764
|
-
for (const y of YEARS) {
|
|
4765
|
-
const r = instantFromBracketedValue(`${pad4(y)}-06-15T12:30:15.250[GMT+00:00 UTC]`);
|
|
4766
|
-
expect(r, `year ${y}`).to.deep.equal({ epochMs: epochOf(y, 6, 15, 12, 30, 15, 250), timezone: 'UTC' });
|
|
4767
|
-
}
|
|
4768
|
-
});
|
|
4769
|
-
for (const y of YEARS) {
|
|
4770
|
-
it(`Y5.${y}. Z instant in year ${pad4(y)} emits the true epoch, a sane bracket, and round-trips`, async () => {
|
|
4771
|
-
const raw = `${pad4(y)}-06-15T12:30:15.250Z`;
|
|
4772
|
-
const p = await apply(await makePicker({ value: raw, timezone: 'UTC' }));
|
|
4773
|
-
expect(p, 'payload').to.exist;
|
|
4774
|
-
expect(p.unixEpoch).to.equal(epochOf(y, 6, 15, 12, 30, 15, 250));
|
|
4775
|
-
expect(p.value).to.equal(`${pad4(y)}-06-15T12:30:15.250[GMT+00:00 UTC]`);
|
|
4776
|
-
const rt = await roundTrip(p);
|
|
4777
|
-
expect(rt.second && rt.second.unixEpoch, 'epoch after reload').to.equal(p.unixEpoch);
|
|
4778
|
-
expect(rt.second && rt.second.value).to.equal(p.value);
|
|
4779
|
-
}).timeout(60000);
|
|
4780
|
-
it(`Y6.${y}. offset-less value in year ${pad4(y)} keeps its digits (no 19xx remap)`, async () => {
|
|
4781
|
-
const p = await apply(await makePicker({ value: `${pad4(y)}-06-15T12:30:15.250`, timezone: 'UTC' }));
|
|
4782
|
-
expect(p, 'payload').to.exist;
|
|
4783
|
-
expect(p.unixEpoch).to.equal(epochOf(y, 6, 15, 12, 30, 15, 250));
|
|
4784
|
-
expect(p.value).to.equal(`${pad4(y)}-06-15T12:30:15.250[GMT+00:00 UTC]`);
|
|
4785
|
-
}).timeout(60000);
|
|
4786
|
-
it(`Y7.${y}. bracketed value in year ${pad4(y)} reloads to the same epoch`, async () => {
|
|
4787
|
-
const p = await apply(await makePicker({
|
|
4788
|
-
value: `${pad4(y)}-06-15T12:30:15.250[GMT+00:00 UTC]`, timezone: 'UTC',
|
|
4789
|
-
}));
|
|
4790
|
-
expect(p, 'payload').to.exist;
|
|
4791
|
-
expect(p.unixEpoch).to.equal(epochOf(y, 6, 15, 12, 30, 15, 250));
|
|
4792
|
-
}).timeout(60000);
|
|
4793
|
-
}
|
|
4794
|
-
it('Y8. a Feb-29 in year 0 (leap) survives; year 0001 shows no absurd offset', async () => {
|
|
4795
|
-
const p = await apply(await makePicker({ value: '0001-01-01T00:00:00.000Z', timezone: 'UTC' }));
|
|
4796
|
-
expect(p.value).to.not.match(/GMT[+-]\d{3,}:/);
|
|
4797
|
-
expect(p.value).to.match(/\[GMT[+-]\d{2}:\d{2} UTC\]$/);
|
|
4798
|
-
}).timeout(60000);
|
|
4799
|
-
});
|
|
4800
|
-
describe('Y9. typed date in years 0-99 (mask -> calendar)', () => {
|
|
4801
|
-
it('Y9. a fully typed day in year 0050 selects year 50 (not 1950), and Feb 29 of year 0 is kept', async () => {
|
|
4802
|
-
const el = await makePicker({});
|
|
4803
|
-
el.dateFormat = 'DD/MM/YYYY'; // the default DD/MM/YY reads two digits as 20xx; a literal year 0050 needs YYYY
|
|
4804
|
-
await settle(el);
|
|
4805
|
-
const layout = el.maskLayout();
|
|
4806
|
-
const digitsFor = (mm, dd, yyyy) => {
|
|
4807
|
-
const map = { month: mm, day: dd, year: yyyy };
|
|
4808
|
-
const idx = { month: 0, day: 0, year: 0 };
|
|
4809
|
-
return layout.slots.map((s) => (s.kind in map ? map[s.kind][idx[s.kind]++] : '0'));
|
|
4810
|
-
};
|
|
4811
|
-
const cal = el.calendarElement;
|
|
4812
|
-
const run = async (mm, dd, yyyy) => {
|
|
4813
|
-
el.maskValues = digitsFor(mm, dd, yyyy);
|
|
4814
|
-
el.syncCalendarFromMask();
|
|
4815
|
-
await settle(el);
|
|
4816
|
-
};
|
|
4817
|
-
await run('06', '15', '0050');
|
|
4818
|
-
expect(cal.value.getFullYear(), 'year').to.equal(50);
|
|
4819
|
-
expect(cal.value.getMonth(), 'month').to.equal(5);
|
|
4820
|
-
expect(cal.value.getDate(), 'day').to.equal(15);
|
|
4821
|
-
await run('02', '29', '0000');
|
|
4822
|
-
expect(cal.value.getFullYear(), 'year 0').to.equal(0);
|
|
4823
|
-
expect(cal.value.getDate(), 'Feb 29 exists in year 0 (leap)').to.equal(29);
|
|
4824
|
-
await run('02', '29', '0100');
|
|
4825
|
-
expect(cal.value.getFullYear(), 'year 100 unchanged').to.equal(100);
|
|
4826
|
-
expect(cal.value.getDate(), 'year 100 is not leap: clamps to 28').to.equal(28);
|
|
4827
|
-
}).timeout(60000);
|
|
4828
|
-
});
|
|
4829
|
-
describe('Y10. YYYY display in years 0-99 (picker input)', () => {
|
|
4830
|
-
const wall = (year, month = 6, day = 15) => ({ year, month, day, hours: 12, minutes: 30, seconds: 15, ms: 250 });
|
|
4831
|
-
it('Y10a. formatYear4 pads only years 0-99', () => {
|
|
4832
|
-
expect([0, 1, 50, 99].map(formatYear4)).to.deep.equal(['0000', '0001', '0050', '0099']);
|
|
4833
|
-
for (const y of [100, 999, 1000, 2000, 9999, 10000])
|
|
4834
|
-
expect(formatYear4(y)).to.equal(String(y));
|
|
4835
|
-
});
|
|
4836
|
-
it('Y10b. formatDatePartFields pads YYYY for 0-999, keeps >= 1000, and leaves YY alone', async () => {
|
|
4837
|
-
const el = await makePicker({});
|
|
4838
|
-
el.dateFormat = 'DD/MM/YYYY';
|
|
4839
|
-
expect(el.formatDatePartFields(wall(50))).to.equal('15/06/0050');
|
|
4840
|
-
expect(el.formatDatePartFields(wall(0, 2, 29))).to.equal('29/02/0000');
|
|
4841
|
-
expect(el.formatDatePartFields(wall(1))).to.equal('15/06/0001');
|
|
4842
|
-
expect(el.formatDatePartFields(wall(99))).to.equal('15/06/0099');
|
|
4843
|
-
expect(el.formatDatePartFields(wall(100)), 'the mask has four year slots, so 100-999 are padded too').to.equal('15/06/0100');
|
|
4844
|
-
expect(el.formatDatePartFields(wall(999))).to.equal('15/06/0999');
|
|
4845
|
-
expect(el.formatDatePartFields(wall(1000))).to.equal('15/06/1000');
|
|
4846
|
-
expect(el.formatDatePartFields(wall(2026))).to.equal('15/06/2026');
|
|
4847
|
-
el.dateFormat = 'DD/MM/YY';
|
|
4848
|
-
expect(el.formatDatePartFields(wall(1)), 'YY is always two characters (Y18)').to.equal('15/06/01');
|
|
4849
|
-
expect(el.formatDatePartFields(wall(50))).to.equal('15/06/50');
|
|
4850
|
-
expect(el.formatDatePartFields(wall(2026))).to.equal('15/06/26');
|
|
4851
|
-
}).timeout(60000);
|
|
4852
|
-
it('Y10c. the trigger input shows a year-0050 value as 0050 with time and timezone, and year 2026 is unchanged', async () => {
|
|
4853
|
-
for (const [raw, shown] of [
|
|
4854
|
-
['0050-06-15T12:30:15.250Z', '0050-06-15 - 12:30:15.250 - UTC'],
|
|
4855
|
-
['2026-06-15T12:30:15.250Z', '2026-06-15 - 12:30:15.250 - UTC'],
|
|
4856
|
-
]) {
|
|
4857
|
-
const el = await fixture(html `<nile-date-time-picker .dateFormat=${'YYYY-MM-DD'} .timezone=${'UTC'} .value=${raw}></nile-date-time-picker>`);
|
|
4858
|
-
await settle(el);
|
|
4859
|
-
expect(el.shadowRoot.querySelector('nile-input').value, raw).to.equal(shown);
|
|
4860
|
-
}
|
|
4861
|
-
}).timeout(60000);
|
|
4862
|
-
it('Y10d. typed 0050 -> mask -> calendar -> display round-trips as 0050 (year 50, not 1950)', async () => {
|
|
4863
|
-
const el = await makePicker({});
|
|
4864
|
-
el.dateFormat = 'DD/MM/YYYY';
|
|
4865
|
-
await settle(el);
|
|
4866
|
-
const layout = el.maskLayout();
|
|
4867
|
-
const map = { month: '06', day: '15', year: '0050' };
|
|
4868
|
-
const idx = { month: 0, day: 0, year: 0 };
|
|
4869
|
-
el.maskValues = layout.slots.map((s) => (s.kind in map ? map[s.kind][idx[s.kind]++] : '0'));
|
|
4870
|
-
el.syncCalendarFromMask();
|
|
4871
|
-
await settle(el);
|
|
4872
|
-
const cal = el.calendarElement;
|
|
4873
|
-
expect(cal.value.getFullYear()).to.equal(50);
|
|
4874
|
-
expect(cal.formatDate(cal.value)).to.equal('15/06/0050');
|
|
4875
|
-
}).timeout(60000);
|
|
4876
|
-
});
|
|
4877
|
-
describe('Y11. years 0-999 in the picker input: four-digit display and a stable focus/blur round trip', () => {
|
|
4878
|
-
const FORMATS = [
|
|
4879
|
-
['YYYY-MM-DD', y => `${y}-06-15`],
|
|
4880
|
-
['MM/DD/YYYY', y => `06/15/${y}`],
|
|
4881
|
-
['DD/MM/YYYY', y => `15/06/${y}`],
|
|
4882
|
-
];
|
|
4883
|
-
const YEARS = ['0001', '0050', '0099', '0100', '0999', '1000', '2026'];
|
|
4884
|
-
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
4885
|
-
const make = async (format, year) => {
|
|
4886
|
-
const el = await fixture(html `<nile-date-time-picker
|
|
4887
|
-
.timezone=${'UTC'} dateFormat=${format} .startYear=${0} .endYear=${9999}
|
|
4888
|
-
.hideTimeFields=${DATE_ONLY} value=${`${year}-06-15T10:20:30[GMT+00:00 UTC]`}></nile-date-time-picker>`);
|
|
4889
|
-
await settle2(el);
|
|
4890
|
-
return el;
|
|
4891
|
-
};
|
|
4892
|
-
const textOf = (el) => el.shadowRoot.querySelector('nile-input').input.value;
|
|
4893
|
-
const calDay = (el) => {
|
|
4894
|
-
const c = el.calendarElement;
|
|
4895
|
-
return [c.value.getFullYear(), c.value.getMonth(), c.value.getDate(), c.currentYear, c.currentMonth];
|
|
4896
|
-
};
|
|
4897
|
-
const focusBlur = async (el) => {
|
|
4898
|
-
const ni = el.shadowRoot.querySelector('nile-input');
|
|
4899
|
-
ni.input.focus();
|
|
4900
|
-
ni.dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
4901
|
-
await settle2(el);
|
|
4902
|
-
};
|
|
4903
|
-
for (const [format, expectText] of FORMATS) {
|
|
4904
|
-
for (const year of YEARS) {
|
|
4905
|
-
it(`Y11 [${format}] year ${year}: four-digit text, and focus/blur x3 leaves text, calendar and value untouched`, async () => {
|
|
4906
|
-
const el = await make(format, year);
|
|
4907
|
-
const n = Number(year);
|
|
4908
|
-
expect(textOf(el), 'seeded text').to.equal(expectText(year));
|
|
4909
|
-
const before = calDay(el);
|
|
4910
|
-
expect(before, 'seeded calendar').to.deep.equal([n, 5, 15, n, 5]);
|
|
4911
|
-
const valueBefore = el.value;
|
|
4912
|
-
let emitted = 0;
|
|
4913
|
-
el.addEventListener('nile-change', () => { emitted++; });
|
|
4914
|
-
el.addEventListener('nile-changed', () => { emitted++; });
|
|
4915
|
-
for (let i = 0; i < 3; i++) {
|
|
4916
|
-
await focusBlur(el);
|
|
4917
|
-
expect(textOf(el), `text after cycle ${i + 1}`).to.equal(expectText(year));
|
|
4918
|
-
expect(calDay(el), `calendar after cycle ${i + 1}`).to.deep.equal(before);
|
|
4919
|
-
}
|
|
4920
|
-
expect(el.value, 'value untouched').to.equal(valueBefore);
|
|
4921
|
-
expect(emitted, 'no change event from focus/blur').to.equal(0);
|
|
4922
|
-
}).timeout(60000);
|
|
4923
|
-
}
|
|
4924
|
-
}
|
|
4925
|
-
});
|
|
4926
|
-
describe('Y12. typed dates are clamped to the allowedDates range (user edits only)', () => {
|
|
4927
|
-
const DMY = 'DD/MM/YYYY';
|
|
4928
|
-
const make = async (range, value, tz = 'UTC') => {
|
|
4929
|
-
const el = await fixture(html `<nile-date-time-picker
|
|
4930
|
-
.timezone=${tz} dateFormat=${DMY} .startYear=${0} .endYear=${9999}
|
|
4931
|
-
.allowedDates=${range ? JSON.stringify({ startDate: range[0], endDate: range[1] }) : JSON.stringify({})}
|
|
4932
|
-
value=${value}></nile-date-time-picker>`);
|
|
4933
|
-
await settle2(el);
|
|
4934
|
-
return el;
|
|
4935
|
-
};
|
|
4936
|
-
const inputOf = (el) => el.shadowRoot.querySelector('nile-input');
|
|
4937
|
-
const nativeOf = (el) => inputOf(el).input;
|
|
4938
|
-
const press = (el, key) => inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, composed: true, cancelable: true }));
|
|
4939
|
-
const textOf = (el) => nativeOf(el).value;
|
|
4940
|
-
/** select the DD/MM/YYYY text, delete it, and type a fresh date digit by digit */
|
|
4941
|
-
const typeDate = async (el, ddmmyyyy) => {
|
|
4942
|
-
nativeOf(el).setSelectionRange(0, 10);
|
|
4943
|
-
press(el, 'Backspace');
|
|
4944
|
-
for (const ch of ddmmyyyy)
|
|
4945
|
-
press(el, ch);
|
|
4946
|
-
await settle2(el);
|
|
4947
|
-
};
|
|
4948
|
-
const calDate = (el) => {
|
|
4949
|
-
const c = el.calendarElement;
|
|
4950
|
-
return [c.value.getFullYear(), c.value.getMonth() + 1, c.value.getDate()];
|
|
4951
|
-
};
|
|
4952
|
-
const focusBlur = async (el) => {
|
|
4953
|
-
inputOf(el).input.focus();
|
|
4954
|
-
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
4955
|
-
await settle2(el);
|
|
4956
|
-
};
|
|
4957
|
-
const applyAndCount = async (el) => {
|
|
4958
|
-
const cal = el.calendarElement;
|
|
4959
|
-
const events = [];
|
|
4960
|
-
const details = [];
|
|
4961
|
-
for (const n of ['nile-change']) {
|
|
4962
|
-
el.addEventListener(n, (e) => { events.push(n); details.push(e.detail); });
|
|
4963
|
-
}
|
|
4964
|
-
cal.shadowRoot.querySelector('.apply-button').click();
|
|
4965
|
-
await settle2(el);
|
|
4966
|
-
return { events, details };
|
|
4967
|
-
};
|
|
4968
|
-
const SEED = '2026-06-15T10:20:30.250[GMT+00:00 UTC]';
|
|
4969
|
-
const JUNE = ['2026-06-10', '2026-06-20'];
|
|
4970
|
-
const CASES = [
|
|
4971
|
-
['before range', JUNE, '05062026', '10/06/2026', '2026-06-10'],
|
|
4972
|
-
['lower boundary', JUNE, '10062026', '10/06/2026', '2026-06-10'],
|
|
4973
|
-
['inside range', JUNE, '15062026', '15/06/2026', '2026-06-15'],
|
|
4974
|
-
['upper boundary', JUNE, '20062026', '20/06/2026', '2026-06-20'],
|
|
4975
|
-
['after range', JUNE, '25062026', '20/06/2026', '2026-06-20'],
|
|
4976
|
-
['month boundary, before', ['2026-12-29', '2027-01-03'], '28122026', '29/12/2026', '2026-12-29'],
|
|
4977
|
-
['year boundary, after', ['2026-12-29', '2027-01-03'], '04012027', '03/01/2027', '2027-01-03'],
|
|
4978
|
-
['year boundary, inside', ['2026-12-29', '2027-01-03'], '01012027', '01/01/2027', '2027-01-01'],
|
|
4979
|
-
['leap: before 28 Feb', ['2024-02-28', '2024-03-01'], '27022024', '28/02/2024', '2024-02-28'],
|
|
4980
|
-
['leap: 29 Feb is inside', ['2024-02-28', '2024-03-01'], '29022024', '29/02/2024', '2024-02-29'],
|
|
4981
|
-
['leap: after 1 Mar', ['2024-02-28', '2024-03-01'], '02032024', '01/03/2024', '2024-03-01'],
|
|
4982
|
-
['non-leap: before 27 Feb', ['2023-02-27', '2023-03-02'], '26022023', '27/02/2023', '2023-02-27'],
|
|
4983
|
-
['non-leap: after 2 Mar', ['2023-02-27', '2023-03-02'], '03032023', '02/03/2023', '2023-03-02'],
|
|
4984
|
-
];
|
|
4985
|
-
for (const [name, range, typed, text, iso] of CASES) {
|
|
4986
|
-
it(`Y12 ${name}: typing ${typed} gives ${text}; trigger, calendar and Apply agree, time and zone kept`, async () => {
|
|
4987
|
-
const el = await make(range, SEED);
|
|
4988
|
-
await typeDate(el, typed);
|
|
4989
|
-
const [y, m, d] = iso.split('-').map(Number);
|
|
4990
|
-
expect(textOf(el).slice(0, 10), 'trigger').to.equal(text);
|
|
4991
|
-
expect(calDate(el), 'calendar').to.deep.equal([y, m, d]);
|
|
4992
|
-
expect(el.calendarElement.timezone).to.equal('UTC');
|
|
4993
|
-
const { events, details } = await applyAndCount(el);
|
|
4994
|
-
expect([...events].sort(), 'exactly one change event').to.deep.equal(['nile-change']);
|
|
4995
|
-
expect(details[0].value, 'emitted value').to.equal(`${iso}T10:20:30.250[GMT+00:00 UTC]`);
|
|
4996
|
-
const typedIso = `${typed.slice(4)}-${typed.slice(2, 4)}-${typed.slice(0, 2)}`;
|
|
4997
|
-
if (typedIso !== iso)
|
|
4998
|
-
expect(details[0].value, 'disallowed date never committed').to.not.contain(typedIso);
|
|
4999
|
-
}).timeout(60000);
|
|
5000
|
-
}
|
|
5001
|
-
it('Y12 preserves a non-UTC zone and time of day while clamping', async () => {
|
|
5002
|
-
const el = await make(JUNE, '2026-06-15T23:45:10.005[GMT+05:30 Asia/Kolkata]', 'Asia/Kolkata');
|
|
5003
|
-
await typeDate(el, '25062026');
|
|
5004
|
-
expect(textOf(el).slice(0, 10)).to.equal('20/06/2026');
|
|
5005
|
-
expect(el.calendarElement.timezone).to.equal('Asia/Kolkata');
|
|
5006
|
-
const { details } = await applyAndCount(el);
|
|
5007
|
-
expect(details[0].value).to.equal('2026-06-20T23:45:10.005[GMT+05:30 Asia/Kolkata]');
|
|
5008
|
-
}).timeout(60000);
|
|
5009
|
-
it('Y12 focus/blur x3 after a clamp does not change the date again and emits nothing', async () => {
|
|
5010
|
-
const el = await make(JUNE, SEED);
|
|
5011
|
-
await typeDate(el, '25062026');
|
|
5012
|
-
const text = textOf(el);
|
|
5013
|
-
const cal = calDate(el);
|
|
5014
|
-
let emitted = 0;
|
|
5015
|
-
el.addEventListener('nile-change', () => { emitted++; });
|
|
5016
|
-
el.addEventListener('nile-changed', () => { emitted++; });
|
|
5017
|
-
for (let i = 0; i < 3; i++) {
|
|
5018
|
-
await focusBlur(el);
|
|
5019
|
-
expect(textOf(el), `text ${i + 1}`).to.equal(text);
|
|
5020
|
-
expect(calDate(el), `calendar ${i + 1}`).to.deep.equal(cal);
|
|
5021
|
-
}
|
|
5022
|
-
expect(emitted).to.equal(0);
|
|
5023
|
-
}).timeout(60000);
|
|
5024
|
-
it('Y12 a programmatic value outside the range is not clamped by focus/blur', async () => {
|
|
5025
|
-
const el = await make(JUNE, '2026-06-25T10:20:30.250[GMT+00:00 UTC]');
|
|
5026
|
-
const text = textOf(el);
|
|
5027
|
-
const cal = calDate(el);
|
|
5028
|
-
const value = el.value;
|
|
5029
|
-
let emitted = 0;
|
|
5030
|
-
el.addEventListener('nile-change', () => { emitted++; });
|
|
5031
|
-
el.addEventListener('nile-changed', () => { emitted++; });
|
|
5032
|
-
for (let i = 0; i < 3; i++) {
|
|
5033
|
-
await focusBlur(el);
|
|
5034
|
-
expect(textOf(el)).to.equal(text);
|
|
5035
|
-
expect(calDate(el)).to.deep.equal(cal);
|
|
5036
|
-
}
|
|
5037
|
-
expect(text.slice(0, 10)).to.equal('25/06/2026');
|
|
5038
|
-
expect(el.value).to.equal(value);
|
|
5039
|
-
expect(emitted).to.equal(0);
|
|
5040
|
-
}).timeout(60000);
|
|
5041
|
-
it('Y12 without allowedDates a typed date is never clamped', async () => {
|
|
5042
|
-
const el = await make(null, SEED);
|
|
5043
|
-
await typeDate(el, '25062026');
|
|
5044
|
-
expect(textOf(el).slice(0, 10)).to.equal('25/06/2026');
|
|
5045
|
-
expect(calDate(el)).to.deep.equal([2026, 6, 25]);
|
|
5046
|
-
}).timeout(60000);
|
|
5047
|
-
});
|
|
5048
|
-
describe('Y13. changing dateFormat / hideTimeFields after render redraws the trigger from the committed value', () => {
|
|
5049
|
-
const ALL_TIME = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
5050
|
-
const SEED = '2026-06-15T10:20:30.250[GMT+05:30 Asia/Kolkata]';
|
|
5051
|
-
const make = async (extra = {}) => {
|
|
5052
|
-
const el = await fixture(html `<nile-date-time-picker
|
|
5053
|
-
timezone="Asia/Kolkata" dateFormat="DD/MM/YYYY" .startYear=${0} .endYear=${9999}
|
|
5054
|
-
.allowedDates=${extra.allowed ? JSON.stringify({ startDate: extra.allowed[0], endDate: extra.allowed[1] }) : JSON.stringify({})}
|
|
5055
|
-
value=${SEED}></nile-date-time-picker>`);
|
|
5056
|
-
await settle2(el);
|
|
5057
|
-
return el;
|
|
5058
|
-
};
|
|
5059
|
-
const inputOf = (el) => el.shadowRoot.querySelector('nile-input');
|
|
5060
|
-
const nativeOf = (el) => inputOf(el).input;
|
|
5061
|
-
const press = (el, key) => inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, composed: true, cancelable: true }));
|
|
5062
|
-
const textOf = (el) => nativeOf(el).value;
|
|
5063
|
-
const calDate = (el) => {
|
|
5064
|
-
const c = el.calendarElement;
|
|
5065
|
-
return [c.value.getFullYear(), c.value.getMonth() + 1, c.value.getDate()];
|
|
5066
|
-
};
|
|
5067
|
-
const focusBlur = async (el) => {
|
|
5068
|
-
inputOf(el).input.focus();
|
|
5069
|
-
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
5070
|
-
await settle2(el);
|
|
5071
|
-
};
|
|
5072
|
-
const watch = (el) => {
|
|
5073
|
-
const seen = [];
|
|
5074
|
-
for (const n of ['nile-change', 'nile-changed', 'nile-type-change'])
|
|
5075
|
-
el.addEventListener(n, () => seen.push(n));
|
|
5076
|
-
return seen;
|
|
5077
|
-
};
|
|
5078
|
-
const apply = async (el) => {
|
|
5079
|
-
el.calendarElement.shadowRoot.querySelector('.apply-button').click();
|
|
5080
|
-
await settle2(el);
|
|
5081
|
-
};
|
|
5082
|
-
it('Y13 DD/MM/YYYY -> YYYY-MM-DD -> back keeps the date, time and zone', async () => {
|
|
5083
|
-
const el = await make();
|
|
5084
|
-
const value = el.value;
|
|
5085
|
-
const seen = watch(el);
|
|
5086
|
-
expect(textOf(el).startsWith('15/06/2026')).to.be.true;
|
|
5087
|
-
el.dateFormat = 'YYYY-MM-DD';
|
|
5088
|
-
await settle2(el);
|
|
5089
|
-
expect(textOf(el).startsWith('2026-06-15')).to.be.true;
|
|
5090
|
-
expect(textOf(el)).to.contain('10:20:30.250').and.to.contain('Asia/Kolkata');
|
|
5091
|
-
el.dateFormat = 'DD/MM/YYYY';
|
|
5092
|
-
await settle2(el);
|
|
5093
|
-
expect(textOf(el).startsWith('15/06/2026')).to.be.true;
|
|
5094
|
-
expect(el.value).to.equal(value);
|
|
5095
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
5096
|
-
expect(calDate(el)).to.deep.equal([2026, 6, 15]);
|
|
5097
|
-
expect(seen).to.deep.equal([]);
|
|
5098
|
-
}).timeout(60000);
|
|
5099
|
-
it('Y13 hideTimeFields hides then restores time and zone without losing them', async () => {
|
|
5100
|
-
const el = await make();
|
|
5101
|
-
const value = el.value;
|
|
5102
|
-
const seen = watch(el);
|
|
5103
|
-
el.hideTimeFields = ALL_TIME;
|
|
5104
|
-
await settle2(el);
|
|
5105
|
-
expect(textOf(el)).to.equal('15/06/2026');
|
|
5106
|
-
el.hideTimeFields = [];
|
|
5107
|
-
await settle2(el);
|
|
5108
|
-
expect(textOf(el)).to.contain('10:20:30.250').and.to.contain('Asia/Kolkata');
|
|
5109
|
-
expect(el.value).to.equal(value);
|
|
5110
|
-
expect(seen).to.deep.equal([]);
|
|
5111
|
-
}).timeout(60000);
|
|
5112
|
-
it('Y13 both properties changed in one update give one consistent trigger', async () => {
|
|
5113
|
-
const el = await make();
|
|
5114
|
-
const value = el.value;
|
|
5115
|
-
el.dateFormat = 'YYYY-MM-DD';
|
|
5116
|
-
el.hideTimeFields = ALL_TIME;
|
|
5117
|
-
await settle2(el);
|
|
5118
|
-
expect(textOf(el)).to.equal('2026-06-15');
|
|
5119
|
-
el.dateFormat = 'DD/MM/YYYY';
|
|
5120
|
-
el.hideTimeFields = [];
|
|
5121
|
-
await settle2(el);
|
|
5122
|
-
expect(textOf(el)).to.contain('15/06/2026').and.to.contain('10:20:30.250').and.to.contain('Asia/Kolkata');
|
|
5123
|
-
expect(el.value).to.equal(value);
|
|
5124
|
-
}).timeout(60000);
|
|
5125
|
-
it('Y13 focus/blur after each change does not corrupt the date, time or zone', async () => {
|
|
5126
|
-
const el = await make();
|
|
5127
|
-
const value = el.value;
|
|
5128
|
-
const seen = watch(el);
|
|
5129
|
-
for (const [fmt, hide] of [['YYYY-MM-DD', []], ['YYYY-MM-DD', ALL_TIME], ['DD/MM/YYYY', ALL_TIME], ['DD/MM/YYYY', []]]) {
|
|
5130
|
-
el.dateFormat = fmt;
|
|
5131
|
-
el.hideTimeFields = hide;
|
|
5132
|
-
await settle2(el);
|
|
5133
|
-
const text = textOf(el);
|
|
5134
|
-
for (let i = 0; i < 2; i++) {
|
|
5135
|
-
await focusBlur(el);
|
|
5136
|
-
expect(textOf(el), `${fmt} ${hide.length}`).to.equal(text);
|
|
5137
|
-
}
|
|
5138
|
-
expect(el.value).to.equal(value);
|
|
5139
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
5140
|
-
expect(calDate(el)).to.deep.equal([2026, 6, 15]);
|
|
5141
|
-
}
|
|
5142
|
-
expect(seen).to.deep.equal([]);
|
|
5143
|
-
}).timeout(60000);
|
|
5144
|
-
it('Y13 an uncommitted draft is discarded and the committed value is redrawn', async () => {
|
|
5145
|
-
const el = await make();
|
|
5146
|
-
const value = el.value;
|
|
5147
|
-
nativeOf(el).setSelectionRange(0, 10);
|
|
5148
|
-
press(el, 'Backspace');
|
|
5149
|
-
for (const ch of '01012030')
|
|
5150
|
-
press(el, ch);
|
|
5151
|
-
await settle2(el);
|
|
5152
|
-
expect(textOf(el).startsWith('01/01/2030')).to.be.true;
|
|
5153
|
-
const seen = watch(el);
|
|
5154
|
-
el.dateFormat = 'YYYY-MM-DD';
|
|
5155
|
-
await settle2(el);
|
|
5156
|
-
expect(textOf(el).startsWith('2026-06-15')).to.be.true;
|
|
5157
|
-
await focusBlur(el);
|
|
5158
|
-
expect(textOf(el).startsWith('2026-06-15')).to.be.true;
|
|
5159
|
-
expect(el.value).to.equal(value);
|
|
5160
|
-
expect(seen).to.deep.equal([]);
|
|
5161
|
-
}).timeout(60000);
|
|
5162
|
-
it('Y13 repeated toggles do not drift', async () => {
|
|
5163
|
-
const el = await make();
|
|
5164
|
-
const value = el.value;
|
|
5165
|
-
const first = textOf(el);
|
|
5166
|
-
for (let i = 0; i < 4; i++) {
|
|
5167
|
-
el.dateFormat = 'YYYY-MM-DD';
|
|
5168
|
-
el.hideTimeFields = ALL_TIME;
|
|
5169
|
-
await settle2(el);
|
|
5170
|
-
el.dateFormat = 'DD/MM/YYYY';
|
|
5171
|
-
el.hideTimeFields = [];
|
|
5172
|
-
await settle2(el);
|
|
5173
|
-
}
|
|
5174
|
-
expect(textOf(el)).to.equal(first);
|
|
5175
|
-
expect(el.value).to.equal(value);
|
|
5176
|
-
}).timeout(60000);
|
|
5177
|
-
it('Y13 a programmatic value after a format change shows in the new format', async () => {
|
|
5178
|
-
const el = await make();
|
|
5179
|
-
el.dateFormat = 'YYYY-MM-DD';
|
|
5180
|
-
await settle2(el);
|
|
5181
|
-
el.value = '2027-03-04T05:06:07.008[GMT+05:30 Asia/Kolkata]';
|
|
5182
|
-
await settle2(el);
|
|
5183
|
-
expect(textOf(el).startsWith('2027-03-04')).to.be.true;
|
|
5184
|
-
await focusBlur(el);
|
|
5185
|
-
expect(textOf(el).startsWith('2027-03-04')).to.be.true;
|
|
5186
|
-
expect(calDate(el)).to.deep.equal([2027, 3, 4]);
|
|
5187
|
-
}).timeout(60000);
|
|
5188
|
-
it('Y13 Apply after a format change emits the committed date once', async () => {
|
|
5189
|
-
const el = await make();
|
|
5190
|
-
el.dateFormat = 'YYYY-MM-DD';
|
|
5191
|
-
await settle2(el);
|
|
5192
|
-
const seen = watch(el);
|
|
5193
|
-
await apply(el);
|
|
5194
|
-
expect(seen).to.deep.equal(['nile-change']);
|
|
5195
|
-
expect(el.value.startsWith('2026-06-15T10:20:30.250')).to.be.true;
|
|
5196
|
-
}).timeout(60000);
|
|
5197
|
-
it('Y13 with no value a format change leaves the trigger empty and emits nothing', async () => {
|
|
5198
|
-
const el = await fixture(html `<nile-date-time-picker dateFormat="DD/MM/YYYY"></nile-date-time-picker>`);
|
|
5199
|
-
await settle2(el);
|
|
5200
|
-
const seen = watch(el);
|
|
5201
|
-
el.dateFormat = 'YYYY-MM-DD';
|
|
5202
|
-
el.hideTimeFields = ALL_TIME;
|
|
5203
|
-
await settle2(el);
|
|
5204
|
-
expect(textOf(el)).to.equal('');
|
|
5205
|
-
expect(el.value ?? '').to.equal('');
|
|
5206
|
-
expect(seen).to.deep.equal([]);
|
|
5207
|
-
}).timeout(60000);
|
|
5208
|
-
it('Y13 a format change that discards a typed draft (no committed value) emits no nile-input', async () => {
|
|
5209
|
-
const el = await fixture(html `<nile-date-time-picker dateFormat="DD/MM/YYYY" .startYear=${0} .endYear=${9999}></nile-date-time-picker>`);
|
|
5210
|
-
await settle2(el);
|
|
5211
|
-
nativeOf(el).setSelectionRange(0, 0);
|
|
5212
|
-
for (const ch of '01012030')
|
|
5213
|
-
press(el, ch);
|
|
5214
|
-
await settle2(el);
|
|
5215
|
-
expect(textOf(el).startsWith('01/01/2030')).to.be.true;
|
|
5216
|
-
const seen = watch(el);
|
|
5217
|
-
let inputs = 0;
|
|
5218
|
-
inputOf(el).addEventListener('nile-input', () => { inputs++; });
|
|
5219
|
-
el.dateFormat = 'YYYY-MM-DD';
|
|
5220
|
-
await settle2(el);
|
|
5221
|
-
el.hideTimeFields = ALL_TIME;
|
|
5222
|
-
await settle2(el);
|
|
5223
|
-
expect(textOf(el)).to.equal('');
|
|
5224
|
-
expect(el.value ?? '').to.equal('');
|
|
5225
|
-
expect(inputs).to.equal(0);
|
|
5226
|
-
expect(seen).to.deep.equal([]);
|
|
5227
|
-
}).timeout(60000);
|
|
5228
|
-
it('Y13 a user Clear still emits nile-input and nile-clear', async () => {
|
|
5229
|
-
const el = await make();
|
|
5230
|
-
let inputs = 0;
|
|
5231
|
-
let clears = 0;
|
|
5232
|
-
inputOf(el).addEventListener('nile-input', () => { inputs++; });
|
|
5233
|
-
el.addEventListener('nile-clear', () => { clears++; });
|
|
5234
|
-
el.handleClear();
|
|
5235
|
-
await settle2(el);
|
|
5236
|
-
expect(inputs).to.equal(1);
|
|
5237
|
-
expect(clears).to.equal(1);
|
|
5238
|
-
}).timeout(60000);
|
|
5239
|
-
it('Y13 relative mode ignores a format change', async () => {
|
|
5240
|
-
const el = await fixture(html `<nile-date-time-picker type="relative" dateFormat="DD/MM/YYYY"></nile-date-time-picker>`);
|
|
5241
|
-
await settle2(el);
|
|
5242
|
-
const before = el.type;
|
|
5243
|
-
el.dateFormat = 'YYYY-MM-DD';
|
|
5244
|
-
el.hideTimeFields = ALL_TIME;
|
|
5245
|
-
await settle2(el);
|
|
5246
|
-
expect(el.type).to.equal(before);
|
|
5247
|
-
expect(el.dateFormat).to.equal('YYYY-MM-DD');
|
|
5248
|
-
}).timeout(60000);
|
|
5249
|
-
it('Y13 allowedDates clamping still works after a format change', async () => {
|
|
5250
|
-
const el = await make({ allowed: ['2026-06-10', '2026-06-20'] });
|
|
5251
|
-
el.dateFormat = 'DD/MM/YYYY';
|
|
5252
|
-
el.hideTimeFields = [];
|
|
5253
|
-
await settle2(el);
|
|
5254
|
-
nativeOf(el).setSelectionRange(0, 10);
|
|
5255
|
-
press(el, 'Backspace');
|
|
5256
|
-
for (const ch of '25062026')
|
|
5257
|
-
press(el, ch);
|
|
5258
|
-
await settle2(el);
|
|
5259
|
-
expect(textOf(el).startsWith('20/06/2026')).to.be.true;
|
|
5260
|
-
expect(calDate(el)).to.deep.equal([2026, 6, 20]);
|
|
5261
|
-
}).timeout(60000);
|
|
5262
|
-
});
|
|
5263
|
-
describe('Y14. switching Relative -> Absolute redraws the trigger from the retained absolute value', () => {
|
|
5264
|
-
const SEED = '2026-06-15T10:20:30.250[GMT+05:30 Asia/Kolkata]';
|
|
5265
|
-
const make = async (withValue = true) => {
|
|
5266
|
-
const el = await fixture(html `<nile-date-time-picker
|
|
5267
|
-
timezone="Asia/Kolkata" dateFormat="DD/MM/YYYY" .startYear=${0} .endYear=${9999}
|
|
5268
|
-
value=${withValue ? SEED : ''}></nile-date-time-picker>`);
|
|
5269
|
-
await settle2(el);
|
|
5270
|
-
return el;
|
|
5271
|
-
};
|
|
5272
|
-
const inputOf = (el) => el.shadowRoot.querySelector('nile-input');
|
|
5273
|
-
const nativeOf = (el) => inputOf(el).input;
|
|
5274
|
-
const textOf = (el) => nativeOf(el).value;
|
|
5275
|
-
const calDate = (el) => {
|
|
5276
|
-
const c = el.calendarElement;
|
|
5277
|
-
return [c.value.getFullYear(), c.value.getMonth() + 1, c.value.getDate()];
|
|
5278
|
-
};
|
|
5279
|
-
const focusBlur = async (el) => {
|
|
5280
|
-
inputOf(el).input.focus();
|
|
5281
|
-
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
5282
|
-
await settle2(el);
|
|
5283
|
-
};
|
|
5284
|
-
/** user-style mode switch: the calendar's tab group fires nile-tab-show */
|
|
5285
|
-
const switchTab = async (el, value) => {
|
|
5286
|
-
const cal = el.calendarElement;
|
|
5287
|
-
cal.shadowRoot.querySelector(`nile-tab[panel="${value}"]`).dispatchEvent(new CustomEvent('nile-tab-show', { detail: { value }, bubbles: true, composed: true }));
|
|
5288
|
-
await settle2(el);
|
|
5289
|
-
};
|
|
5290
|
-
const relativeApply = async (el) => {
|
|
5291
|
-
const cal = el.calendarElement;
|
|
5292
|
-
cal.shadowRoot.querySelector('.duration__value').click();
|
|
5293
|
-
await cal.updateComplete;
|
|
5294
|
-
cal.shadowRoot.querySelector('.apply-button').click();
|
|
5295
|
-
await settle2(el);
|
|
5296
|
-
};
|
|
5297
|
-
const watch = (el) => {
|
|
5298
|
-
const seen = [];
|
|
5299
|
-
for (const n of ['nile-change', 'nile-changed'])
|
|
5300
|
-
el.addEventListener(n, () => seen.push(n));
|
|
5301
|
-
const types = [];
|
|
5302
|
-
el.addEventListener('nile-type-change', (e) => types.push(e.detail?.value));
|
|
5303
|
-
let inputs = 0;
|
|
5304
|
-
inputOf(el).addEventListener('nile-input', () => { inputs++; });
|
|
5305
|
-
return { seen, types, inputs: () => inputs };
|
|
5306
|
-
};
|
|
5307
|
-
it('Y14 Relative -> Absolute restores the retained absolute value, never the relative text', async () => {
|
|
5308
|
-
const el = await make();
|
|
5309
|
-
const value = el.value;
|
|
5310
|
-
await switchTab(el, 'relative');
|
|
5311
|
-
await relativeApply(el);
|
|
5312
|
-
expect(textOf(el)).to.contain(' - ');
|
|
5313
|
-
expect(el.value, 'relative apply leaves value alone').to.equal(value);
|
|
5314
|
-
const w = watch(el);
|
|
5315
|
-
await switchTab(el, 'absolute');
|
|
5316
|
-
expect(el.type).to.equal('absolute');
|
|
5317
|
-
expect(textOf(el).startsWith('15/06/2026')).to.be.true;
|
|
5318
|
-
expect(textOf(el)).to.contain('10:20:30.250').and.to.contain('Asia/Kolkata');
|
|
5319
|
-
expect(el.value).to.equal(value);
|
|
5320
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
5321
|
-
expect(w.seen).to.deep.equal([]);
|
|
5322
|
-
expect(w.inputs()).to.equal(0);
|
|
5323
|
-
expect(w.types).to.deep.equal(['absolute']);
|
|
5324
|
-
}).timeout(60000);
|
|
5325
|
-
it('Y14 with no absolute value the trigger is cleared silently', async () => {
|
|
5326
|
-
const el = await make(false);
|
|
5327
|
-
await switchTab(el, 'relative');
|
|
5328
|
-
await relativeApply(el);
|
|
5329
|
-
expect(textOf(el)).to.contain(' - ');
|
|
5330
|
-
const w = watch(el);
|
|
5331
|
-
await switchTab(el, 'absolute');
|
|
5332
|
-
expect(textOf(el)).to.equal('');
|
|
5333
|
-
expect(el.value ?? '').to.equal('');
|
|
5334
|
-
expect(w.inputs()).to.equal(0);
|
|
5335
|
-
expect(w.seen).to.deep.equal([]);
|
|
5336
|
-
expect(w.types).to.deep.equal(['absolute']);
|
|
5337
|
-
}).timeout(60000);
|
|
5338
|
-
it('Y14 focus/blur after returning to Absolute does not corrupt date, time or zone', async () => {
|
|
5339
|
-
const el = await make();
|
|
5340
|
-
const value = el.value;
|
|
5341
|
-
await switchTab(el, 'relative');
|
|
5342
|
-
await relativeApply(el);
|
|
5343
|
-
await switchTab(el, 'absolute');
|
|
5344
|
-
const text = textOf(el);
|
|
5345
|
-
for (let i = 0; i < 3; i++) {
|
|
5346
|
-
await focusBlur(el);
|
|
5347
|
-
expect(textOf(el), `blur ${i + 1}`).to.equal(text);
|
|
5348
|
-
}
|
|
5349
|
-
expect(el.value).to.equal(value);
|
|
5350
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
5351
|
-
expect(calDate(el)).to.deep.equal([2026, 6, 15]);
|
|
5352
|
-
expect(el.maskValues.length).to.be.greaterThan(0);
|
|
5353
|
-
}).timeout(60000);
|
|
5354
|
-
it('Y14 with no absolute value, focus/blur after returning leaves the trigger empty', async () => {
|
|
5355
|
-
const el = await make(false);
|
|
5356
|
-
await switchTab(el, 'relative');
|
|
5357
|
-
await relativeApply(el);
|
|
5358
|
-
await switchTab(el, 'absolute');
|
|
5359
|
-
await focusBlur(el);
|
|
5360
|
-
expect(textOf(el)).to.equal('');
|
|
5361
|
-
expect(el.value ?? '').to.equal('');
|
|
5362
|
-
}).timeout(60000);
|
|
5363
|
-
it('Y14 Absolute -> Relative -> Absolute and repeated switching show no stale text', async () => {
|
|
5364
|
-
const el = await make();
|
|
5365
|
-
const first = textOf(el);
|
|
5366
|
-
const w = watch(el);
|
|
5367
|
-
for (let i = 0; i < 3; i++) {
|
|
5368
|
-
await switchTab(el, 'relative');
|
|
5369
|
-
expect(el.type).to.equal('relative');
|
|
5370
|
-
await switchTab(el, 'absolute');
|
|
5371
|
-
expect(textOf(el), `round ${i + 1}`).to.equal(first);
|
|
5372
|
-
expect(textOf(el)).to.not.contain(' - Asia/Kolkata - ');
|
|
5373
|
-
}
|
|
5374
|
-
expect(w.types).to.deep.equal(['relative', 'absolute', 'relative', 'absolute', 'relative', 'absolute']);
|
|
5375
|
-
expect(w.seen).to.deep.equal([]);
|
|
5376
|
-
expect(w.inputs()).to.equal(0);
|
|
5377
|
-
}).timeout(60000);
|
|
5378
|
-
it('Y14 a programmatic type change back to Absolute also redraws', async () => {
|
|
5379
|
-
const el = await make();
|
|
5380
|
-
const first = textOf(el);
|
|
5381
|
-
el.type = 'relative';
|
|
5382
|
-
await settle2(el);
|
|
5383
|
-
await relativeApply(el);
|
|
5384
|
-
el.type = 'absolute';
|
|
5385
|
-
await settle2(el);
|
|
5386
|
-
expect(textOf(el)).to.equal(first);
|
|
5387
|
-
}).timeout(60000);
|
|
5388
|
-
it('Y14 Absolute -> Relative does not change the absolute value', async () => {
|
|
5389
|
-
const el = await make();
|
|
5390
|
-
const value = el.value;
|
|
5391
|
-
await switchTab(el, 'relative');
|
|
5392
|
-
expect(el.value).to.equal(value);
|
|
5393
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
5394
|
-
}).timeout(60000);
|
|
5395
|
-
it('Y14 Absolute Apply and Relative Apply still work after switching back and forth', async () => {
|
|
5396
|
-
const el = await make();
|
|
5397
|
-
await switchTab(el, 'relative');
|
|
5398
|
-
let relative = null;
|
|
5399
|
-
el.addEventListener('nile-change', ((e) => { relative = e.detail; }));
|
|
5400
|
-
await relativeApply(el);
|
|
5401
|
-
expect(relative?.startDate, 'relative apply emits a range').to.exist;
|
|
5402
|
-
await switchTab(el, 'absolute');
|
|
5403
|
-
const events = [];
|
|
5404
|
-
let detail = null;
|
|
5405
|
-
for (const n of ['nile-change', 'nile-changed'])
|
|
5406
|
-
el.addEventListener(n, (e) => { events.push(n); detail = e.detail; });
|
|
5407
|
-
el.calendarElement.shadowRoot.querySelector('.apply-button').click();
|
|
5408
|
-
await settle2(el);
|
|
5409
|
-
expect(events).to.deep.equal(['nile-change']);
|
|
5410
|
-
expect(detail.value.startsWith('2026-06-15T10:20:30.250')).to.be.true;
|
|
5411
|
-
expect(el.value.startsWith('2026-06-15T10:20:30.250')).to.be.true;
|
|
5412
|
-
}).timeout(60000);
|
|
5413
|
-
it('Y14 dateFormat and hideTimeFields updates still work after returning to Absolute', async () => {
|
|
5414
|
-
const el = await make();
|
|
5415
|
-
await switchTab(el, 'relative');
|
|
5416
|
-
await relativeApply(el);
|
|
5417
|
-
await switchTab(el, 'absolute');
|
|
5418
|
-
el.dateFormat = 'YYYY-MM-DD';
|
|
5419
|
-
el.hideTimeFields = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
5420
|
-
await settle2(el);
|
|
5421
|
-
expect(textOf(el)).to.equal('2026-06-15');
|
|
5422
|
-
el.hideTimeFields = [];
|
|
5423
|
-
el.dateFormat = 'DD/MM/YYYY';
|
|
5424
|
-
await settle2(el);
|
|
5425
|
-
expect(textOf(el).startsWith('15/06/2026')).to.be.true;
|
|
5426
|
-
}).timeout(60000);
|
|
5427
|
-
});
|
|
5428
|
-
describe('Y15. focus/blur never clamps a seeded year outside the default startYear/endYear range', () => {
|
|
5429
|
-
// no .startYear/.endYear here on purpose: the default navigation range (2000-2050) is what used to clamp the seed
|
|
5430
|
-
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
5431
|
-
const make = async (year, format = 'DD/MM/YYYY') => {
|
|
5432
|
-
const el = await fixture(html `<nile-date-time-picker
|
|
5433
|
-
.timezone=${'UTC'} dateFormat=${format} .hideTimeFields=${DATE_ONLY}
|
|
5434
|
-
value=${`${year}-06-15T10:20:30[GMT+00:00 UTC]`}></nile-date-time-picker>`);
|
|
5435
|
-
await settle2(el);
|
|
5436
|
-
return el;
|
|
5437
|
-
};
|
|
5438
|
-
const inputOf = (el) => el.shadowRoot.querySelector('nile-input');
|
|
5439
|
-
const textOf = (el) => inputOf(el).input.value;
|
|
5440
|
-
const calState = (el) => {
|
|
5441
|
-
const c = el.calendarElement;
|
|
5442
|
-
return [c.value.getFullYear(), c.value.getMonth(), c.value.getDate(), c.currentYear, c.currentMonth];
|
|
5443
|
-
};
|
|
5444
|
-
const focusBlur = async (el) => {
|
|
5445
|
-
inputOf(el).input.focus();
|
|
5446
|
-
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
5447
|
-
await settle2(el);
|
|
5448
|
-
};
|
|
5449
|
-
for (const year of ['0050', '1985', '1999', '2051', '2100', '9999']) {
|
|
5450
|
-
for (const format of ['DD/MM/YYYY', 'YYYY-MM-DD']) {
|
|
5451
|
-
it(`Y15 [${format}] seeded year ${year}: focus/blur x3 leaves text, calendar, value and events untouched`, async () => {
|
|
5452
|
-
const el = await make(year, format);
|
|
5453
|
-
const text = textOf(el);
|
|
5454
|
-
const cal = calState(el);
|
|
5455
|
-
const value = el.value;
|
|
5456
|
-
expect(text, 'seeded text carries the literal year').to.contain(year);
|
|
5457
|
-
expect(cal.slice(0, 1), 'seeded calendar year').to.deep.equal([Number(year)]);
|
|
5458
|
-
let emitted = 0;
|
|
5459
|
-
el.addEventListener('nile-change', () => { emitted++; });
|
|
5460
|
-
el.addEventListener('nile-changed', () => { emitted++; });
|
|
5461
|
-
for (let i = 0; i < 3; i++) {
|
|
5462
|
-
await focusBlur(el);
|
|
5463
|
-
expect(textOf(el), `text after cycle ${i + 1}`).to.equal(text);
|
|
5464
|
-
expect(calState(el), `calendar after cycle ${i + 1}`).to.deep.equal(cal);
|
|
5465
|
-
}
|
|
5466
|
-
expect(el.value, 'value untouched').to.equal(value);
|
|
5467
|
-
expect(emitted, 'no change event from focus/blur').to.equal(0);
|
|
5468
|
-
}).timeout(60000);
|
|
5469
|
-
}
|
|
5470
|
-
}
|
|
5471
|
-
it('Y15 a year the USER types outside the range is still clamped (user edits only)', async () => {
|
|
5472
|
-
const el = await make('2026');
|
|
5473
|
-
const native = inputOf(el).input;
|
|
5474
|
-
native.setSelectionRange(0, 10);
|
|
5475
|
-
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace', bubbles: true, composed: true, cancelable: true }));
|
|
5476
|
-
for (const ch of '15061850') {
|
|
5477
|
-
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key: ch, bubbles: true, composed: true, cancelable: true }));
|
|
5478
|
-
}
|
|
5479
|
-
await settle2(el);
|
|
5480
|
-
await focusBlur(el);
|
|
5481
|
-
expect(textOf(el)).to.equal('15/06/2000');
|
|
5482
|
-
}).timeout(60000);
|
|
5483
|
-
it('Y15 a year the USER types above the range clamps to the range end', async () => {
|
|
5484
|
-
const el = await make('2026');
|
|
5485
|
-
const native = inputOf(el).input;
|
|
5486
|
-
native.setSelectionRange(0, 10);
|
|
5487
|
-
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace', bubbles: true, composed: true, cancelable: true }));
|
|
5488
|
-
for (const ch of '15062100') {
|
|
5489
|
-
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key: ch, bubbles: true, composed: true, cancelable: true }));
|
|
5490
|
-
}
|
|
5491
|
-
await settle2(el);
|
|
5492
|
-
await focusBlur(el);
|
|
5493
|
-
expect(textOf(el)).to.equal('15/06/2050');
|
|
5494
|
-
}).timeout(60000);
|
|
5495
|
-
});
|
|
5496
|
-
describe('Y16. an unparseable value after a valid one does not leave the old selection on screen', () => {
|
|
5497
|
-
const SEED = '2026-06-15T10:20:30.000[GMT+05:30 Asia/Kolkata]';
|
|
5498
|
-
const BAD = ['not-a-date', '2026-13-45T10:00:00', 'garbage[GMT+00:00 UTC]', ' '];
|
|
5499
|
-
const make = async (value = SEED) => {
|
|
5500
|
-
const el = await fixture(html `<nile-date-time-picker
|
|
5501
|
-
timezone="Asia/Kolkata" dateFormat="DD/MM/YYYY" value=${value}></nile-date-time-picker>`);
|
|
5502
|
-
await settle2(el);
|
|
5503
|
-
return el;
|
|
5504
|
-
};
|
|
5505
|
-
const textOf = (el) => el.shadowRoot.querySelector('nile-input').input.value;
|
|
5506
|
-
for (const bad of BAD) {
|
|
5507
|
-
it(`Y16 ${JSON.stringify(bad)}: trigger and calendar empty (as for an invalid initial value), zone and events untouched`, async () => {
|
|
5508
|
-
const el = await make();
|
|
5509
|
-
expect(textOf(el), 'precondition').to.contain('15/06/2026');
|
|
5510
|
-
let changes = 0;
|
|
5511
|
-
el.addEventListener('nile-change', () => { changes++; });
|
|
5512
|
-
el.addEventListener('nile-changed', () => { changes++; });
|
|
5513
|
-
el.value = bad;
|
|
5514
|
-
await settle2(el);
|
|
5515
|
-
expect(textOf(el), 'trigger text').to.equal('');
|
|
5516
|
-
expect(el.calendarElement.value, 'calendar selection').to.equal(null);
|
|
5517
|
-
expect(el.timezone, 'zone is not touched').to.equal('Asia/Kolkata');
|
|
5518
|
-
expect(el.value, 'value is the consumer\'s, never rewritten').to.equal(bad);
|
|
5519
|
-
expect(changes, 'no change event').to.equal(0);
|
|
5520
|
-
// and a later valid value seeds normally
|
|
5521
|
-
el.value = '2027-01-02T03:04:05.000[GMT+05:30 Asia/Kolkata]';
|
|
5522
|
-
await settle2(el);
|
|
5523
|
-
expect(textOf(el)).to.contain('02/01/2027');
|
|
5524
|
-
expect(el.calendarElement.value.getFullYear()).to.equal(2027);
|
|
5525
|
-
}).timeout(60000);
|
|
5526
|
-
}
|
|
5527
|
-
it('Y16 an invalid INITIAL value shows an empty trigger (the behaviour the after-valid case must match)', async () => {
|
|
5528
|
-
const el = await make('not-a-date');
|
|
5529
|
-
expect(textOf(el)).to.equal('');
|
|
5530
|
-
expect(el.calendarElement.value ?? null).to.equal(null);
|
|
5531
|
-
}).timeout(60000);
|
|
5532
|
-
});
|
|
5533
|
-
describe('Y17. focus/blur with a two-digit (YY) format never moves the calendar off a seeded year outside 2000-2099', () => {
|
|
5534
|
-
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
5535
|
-
const make = async (year) => {
|
|
5536
|
-
const el = await fixture(html `<nile-date-time-picker
|
|
5537
|
-
.timezone=${'UTC'} dateFormat="DD/MM/YY" .startYear=${0} .endYear=${9999} .hideTimeFields=${DATE_ONLY}
|
|
5538
|
-
value=${`${year}-06-15T10:20:30[GMT+00:00 UTC]`}></nile-date-time-picker>`);
|
|
5539
|
-
await settle2(el);
|
|
5540
|
-
return el;
|
|
5541
|
-
};
|
|
5542
|
-
const inputOf = (el) => el.shadowRoot.querySelector('nile-input');
|
|
5543
|
-
const calState = (el) => {
|
|
5544
|
-
const c = el.calendarElement;
|
|
5545
|
-
return [c.value.getFullYear(), c.value.getMonth(), c.value.getDate(), c.currentYear, c.currentMonth];
|
|
5546
|
-
};
|
|
5547
|
-
for (const year of ['1985', '2026', '2099', '2100']) {
|
|
5548
|
-
it(`Y17 seeded year ${year}: focus/blur x3 leaves calendar, text, value and events untouched`, async () => {
|
|
5549
|
-
const el = await make(year);
|
|
5550
|
-
const text = inputOf(el).input.value;
|
|
5551
|
-
const cal = calState(el);
|
|
5552
|
-
const value = el.value;
|
|
5553
|
-
let emitted = 0;
|
|
5554
|
-
el.addEventListener('nile-change', () => { emitted++; });
|
|
5555
|
-
for (let i = 0; i < 3; i++) {
|
|
5556
|
-
inputOf(el).input.focus();
|
|
5557
|
-
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
5558
|
-
await settle2(el);
|
|
5559
|
-
expect(calState(el), `calendar after cycle ${i + 1}`).to.deep.equal(cal);
|
|
5560
|
-
expect(inputOf(el).input.value, `text after cycle ${i + 1}`).to.equal(text);
|
|
5561
|
-
}
|
|
5562
|
-
expect(el.value).to.equal(value);
|
|
5563
|
-
expect(emitted).to.equal(0);
|
|
5564
|
-
}).timeout(60000);
|
|
5565
|
-
}
|
|
5566
|
-
});
|
|
5567
|
-
describe('Y18. a YY year is always two characters', () => {
|
|
5568
|
-
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
5569
|
-
for (const [year, yy] of [['0005', '05'], ['0009', '09'], ['0010', '10'], ['2005', '05'], ['2026', '26']]) {
|
|
5570
|
-
it(`Y18 year ${year} renders as ${yy} under DD/MM/YY`, async () => {
|
|
5571
|
-
const el = await fixture(html `<nile-date-time-picker
|
|
5572
|
-
.timezone=${'UTC'} dateFormat="DD/MM/YY" .startYear=${0} .endYear=${9999} .hideTimeFields=${DATE_ONLY}
|
|
5573
|
-
value=${`${year}-06-15T10:20:30[GMT+00:00 UTC]`}></nile-date-time-picker>`);
|
|
5574
|
-
await settle2(el);
|
|
5575
|
-
expect(el.shadowRoot.querySelector('nile-input').input.value).to.equal(`15/06/${yy}`);
|
|
5576
|
-
}).timeout(60000);
|
|
5577
|
-
}
|
|
5578
|
-
});
|
|
5579
|
-
describe('Y19. blur clamps only the segments the user actually edited', () => {
|
|
5580
|
-
// default navigation range (2000-2050) on purpose: every seed below is outside it (1999 and 2051 sit just beyond each end)
|
|
5581
|
-
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
5582
|
-
const make = async (value, format = 'DD/MM/YYYY') => {
|
|
5583
|
-
const el = await fixture(html `<nile-date-time-picker
|
|
5584
|
-
.timezone=${'UTC'} dateFormat=${format} .hideTimeFields=${DATE_ONLY} value=${value}></nile-date-time-picker>`);
|
|
5585
|
-
await settle2(el);
|
|
5586
|
-
return el;
|
|
5587
|
-
};
|
|
5588
|
-
const inputOf = (el) => el.shadowRoot.querySelector('nile-input');
|
|
5589
|
-
const nativeOf = (el) => inputOf(el).input;
|
|
5590
|
-
const press = (el, key) => inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, composed: true, cancelable: true }));
|
|
5591
|
-
const blur = async (el) => {
|
|
5592
|
-
nativeOf(el).focus();
|
|
5593
|
-
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
5594
|
-
await settle2(el);
|
|
5595
|
-
};
|
|
5596
|
-
const calDate = (el) => {
|
|
5597
|
-
const c = el.calendarElement;
|
|
5598
|
-
return [c.value.getFullYear(), c.value.getMonth() + 1, c.value.getDate()];
|
|
5599
|
-
};
|
|
5600
|
-
/** select [from, to) of the text, delete it, and type digits */
|
|
5601
|
-
const retype = async (el, from, to, digits) => {
|
|
5602
|
-
nativeOf(el).setSelectionRange(from, to);
|
|
5603
|
-
press(el, 'Backspace');
|
|
5604
|
-
for (const ch of digits)
|
|
5605
|
-
press(el, ch);
|
|
5606
|
-
await settle2(el);
|
|
5607
|
-
};
|
|
5608
|
-
for (const year of ['1985', '1999', '2051', '2100', '0050']) {
|
|
5609
|
-
it(`Y19 seeded ${year}: editing only the day, then blur, leaves the untouched year alone`, async () => {
|
|
5610
|
-
const el = await make(`${year}-06-15T00:00:00[GMT+00:00 UTC]`);
|
|
5611
|
-
await retype(el, 0, 2, '20');
|
|
5612
|
-
await blur(el);
|
|
5613
|
-
expect(nativeOf(el).value).to.equal(`20/06/${year}`);
|
|
5614
|
-
expect(calDate(el)).to.deep.equal([Number(year), 6, 20]);
|
|
5615
|
-
}).timeout(60000);
|
|
5616
|
-
it(`Y19 seeded ${year}: editing only the month, then blur, leaves the untouched year alone`, async () => {
|
|
5617
|
-
const el = await make(`${year}-06-15T00:00:00[GMT+00:00 UTC]`);
|
|
5618
|
-
await retype(el, 3, 5, '08');
|
|
5619
|
-
await blur(el);
|
|
5620
|
-
expect(nativeOf(el).value).to.equal(`15/08/${year}`);
|
|
5621
|
-
expect(calDate(el)).to.deep.equal([Number(year), 8, 15]);
|
|
5622
|
-
}).timeout(60000);
|
|
5623
|
-
}
|
|
5624
|
-
// the approved default range is 2000-2050: a year the user completes is clamped into it, a year inside it is kept
|
|
5625
|
-
for (const [typed, expected, why] of [
|
|
5626
|
-
['1990', '2000', 'below the range → 2000'],
|
|
5627
|
-
['1999', '2000', 'just below the range → 2000'],
|
|
5628
|
-
['2100', '2050', 'above the range → 2050'],
|
|
5629
|
-
['2051', '2050', 'just above the range → 2050'],
|
|
5630
|
-
['2000', '2000', 'the range start is kept'],
|
|
5631
|
-
['2050', '2050', 'the range end is kept'],
|
|
5632
|
-
['2030', '2030', 'inside the range is kept'],
|
|
5633
|
-
]) {
|
|
5634
|
-
it(`Y19 the year IS clamped when the user edits the year itself: ${typed} → ${expected} (${why})`, async () => {
|
|
5635
|
-
const el = await make('1985-06-15T00:00:00[GMT+00:00 UTC]');
|
|
5636
|
-
await retype(el, 6, 10, typed);
|
|
5637
|
-
await blur(el);
|
|
5638
|
-
expect(nativeOf(el).value).to.equal(`15/06/${expected}`);
|
|
5639
|
-
expect(calDate(el)).to.deep.equal([Number(expected), 6, 15]);
|
|
5640
|
-
}).timeout(60000);
|
|
5641
|
-
}
|
|
5642
|
-
it('Y19 an in-range seeded year is not changed by editing another segment', async () => {
|
|
5643
|
-
const el = await make('2030-06-15T00:00:00[GMT+00:00 UTC]');
|
|
5644
|
-
await retype(el, 0, 2, '20');
|
|
5645
|
-
await blur(el);
|
|
5646
|
-
expect(nativeOf(el).value).to.equal('20/06/2030');
|
|
5647
|
-
}).timeout(60000);
|
|
5648
|
-
it('Y19 a second edit after a blur still leaves the untouched year alone', async () => {
|
|
5649
|
-
const el = await make('1985-06-15T00:00:00[GMT+00:00 UTC]');
|
|
5650
|
-
await retype(el, 0, 2, '20');
|
|
5651
|
-
await blur(el);
|
|
5652
|
-
await retype(el, 3, 5, '08');
|
|
5653
|
-
await blur(el);
|
|
5654
|
-
expect(nativeOf(el).value).to.equal('20/08/1985');
|
|
5655
|
-
}).timeout(60000);
|
|
5656
|
-
it('Y19 an edited month/year still clamps the day to the month length (e.g. 31 -> 28 after choosing February)', async () => {
|
|
5657
|
-
const el = await make('1985-01-31T00:00:00[GMT+00:00 UTC]');
|
|
5658
|
-
await retype(el, 3, 5, '02');
|
|
5659
|
-
await blur(el);
|
|
5660
|
-
expect(nativeOf(el).value).to.equal('28/02/1985');
|
|
5661
|
-
}).timeout(60000);
|
|
5662
|
-
});
|
|
5663
|
-
describe('Y19b. typed-year clamping: explicit startYear / endYear win, an unset side falls back to 2000 / 2050', () => {
|
|
5664
|
-
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
5665
|
-
const make = async (bounds, format = 'DD/MM/YYYY') => {
|
|
5666
|
-
const el = await fixture(html `<nile-date-time-picker
|
|
5667
|
-
.timezone=${'UTC'} dateFormat=${format} .hideTimeFields=${DATE_ONLY} .startYear=${bounds.start} .endYear=${bounds.end}
|
|
5668
|
-
value="2026-06-15T00:00:00[GMT+00:00 UTC]"></nile-date-time-picker>`);
|
|
5669
|
-
await settle2(el);
|
|
5670
|
-
return el;
|
|
5671
|
-
};
|
|
5672
|
-
const inputOf = (el) => el.shadowRoot.querySelector('nile-input');
|
|
5673
|
-
const nativeOf = (el) => inputOf(el).input;
|
|
5674
|
-
const press = (el, key) => inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, composed: true, cancelable: true }));
|
|
5675
|
-
/** retype the year segment (the last four characters of DD/MM/YYYY) and blur */
|
|
5676
|
-
const typeYear = async (el, digits, from = 6, to = 10) => {
|
|
5677
|
-
nativeOf(el).setSelectionRange(from, to);
|
|
5678
|
-
press(el, 'Backspace');
|
|
5679
|
-
for (const ch of digits)
|
|
5680
|
-
press(el, ch);
|
|
5681
|
-
await settle2(el);
|
|
5682
|
-
nativeOf(el).focus();
|
|
5683
|
-
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
5684
|
-
await settle2(el);
|
|
5685
|
-
};
|
|
5686
|
-
const calYear = (el) => el.calendarElement.value.getFullYear();
|
|
5687
|
-
const cases = [
|
|
5688
|
-
// no bounds: the 2000-2050 default applies on both sides
|
|
5689
|
-
['no bounds, before 2000', {}, '1850', '2000'],
|
|
5690
|
-
['no bounds, 1999', {}, '1999', '2000'],
|
|
5691
|
-
['no bounds, after 2050', {}, '2100', '2050'],
|
|
5692
|
-
['no bounds, 2051', {}, '2051', '2050'],
|
|
5693
|
-
['no bounds, year 0050', {}, '0050', '2000'],
|
|
5694
|
-
['no bounds, 2000 and 2050 are kept', {}, '2000', '2000'],
|
|
5695
|
-
['no bounds, 2050 is kept', {}, '2050', '2050'],
|
|
5696
|
-
// explicit bounds win over the default, including outside 2000-2050
|
|
5697
|
-
['explicit bounds before 2000 are respected', { start: 1850, end: 2100 }, '1850', '1850'],
|
|
5698
|
-
['explicit bounds after 2050 are respected', { start: 1850, end: 2100 }, '2100', '2100'],
|
|
5699
|
-
['explicit bounds still clamp below', { start: 1850, end: 2100 }, '1800', '1850'],
|
|
5700
|
-
['explicit bounds still clamp above', { start: 1850, end: 2100 }, '2200', '2100'],
|
|
5701
|
-
['explicit 0-9999 keeps year 0050', { start: 0, end: 9999 }, '0050', '0050'],
|
|
5702
|
-
['explicit 0-9999 keeps 9999', { start: 0, end: 9999 }, '9999', '9999'],
|
|
5703
|
-
// custom bounds inside the default range
|
|
5704
|
-
['custom bounds, below', { start: 1990, end: 2010 }, '1980', '1990'],
|
|
5705
|
-
['custom bounds, above', { start: 1990, end: 2010 }, '2020', '2010'],
|
|
5706
|
-
['custom bounds, inside', { start: 1990, end: 2010 }, '2000', '2000'],
|
|
5707
|
-
// one-sided: the unset side falls back to 2000 / 2050
|
|
5708
|
-
['startYear only, below it', { start: 1990 }, '1980', '1990'],
|
|
5709
|
-
['startYear only, before 2000 but above it', { start: 1990 }, '1995', '1995'],
|
|
5710
|
-
['startYear only, above the default end', { start: 1990 }, '2100', '2050'],
|
|
5711
|
-
['endYear only, above it', { end: 2010 }, '2020', '2010'],
|
|
5712
|
-
['endYear only, below the default start', { end: 2010 }, '1850', '2000'],
|
|
5713
|
-
['endYear only, past 2050 but within it', { end: 2100 }, '2080', '2080'],
|
|
5714
|
-
['endYear only, past it', { end: 2100 }, '2101', '2100'],
|
|
5715
|
-
];
|
|
5716
|
-
for (const [name, bounds, typed, expected] of cases) {
|
|
5717
|
-
it(`Y19b ${name}: typing ${typed} gives ${expected}`, async () => {
|
|
5718
|
-
const el = await make(bounds);
|
|
5719
|
-
await typeYear(el, typed);
|
|
5720
|
-
expect(nativeOf(el).value).to.equal(`15/06/${expected}`);
|
|
5721
|
-
expect(calYear(el)).to.equal(Number(expected));
|
|
5722
|
-
}).timeout(60000);
|
|
5723
|
-
}
|
|
5724
|
-
it('Y19b no bounds: a typed YY year past 2050 is pulled back to 2050 (75 becomes 50)', async () => {
|
|
5725
|
-
const el = await make({}, 'DD/MM/YY');
|
|
5726
|
-
await typeYear(el, '75', 6, 8);
|
|
5727
|
-
expect(nativeOf(el).value).to.equal('15/06/50');
|
|
5728
|
-
expect(calYear(el)).to.equal(2050);
|
|
5729
|
-
}).timeout(60000);
|
|
5730
|
-
it('Y19b explicit endYear 2099: a typed YY year 75 is kept (2075)', async () => {
|
|
5731
|
-
const el = await make({ end: 2099 }, 'DD/MM/YY');
|
|
5732
|
-
await typeYear(el, '75', 6, 8);
|
|
5733
|
-
expect(nativeOf(el).value).to.equal('15/06/75');
|
|
5734
|
-
expect(calYear(el)).to.equal(2075);
|
|
5735
|
-
}).timeout(60000);
|
|
5736
|
-
it('Y19b endYear only: the calendar the picker renders gets only that bound', async () => {
|
|
5737
|
-
const el = await make({ end: 2010 });
|
|
5738
|
-
const cal = el.calendarElement;
|
|
5739
|
-
expect(cal.startYear).to.be.undefined;
|
|
5740
|
-
expect(Number(cal.endYear)).to.equal(2010);
|
|
5741
|
-
}).timeout(60000);
|
|
5742
|
-
});
|
|
5743
|
-
describe('Y20. Set to now uses the machine zone; value = null keeps the configured timezone', () => {
|
|
5744
|
-
const FROZEN = Date.UTC(2026, 5, 15, 18, 42, 37, 456);
|
|
5745
|
-
const textOf = (el) => el.shadowRoot.querySelector('nile-input').input.value;
|
|
5746
|
-
it('Y20 Set to now shows the machine clock and zone in the trigger, switches picker and calendar to the machine zone, and emits it', async () => {
|
|
5747
|
-
const HOST = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
5748
|
-
const el = await fixture(html `<nile-date-time-picker timezone="America/New_York" dateFormat="DD/MM/YYYY"></nile-date-time-picker>`);
|
|
5749
|
-
const cal = await settle2(el);
|
|
5750
|
-
const RealDate = Date;
|
|
5751
|
-
class FrozenDate extends RealDate {
|
|
5752
|
-
constructor(...args) { if (args.length === 0)
|
|
5753
|
-
super(FROZEN);
|
|
5754
|
-
else
|
|
5755
|
-
super(...args); }
|
|
5756
|
-
static now() { return FROZEN; }
|
|
5757
|
-
}
|
|
5758
|
-
let detail = null;
|
|
5759
|
-
el.addEventListener('nile-change', (e) => { detail = e.detail; });
|
|
5760
|
-
globalThis.Date = FrozenDate;
|
|
5761
|
-
try {
|
|
5762
|
-
cal.shadowRoot.querySelector('.tp-set-to-now-button').click();
|
|
5763
|
-
}
|
|
5764
|
-
finally {
|
|
5765
|
-
globalThis.Date = RealDate;
|
|
5766
|
-
}
|
|
5767
|
-
await settle2(el);
|
|
5768
|
-
cal.shadowRoot.querySelector('.apply-button').click();
|
|
5769
|
-
await settle2(el);
|
|
5770
|
-
// the machine's own reading of the frozen instant (host zone differs between runs)
|
|
5771
|
-
const t = new RealDate(FROZEN);
|
|
5772
|
-
const p2 = (n) => String(n).padStart(2, '0');
|
|
5773
|
-
expect(textOf(el)).to.equal(`${p2(t.getDate())}/${p2(t.getMonth() + 1)}/${t.getFullYear()} - ${p2(t.getHours())}:${p2(t.getMinutes())}:${p2(t.getSeconds())}.456 - ${HOST}`);
|
|
5774
|
-
expect(el.timezone, 'picker zone becomes the machine zone').to.equal(HOST);
|
|
5775
|
-
expect(cal.timezone).to.equal(HOST);
|
|
5776
|
-
expect(detail.timezone).to.equal(HOST);
|
|
5777
|
-
expect(detail.unixEpoch).to.equal(FROZEN);
|
|
5778
|
-
}).timeout(60000);
|
|
5779
|
-
it('Y20 value = null clears value and display and keeps the configured timezone', async () => {
|
|
5780
|
-
const el = await fixture(html `<nile-date-time-picker timezone="Asia/Kolkata" dateFormat="DD/MM/YYYY"
|
|
5781
|
-
value="2026-06-15T10:20:30"></nile-date-time-picker>`);
|
|
5782
|
-
await settle2(el);
|
|
5783
|
-
expect(textOf(el), 'precondition').to.contain('15/06/2026');
|
|
5784
|
-
el.value = null;
|
|
5785
|
-
await settle2(el);
|
|
5786
|
-
expect(el.value).to.equal(null);
|
|
5787
|
-
expect(textOf(el)).to.equal('');
|
|
5788
|
-
expect(el.calendarElement.value).to.equal(null);
|
|
5789
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
5790
|
-
expect(el.calendarElement.timezone).to.equal('Asia/Kolkata');
|
|
5791
|
-
}).timeout(60000);
|
|
5792
|
-
});
|
|
5793
|
-
describe('Y21. an overflow Relative duration never reaches the picker (Finding #8)', () => {
|
|
5794
|
-
const fire = (target, value) => target.dispatchEvent(new CustomEvent('nile-change', { detail: { value }, bubbles: false, composed: true }));
|
|
5795
|
-
const make = async () => {
|
|
5796
|
-
const el = await fixture(html `<nile-date-time-picker timezone="UTC" dateFormat="DD/MM/YYYY"
|
|
5797
|
-
value="2026-06-15T10:20:30.250[GMT+00:00 UTC]"></nile-date-time-picker>`);
|
|
5798
|
-
await settle2(el);
|
|
5799
|
-
return el;
|
|
5800
|
-
};
|
|
5801
|
-
const tab = async (el, value) => {
|
|
5802
|
-
el.calendarElement.shadowRoot.querySelector(`nile-tab[panel="${value}"]`).dispatchEvent(new CustomEvent('nile-tab-show', { detail: { value }, bubbles: true, composed: true }));
|
|
5803
|
-
await settle2(el);
|
|
5804
|
-
};
|
|
5805
|
-
const enter = async (el, unit, n) => {
|
|
5806
|
-
const cal = el.calendarElement;
|
|
5807
|
-
fire(cal.shadowRoot.querySelector('.time-input'), unit);
|
|
5808
|
-
fire(cal.shadowRoot.querySelector('.duration-input'), String(n));
|
|
5809
|
-
await settle2(el);
|
|
5810
|
-
};
|
|
5811
|
-
const apply = (el) => el.calendarElement.shadowRoot.querySelector('.apply-button');
|
|
5812
|
-
const textOf = (el) => el.shadowRoot.querySelector('nile-input').input.value;
|
|
5813
|
-
for (const [unit, n] of [['minutes', 999999999999], ['hours', 99999999999], ['days', 999999999], ['weeks', 999999999], ['months', 999999999]]) {
|
|
5814
|
-
it(`Y21 ${unit}: ${n} -> Apply is disabled, nothing is thrown, emitted or changed; correcting it applies normally`, async () => {
|
|
5815
|
-
const el = await make();
|
|
5816
|
-
const value = el.value;
|
|
5817
|
-
await tab(el, 'relative');
|
|
5818
|
-
const errors = [];
|
|
5819
|
-
const onError = (e) => { errors.push(e.message); e.preventDefault(); };
|
|
5820
|
-
window.addEventListener('error', onError);
|
|
5821
|
-
const seen = [];
|
|
5822
|
-
for (const name of ['nile-change', 'nile-changed'])
|
|
5823
|
-
el.addEventListener(name, () => seen.push(name));
|
|
5824
|
-
try {
|
|
5825
|
-
const before = textOf(el);
|
|
5826
|
-
await enter(el, unit, n);
|
|
5827
|
-
expect(apply(el).hasAttribute('disabled'), 'Apply disabled').to.be.true;
|
|
5828
|
-
apply(el).click();
|
|
5829
|
-
await settle2(el);
|
|
5830
|
-
expect(errors, 'no uncaught RangeError').to.deep.equal([]);
|
|
5831
|
-
expect(seen, 'no change events').to.deep.equal([]);
|
|
5832
|
-
expect(textOf(el), 'trigger unchanged').to.equal(before);
|
|
5833
|
-
expect(el.value, 'value unchanged').to.equal(value);
|
|
5834
|
-
expect(el.timezone).to.equal('UTC');
|
|
5835
|
-
await enter(el, unit, 2);
|
|
5836
|
-
expect(apply(el).hasAttribute('disabled'), 'Apply enabled again').to.be.false;
|
|
5837
|
-
apply(el).click();
|
|
5838
|
-
await settle2(el);
|
|
5839
|
-
expect(seen).to.deep.equal(['nile-change']);
|
|
5840
|
-
expect(textOf(el)).to.contain(' - UTC');
|
|
5841
|
-
expect(errors).to.deep.equal([]);
|
|
5842
|
-
}
|
|
5843
|
-
finally {
|
|
5844
|
-
window.removeEventListener('error', onError);
|
|
5845
|
-
}
|
|
5846
|
-
}).timeout(60000);
|
|
5847
|
-
}
|
|
5848
|
-
});
|
|
5849
|
-
/**
|
|
5850
|
-
* Year handling in the structured mask and the calendar view.
|
|
5851
|
-
*
|
|
5852
|
-
* Y1 `YY` keeps a seeded value's century when an unrelated segment is edited (DTP-02);
|
|
5853
|
-
* an explicitly edited year reads as 2000-2099
|
|
5854
|
-
* Y2 a year being overtyped is normalised only once it is fully typed (range clamp, leap day)
|
|
5855
|
-
* Y3 the year/month dropdowns only navigate; reopening the panel shows the selected date's month/year
|
|
5856
|
-
*/
|
|
5857
|
-
describe('NileDateTimePicker — year handling', () => {
|
|
5858
|
-
const SEED = (y, md = '06-15') => `${y}-${md}T10:20:30.000[GMT+00:00 UTC]`;
|
|
5859
|
-
const build = async (o = {}) => {
|
|
5860
|
-
const el = await fixture(html `<nile-date-time-picker .dateFormat=${o.fmt ?? 'DD/MM/YY'}></nile-date-time-picker>`);
|
|
5861
|
-
// explicit bounds, so these tests do not depend on the component's default year range
|
|
5862
|
-
el.startYear = o.start ?? 1900;
|
|
5863
|
-
el.endYear = o.end ?? 3000;
|
|
5864
|
-
if (o.hide)
|
|
5865
|
-
el.hideTimeFields = o.hide;
|
|
5866
|
-
if (o.dropdowns) {
|
|
5867
|
-
el.showMonthDropdown = true;
|
|
5868
|
-
el.showYearDropdown = true;
|
|
5869
|
-
}
|
|
5870
|
-
if (o.value)
|
|
5871
|
-
el.value = o.value;
|
|
5872
|
-
await settle(el);
|
|
5873
|
-
await settle(el);
|
|
5874
|
-
await new Promise(r => setTimeout(r, 30));
|
|
5875
|
-
return el;
|
|
5876
|
-
};
|
|
5877
|
-
const settle = async (el) => {
|
|
5878
|
-
await el.updateComplete;
|
|
5879
|
-
const cal = el.calendarElement;
|
|
5880
|
-
if (cal)
|
|
5881
|
-
await cal.updateComplete;
|
|
5882
|
-
await inputOf(el).updateComplete;
|
|
5883
|
-
return cal;
|
|
5884
|
-
};
|
|
5885
|
-
const calOf = (el) => el.calendarElement;
|
|
5886
|
-
const inputOf = (el) => el.shadowRoot.querySelector('nile-input');
|
|
5887
|
-
const nativeOf = (el) => inputOf(el).input;
|
|
5888
|
-
const textOf = (el) => nativeOf(el).value;
|
|
5889
|
-
const press = (el, key) => inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, composed: true, cancelable: true }));
|
|
5890
|
-
const typeKeys = (el, s) => { for (const ch of s)
|
|
5891
|
-
press(el, ch); };
|
|
5892
|
-
const caret = (el, p, q = p) => { nativeOf(el).focus(); nativeOf(el).setSelectionRange(p, q); };
|
|
5893
|
-
const blur = async (el) => {
|
|
5894
|
-
inputOf(el).dispatchEvent(new Event('focusout', { bubbles: true, composed: true }));
|
|
5895
|
-
await settle(el);
|
|
5896
|
-
};
|
|
5897
|
-
const paste = (el, text) => {
|
|
5898
|
-
const dt = new DataTransfer();
|
|
5899
|
-
dt.setData('text', text);
|
|
5900
|
-
inputOf(el).dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, composed: true, cancelable: true }));
|
|
5901
|
-
};
|
|
5902
|
-
/** the mask's year digits, e.g. "2026" or "26" */
|
|
5903
|
-
const yearText = (el) => {
|
|
5904
|
-
const t = textOf(el);
|
|
5905
|
-
return el.dateFormat.endsWith('YYYY') ? t.slice(6, 10) : t.slice(6, 8);
|
|
5906
|
-
};
|
|
5907
|
-
const apply = async (el) => {
|
|
5908
|
-
const events = [];
|
|
5909
|
-
const rec = ((e) => events.push(e));
|
|
5910
|
-
el.addEventListener('nile-change', rec);
|
|
5911
|
-
const btn = calOf(el).shadowRoot.querySelector('.apply-button');
|
|
5912
|
-
await btn.updateComplete;
|
|
5913
|
-
btn.click();
|
|
5914
|
-
await settle(el);
|
|
5915
|
-
el.removeEventListener('nile-change', rec);
|
|
5916
|
-
return events;
|
|
5917
|
-
};
|
|
5918
|
-
const yearOf = (iso) => Number((iso ?? '').slice(0, 4));
|
|
5919
|
-
const openPanel = async (el) => {
|
|
5920
|
-
el.open = true;
|
|
5921
|
-
await settle(el);
|
|
5922
|
-
await new Promise(r => setTimeout(r, 60));
|
|
5923
|
-
};
|
|
5924
|
-
const closePanel = async (el) => {
|
|
5925
|
-
el.open = false;
|
|
5926
|
-
await settle(el);
|
|
5927
|
-
await new Promise(r => setTimeout(r, 60));
|
|
5928
|
-
};
|
|
5929
|
-
const pickYear = async (el, y) => {
|
|
5930
|
-
const cal = calOf(el);
|
|
5931
|
-
const item = [...cal.shadowRoot.querySelectorAll('.year-menu-item')]
|
|
5932
|
-
.find((m) => m.textContent.trim() === String(y));
|
|
5933
|
-
item.click();
|
|
5934
|
-
await cal.updateComplete;
|
|
5935
|
-
};
|
|
5936
|
-
const pickMonth = async (el, m0) => {
|
|
5937
|
-
const cal = calOf(el);
|
|
5938
|
-
cal.shadowRoot.querySelectorAll('.month-menu-item')[m0].click();
|
|
5939
|
-
await cal.updateComplete;
|
|
5940
|
-
};
|
|
5941
|
-
// ── Y1. YY century ──────────────────────────────────────────────────────────
|
|
5942
|
-
describe('Y1. two-digit year keeps the seeded century', () => {
|
|
5943
|
-
const edits = [
|
|
5944
|
-
['day', el => { caret(el, 0); typeKeys(el, '17'); }],
|
|
5945
|
-
['month', el => { caret(el, 3); typeKeys(el, '03'); }],
|
|
5946
|
-
['minutes', el => { caret(el, textOf(el).indexOf(':') + 1); typeKeys(el, '45'); }],
|
|
5947
|
-
];
|
|
5948
|
-
for (const [what, edit] of edits) {
|
|
5949
|
-
it(`Y1a. YY seeded 1999, edit ${what} → still 1999 in value, epoch, trigger and calendar`, async () => {
|
|
5950
|
-
const el = await build({ value: SEED('1999') });
|
|
5951
|
-
expect(textOf(el)).to.match(/^15\/06\/99 - /);
|
|
5952
|
-
edit(el);
|
|
5953
|
-
await blur(el);
|
|
5954
|
-
expect(yearText(el), 'trigger year').to.equal('99');
|
|
5955
|
-
const [ev, ...rest] = await apply(el);
|
|
5956
|
-
expect(rest).to.have.length(0);
|
|
5957
|
-
expect(yearOf(ev.detail.value), 'emitted value').to.equal(1999);
|
|
5958
|
-
expect(new Date(ev.detail.unixEpoch).getUTCFullYear(), 'emitted epoch').to.equal(1999);
|
|
5959
|
-
expect(yearOf(el.value), 'public value').to.equal(1999);
|
|
5960
|
-
expect(calOf(el).value.getFullYear(), 'calendar selection').to.equal(1999);
|
|
5961
|
-
expect(yearText(el)).to.equal('99');
|
|
5962
|
-
});
|
|
5963
|
-
}
|
|
5964
|
-
it('Y1b. YY seeded 1999, Apply without editing → 1999', async () => {
|
|
5965
|
-
const el = await build({ value: SEED('1999') });
|
|
5966
|
-
const [ev] = await apply(el);
|
|
5967
|
-
expect(yearOf(ev.detail.value)).to.equal(1999);
|
|
5968
|
-
expect(new Date(ev.detail.unixEpoch).getUTCFullYear()).to.equal(1999);
|
|
5969
|
-
});
|
|
5970
|
-
it('Y1c. YY seeded 2026, edit day → 2026', async () => {
|
|
5971
|
-
const el = await build({ value: SEED('2026') });
|
|
5972
|
-
caret(el, 0);
|
|
5973
|
-
typeKeys(el, '17');
|
|
5974
|
-
await blur(el);
|
|
5975
|
-
const [ev] = await apply(el);
|
|
5976
|
-
expect(ev.detail.value).to.match(/^2026-06-17T/);
|
|
5977
|
-
});
|
|
5978
|
-
it('Y1d. YY empty, typing 99 → 2099 (D1: new two-digit years are 2000-2099)', async () => {
|
|
5979
|
-
const el = await build();
|
|
5980
|
-
typeKeys(el, '150699');
|
|
5981
|
-
await blur(el);
|
|
5982
|
-
expect(calOf(el).value.getFullYear()).to.equal(2099);
|
|
5983
|
-
const [ev] = await apply(el);
|
|
5984
|
-
expect(yearOf(ev.detail.value)).to.equal(2099);
|
|
5985
|
-
});
|
|
5986
|
-
it('Y1e. YYYY seeded 1999, edit day → 1999', async () => {
|
|
5987
|
-
const el = await build({ fmt: 'DD/MM/YYYY', value: SEED('1999') });
|
|
5988
|
-
caret(el, 0);
|
|
5989
|
-
typeKeys(el, '17');
|
|
5990
|
-
await blur(el);
|
|
5991
|
-
const [ev] = await apply(el);
|
|
5992
|
-
expect(ev.detail.value).to.match(/^1999-06-17T/);
|
|
5993
|
-
});
|
|
5994
|
-
it('Y1f. YY seeded 1999, retyping the same visible 99 keeps 1999', async () => {
|
|
5995
|
-
const el = await build({ value: SEED('1999') });
|
|
5996
|
-
caret(el, 6);
|
|
5997
|
-
typeKeys(el, '99');
|
|
5998
|
-
await blur(el);
|
|
5999
|
-
expect(yearText(el)).to.equal('99');
|
|
6000
|
-
expect(calOf(el).value.getFullYear()).to.equal(1999);
|
|
6001
|
-
const [ev] = await apply(el);
|
|
6002
|
-
expect(yearOf(ev.detail.value)).to.equal(1999);
|
|
6003
|
-
expect(new Date(ev.detail.unixEpoch).getUTCFullYear()).to.equal(1999);
|
|
6004
|
-
});
|
|
6005
|
-
it('Y1f2. YY seeded 1999, explicitly changing 99 → 98 reads as 2098 (2000-2099 policy)', async () => {
|
|
6006
|
-
const el = await build({ value: SEED('1999') });
|
|
6007
|
-
caret(el, 6);
|
|
6008
|
-
typeKeys(el, '9');
|
|
6009
|
-
expect(calOf(el).value.getFullYear(), 'half-typed year does not reach the calendar').to.equal(1999);
|
|
6010
|
-
typeKeys(el, '8');
|
|
6011
|
-
expect(calOf(el).value.getFullYear(), 'completed year reaches the calendar').to.equal(2098);
|
|
6012
|
-
await blur(el);
|
|
6013
|
-
expect(yearText(el)).to.equal('98');
|
|
6014
|
-
const [ev] = await apply(el);
|
|
6015
|
-
expect(yearOf(ev.detail.value)).to.equal(2098);
|
|
6016
|
-
expect(new Date(ev.detail.unixEpoch).getUTCFullYear()).to.equal(2098);
|
|
6017
|
-
});
|
|
6018
|
-
it('Y1f3. YY seeded 1999, change to 98 then restore 99 before committing → 1999', async () => {
|
|
6019
|
-
const el = await build({ value: SEED('1999') });
|
|
6020
|
-
caret(el, 6);
|
|
6021
|
-
typeKeys(el, '98');
|
|
6022
|
-
expect(calOf(el).value.getFullYear()).to.equal(2098);
|
|
6023
|
-
caret(el, 6);
|
|
6024
|
-
typeKeys(el, '99');
|
|
6025
|
-
expect(calOf(el).value.getFullYear(), 'restored digits restore the century').to.equal(1999);
|
|
6026
|
-
await blur(el);
|
|
6027
|
-
const [ev] = await apply(el);
|
|
6028
|
-
expect(yearOf(ev.detail.value)).to.equal(1999);
|
|
6029
|
-
});
|
|
6030
|
-
it('Y1f4. the restore also works across a blur, as long as nothing was applied', async () => {
|
|
6031
|
-
const el = await build({ value: SEED('1999') });
|
|
6032
|
-
caret(el, 6);
|
|
6033
|
-
typeKeys(el, '98');
|
|
6034
|
-
await blur(el);
|
|
6035
|
-
caret(el, 0);
|
|
6036
|
-
typeKeys(el, '17'); // an unrelated edit while the year sits at 2098
|
|
6037
|
-
await blur(el);
|
|
6038
|
-
expect(calOf(el).value.getFullYear()).to.equal(2098);
|
|
6039
|
-
caret(el, 6);
|
|
6040
|
-
typeKeys(el, '99');
|
|
6041
|
-
await blur(el);
|
|
6042
|
-
const [ev] = await apply(el);
|
|
6043
|
-
expect(ev.detail.value).to.match(/^1999-06-17T/);
|
|
6044
|
-
});
|
|
6045
|
-
it('Y1f5. after Apply the applied year is the new baseline (2098 stays 2098 through a day edit)', async () => {
|
|
6046
|
-
const el = await build({ value: SEED('1999') });
|
|
6047
|
-
caret(el, 6);
|
|
6048
|
-
typeKeys(el, '98');
|
|
6049
|
-
await blur(el);
|
|
6050
|
-
await apply(el);
|
|
6051
|
-
caret(el, 0);
|
|
6052
|
-
typeKeys(el, '18');
|
|
6053
|
-
await blur(el);
|
|
6054
|
-
const [ev] = await apply(el);
|
|
6055
|
-
expect(ev.detail.value).to.match(/^2098-06-18T/);
|
|
6056
|
-
});
|
|
6057
|
-
it('Y1f6. Backspace over the year, then retyping the same 99 → 1999; typing 98 → 2098', async () => {
|
|
6058
|
-
const a = await build({ value: SEED('1999') });
|
|
6059
|
-
caret(a, 6, 8);
|
|
6060
|
-
press(a, 'Backspace');
|
|
6061
|
-
typeKeys(a, '99');
|
|
6062
|
-
await blur(a);
|
|
6063
|
-
expect(calOf(a).value.getFullYear()).to.equal(1999);
|
|
6064
|
-
const b = await build({ value: SEED('1999') });
|
|
6065
|
-
caret(b, 6, 8);
|
|
6066
|
-
press(b, 'Backspace');
|
|
6067
|
-
typeKeys(b, '98');
|
|
6068
|
-
await blur(b);
|
|
6069
|
-
expect(calOf(b).value.getFullYear()).to.equal(2098);
|
|
6070
|
-
});
|
|
6071
|
-
it('Y1f7. YY paste over the year: 99 keeps 1999, 98 reads as 2098', async () => {
|
|
6072
|
-
const a = await build({ value: SEED('1999') });
|
|
6073
|
-
caret(a, 6, 8);
|
|
6074
|
-
paste(a, '99');
|
|
6075
|
-
await blur(a);
|
|
6076
|
-
expect(calOf(a).value.getFullYear()).to.equal(1999);
|
|
6077
|
-
const b = await build({ value: SEED('1999') });
|
|
6078
|
-
caret(b, 6, 8);
|
|
6079
|
-
paste(b, '98');
|
|
6080
|
-
await blur(b);
|
|
6081
|
-
expect(calOf(b).value.getFullYear()).to.equal(2098);
|
|
6082
|
-
});
|
|
6083
|
-
it('Y1g. YY seeded 1999, explicitly typing another year reads as 20xx', async () => {
|
|
6084
|
-
const el = await build({ value: SEED('1999') });
|
|
6085
|
-
caret(el, 6);
|
|
6086
|
-
typeKeys(el, '05');
|
|
6087
|
-
await blur(el);
|
|
6088
|
-
const [ev] = await apply(el);
|
|
6089
|
-
expect(yearOf(ev.detail.value)).to.equal(2005);
|
|
6090
|
-
});
|
|
6091
|
-
it('Y1h. a programmatic value change does not retain the previous seeded century', async () => {
|
|
6092
|
-
const el = await build({ value: SEED('1999') });
|
|
6093
|
-
caret(el, 0);
|
|
6094
|
-
typeKeys(el, '17'); // edit → century 1999 is in play
|
|
6095
|
-
el.value = SEED('2050'); // consumer replaces the value
|
|
6096
|
-
await settle(el);
|
|
6097
|
-
await settle(el);
|
|
6098
|
-
caret(el, 0);
|
|
6099
|
-
typeKeys(el, '18');
|
|
6100
|
-
await blur(el);
|
|
6101
|
-
const [ev] = await apply(el);
|
|
6102
|
-
expect(ev.detail.value).to.match(/^2050-06-18T/);
|
|
6103
|
-
});
|
|
6104
|
-
it('Y1i. Apply re-seeds: after applying 1999, editing the day keeps 1999; Reset forgets it', async () => {
|
|
6105
|
-
const el = await build({ value: SEED('1999') });
|
|
6106
|
-
caret(el, 0);
|
|
6107
|
-
typeKeys(el, '17');
|
|
6108
|
-
await blur(el);
|
|
6109
|
-
await apply(el);
|
|
6110
|
-
caret(el, 0);
|
|
6111
|
-
typeKeys(el, '18');
|
|
6112
|
-
await blur(el);
|
|
6113
|
-
const [ev] = await apply(el);
|
|
6114
|
-
expect(ev.detail.value).to.match(/^1999-06-18T/);
|
|
6115
|
-
calOf(el).shadowRoot.querySelector('.clear-button').click();
|
|
6116
|
-
await settle(el);
|
|
6117
|
-
expect(textOf(el)).to.equal('');
|
|
6118
|
-
typeKeys(el, '150699');
|
|
6119
|
-
await blur(el);
|
|
6120
|
-
const [ev2] = await apply(el);
|
|
6121
|
-
expect(yearOf(ev2.detail.value), 'a cleared picker carries no century').to.equal(2099);
|
|
6122
|
-
});
|
|
6123
|
-
it('Y1j. changing dateFormat YY → YYYY → YY keeps 1999 through a later edit', async () => {
|
|
6124
|
-
const el = await build({ value: SEED('1999') });
|
|
6125
|
-
el.dateFormat = 'DD/MM/YYYY';
|
|
6126
|
-
await settle(el);
|
|
6127
|
-
await settle(el);
|
|
6128
|
-
expect(textOf(el)).to.match(/^15\/06\/1999/);
|
|
6129
|
-
el.dateFormat = 'DD/MM/YY';
|
|
6130
|
-
await settle(el);
|
|
6131
|
-
await settle(el);
|
|
6132
|
-
caret(el, 0);
|
|
6133
|
-
typeKeys(el, '17');
|
|
6134
|
-
await blur(el);
|
|
6135
|
-
const [ev] = await apply(el);
|
|
6136
|
-
expect(ev.detail.value).to.match(/^1999-06-17T/);
|
|
6137
|
-
});
|
|
6138
|
-
it('Y1k. a year 0-99 still round-trips in a four-digit format', async () => {
|
|
6139
|
-
const el = await build({ fmt: 'DD/MM/YYYY', value: SEED('0050') });
|
|
6140
|
-
expect(textOf(el)).to.match(/^15\/06\/0050/);
|
|
6141
|
-
caret(el, 0);
|
|
6142
|
-
typeKeys(el, '17');
|
|
6143
|
-
await blur(el);
|
|
6144
|
-
expect(textOf(el)).to.match(/^17\/06\/0050/);
|
|
6145
|
-
});
|
|
6146
|
-
});
|
|
6147
|
-
// ── Y1x. the remaining paths that carry or reset the seeded century ─────────
|
|
6148
|
-
describe('Y1x. century across reflow, reseed, zones and allowedDates', () => {
|
|
6149
|
-
it('Y1l. the beforeinput reflow path (IME, soft keyboard, cut/undo) keeps the century when the year digits are unchanged', async () => {
|
|
6150
|
-
const el = await build({ value: SEED('1999') });
|
|
6151
|
-
const native = nativeOf(el);
|
|
6152
|
-
native.focus();
|
|
6153
|
-
native.dispatchEvent(new InputEvent('beforeinput', { inputType: 'insertText', data: '7', bubbles: true, composed: true, cancelable: true }));
|
|
6154
|
-
native.value = '17/06/99 - 10:20:30.000 - UTC'; // what the browser's own edit leaves behind
|
|
6155
|
-
native.dispatchEvent(new InputEvent('input', { inputType: 'insertText', bubbles: true, composed: true }));
|
|
6156
|
-
await new Promise(r => setTimeout(r, 30));
|
|
6157
|
-
await blur(el);
|
|
6158
|
-
expect(yearText(el)).to.equal('99');
|
|
6159
|
-
const [ev] = await apply(el);
|
|
6160
|
-
expect(ev.detail.value).to.match(/^1999-06-17T/);
|
|
6161
|
-
});
|
|
6162
|
-
it('Y1m. a programmatic value with the same last two digits but another century replaces the old century', async () => {
|
|
6163
|
-
const el = await build({ value: SEED('1999') });
|
|
6164
|
-
el.value = SEED('2099');
|
|
6165
|
-
await settle(el);
|
|
6166
|
-
await settle(el);
|
|
6167
|
-
caret(el, 0);
|
|
6168
|
-
typeKeys(el, '17');
|
|
6169
|
-
await blur(el);
|
|
6170
|
-
const [ev] = await apply(el);
|
|
6171
|
-
expect(ev.detail.value).to.match(/^2099-06-17T/);
|
|
6172
|
-
});
|
|
6173
|
-
it('Y1n. a zone-encoded seed in another zone keeps its wall-clock century (1999-12-31 23:30 Asia/Kolkata)', async () => {
|
|
6174
|
-
const el = await build({ value: '1999-12-31T23:30:00.000[GMT+05:30 Asia/Kolkata]' });
|
|
6175
|
-
expect(textOf(el)).to.match(/^31\/12\/99 - 23:30:00\.000 - Asia\/Kolkata/);
|
|
6176
|
-
caret(el, textOf(el).indexOf(':') + 1);
|
|
6177
|
-
typeKeys(el, '45');
|
|
6178
|
-
await blur(el);
|
|
6179
|
-
const [ev] = await apply(el);
|
|
6180
|
-
expect(ev.detail.value).to.match(/^1999-12-31T23:45:00\.000\[GMT\+05:30 Asia\/Kolkata\]$/);
|
|
6181
|
-
expect(new Date(ev.detail.unixEpoch).toISOString()).to.equal('1999-12-31T18:15:00.000Z');
|
|
6182
|
-
});
|
|
6183
|
-
it('Y1o. allowedDates: an in-range seeded 1999 is kept; a seeded 1999 outside the range snaps to the boundary year', async () => {
|
|
6184
|
-
const inRange = await build({ value: SEED('1999') });
|
|
6185
|
-
inRange.allowedDates = JSON.stringify({ startDate: '1998-01-01', endDate: '2001-12-31' });
|
|
6186
|
-
await settle(inRange);
|
|
6187
|
-
caret(inRange, 0);
|
|
6188
|
-
typeKeys(inRange, '17');
|
|
6189
|
-
await blur(inRange);
|
|
6190
|
-
const [a] = await apply(inRange);
|
|
6191
|
-
expect(a.detail.value).to.match(/^1999-06-17T/);
|
|
6192
|
-
const outside = await build({ value: SEED('1999') });
|
|
6193
|
-
outside.allowedDates = JSON.stringify({ startDate: '2005-01-01', endDate: '2010-12-31' });
|
|
6194
|
-
await settle(outside);
|
|
6195
|
-
caret(outside, 0);
|
|
6196
|
-
typeKeys(outside, '17');
|
|
6197
|
-
await blur(outside);
|
|
6198
|
-
// the first keystroke already lands outside the range and snaps to the boundary, whose year is 2005
|
|
6199
|
-
expect(yearText(outside)).to.equal('05');
|
|
6200
|
-
const [b] = await apply(outside);
|
|
6201
|
-
expect(yearOf(b.detail.value)).to.equal(2005);
|
|
6202
|
-
expect(new Date(b.detail.unixEpoch).getUTCFullYear()).to.equal(2005);
|
|
6203
|
-
});
|
|
6204
|
-
});
|
|
6205
|
-
// ── Y5. a YY year that no 2000-2099 reading can put inside the configured range ───
|
|
6206
|
-
describe('Y5. YY with a range outside 2000-2099 never writes malformed digits or commits an out-of-range year', () => {
|
|
6207
|
-
const wellFormed = (t) => expect(t, 'no sign or stray characters in the date part').to.match(/^[\d/]*$/);
|
|
6208
|
-
it('Y5a. range 1990-1999, seeded 1999: typing 98 is rejected, the seeded 99 stays, and Apply emits 1999', async () => {
|
|
6209
|
-
const el = await build({ fmt: 'DD/MM/YY', start: 1990, end: 1999, value: SEED('1999') });
|
|
6210
|
-
caret(el, 6);
|
|
6211
|
-
typeKeys(el, '98');
|
|
6212
|
-
await blur(el);
|
|
6213
|
-
expect(textOf(el).slice(0, 8)).to.equal('15/06/99');
|
|
6214
|
-
wellFormed(textOf(el).split(' - ')[0]);
|
|
6215
|
-
expect(calOf(el).value.getFullYear()).to.equal(1999);
|
|
6216
|
-
const [ev] = await apply(el);
|
|
6217
|
-
expect(yearOf(ev.detail.value)).to.equal(1999);
|
|
6218
|
-
expect(new Date(ev.detail.unixEpoch).getUTCFullYear()).to.equal(1999);
|
|
6219
|
-
});
|
|
6220
|
-
it('Y5b. range 2150-2200, seeded 2160: typing 05 is rejected (not 2050), and Apply emits 2160', async () => {
|
|
6221
|
-
const el = await build({ fmt: 'DD/MM/YY', start: 2150, end: 2200, value: SEED('2160') });
|
|
6222
|
-
caret(el, 6);
|
|
6223
|
-
typeKeys(el, '05');
|
|
6224
|
-
await blur(el);
|
|
6225
|
-
expect(textOf(el).slice(0, 8)).to.equal('15/06/60');
|
|
6226
|
-
const [ev] = await apply(el);
|
|
6227
|
-
expect(yearOf(ev.detail.value)).to.equal(2160);
|
|
6228
|
-
});
|
|
6229
|
-
it('Y5c. empty picker, range 1990-1999: the year is rejected, no date is left to Apply, nothing is emitted', async () => {
|
|
6230
|
-
const el = await build({ fmt: 'DD/MM/YY', start: 1990, end: 1999 });
|
|
6231
|
-
typeKeys(el, '150698');
|
|
6232
|
-
await blur(el);
|
|
6233
|
-
expect(textOf(el)).to.equal('15/06/');
|
|
6234
|
-
wellFormed(textOf(el));
|
|
6235
|
-
expect(calOf(el).value, 'no selection built from day and month alone').to.be.null;
|
|
6236
|
-
const btn = calOf(el).shadowRoot.querySelector('.apply-button');
|
|
6237
|
-
await btn.updateComplete;
|
|
6238
|
-
expect(btn.hasAttribute('disabled'), 'Apply is disabled').to.be.true;
|
|
6239
|
-
const events = await apply(el);
|
|
6240
|
-
expect(events).to.have.length(0);
|
|
6241
|
-
expect(el.value ?? null).to.be.null;
|
|
6242
|
-
});
|
|
6243
|
-
it('Y5d. pasting such a year into an empty picker is rejected the same way', async () => {
|
|
6244
|
-
const el = await build({ fmt: 'DD/MM/YY', start: 1990, end: 1999 });
|
|
6245
|
-
paste(el, '150698');
|
|
6246
|
-
await blur(el);
|
|
6247
|
-
expect(textOf(el)).to.equal('15/06/');
|
|
6248
|
-
expect(calOf(el).value).to.be.null;
|
|
6249
|
-
});
|
|
6250
|
-
it('Y5e. the same range with YYYY (the documented recommendation) types and commits 1995 normally', async () => {
|
|
6251
|
-
const el = await build({ fmt: 'DD/MM/YYYY', start: 1990, end: 1999 });
|
|
6252
|
-
typeKeys(el, '15061995');
|
|
6253
|
-
await blur(el);
|
|
6254
|
-
expect(textOf(el).slice(0, 10)).to.equal('15/06/1995');
|
|
6255
|
-
const [ev] = await apply(el);
|
|
6256
|
-
expect(yearOf(ev.detail.value)).to.equal(1995);
|
|
6257
|
-
const above = await build({ fmt: 'DD/MM/YYYY', start: 1990, end: 1999 });
|
|
6258
|
-
typeKeys(above, '15062005');
|
|
6259
|
-
await blur(above);
|
|
6260
|
-
expect(textOf(above).slice(0, 10), 'YYYY still clamps to the range').to.equal('15/06/1999');
|
|
6261
|
-
});
|
|
6262
|
-
it('Y5f. a YY range that does include 2000-2099 still clamps normally', async () => {
|
|
6263
|
-
const el = await build({ fmt: 'DD/MM/YY', start: 2020, end: 2035, value: SEED('2026') });
|
|
6264
|
-
caret(el, 6);
|
|
6265
|
-
typeKeys(el, '99');
|
|
6266
|
-
await blur(el);
|
|
6267
|
-
expect(yearText(el)).to.equal('35');
|
|
6268
|
-
expect(calOf(el).value.getFullYear()).to.equal(2035);
|
|
6269
|
-
});
|
|
6270
|
-
it('Y5h. the rejection ends with the mask it belonged to: a new value, an unusable value, a format change, a type switch, Reset', async () => {
|
|
6271
|
-
// observable: once the rejection is gone, a day and month typed on their own are selected as they always were
|
|
6272
|
-
const selectedAfterTyping = async (el) => { typeKeys(el, '1506'); const v = calOf(el).value; return v === null || v === undefined ? null : v.getMonth(); };
|
|
6273
|
-
const rejected = async (o = {}) => {
|
|
6274
|
-
const el = await build({ fmt: 'DD/MM/YY', start: 1990, end: 1999, ...o });
|
|
6275
|
-
typeKeys(el, '150698');
|
|
6276
|
-
await blur(el);
|
|
6277
|
-
expect(calOf(el).value, 'precondition: rejected, nothing selected').to.be.null;
|
|
6278
|
-
return el;
|
|
6279
|
-
};
|
|
6280
|
-
const control = await rejected(); // still rejected: typing day and month selects nothing
|
|
6281
|
-
typeKeys(control, '1506');
|
|
6282
|
-
expect(calOf(control).value).to.be.null;
|
|
6283
|
-
const byFormat = await rejected();
|
|
6284
|
-
byFormat.dateFormat = 'DD/MM/YYYY';
|
|
6285
|
-
await settle(byFormat);
|
|
6286
|
-
await settle(byFormat);
|
|
6287
|
-
expect(await selectedAfterTyping(byFormat), 'format change').to.equal(5);
|
|
6288
|
-
const byValue = await rejected();
|
|
6289
|
-
byValue.value = 'not-a-date';
|
|
6290
|
-
await settle(byValue);
|
|
6291
|
-
await settle(byValue);
|
|
6292
|
-
expect(await selectedAfterTyping(byValue), 'unusable value').to.equal(5);
|
|
6293
|
-
const byType = await rejected();
|
|
6294
|
-
byType.type = 'relative';
|
|
6295
|
-
await settle(byType);
|
|
6296
|
-
byType.type = 'absolute';
|
|
6297
|
-
await settle(byType);
|
|
6298
|
-
await settle(byType);
|
|
6299
|
-
expect(await selectedAfterTyping(byType), 'type switch').to.equal(5);
|
|
6300
|
-
const byReset = await rejected();
|
|
6301
|
-
calOf(byReset).dispatchEvent(new CustomEvent('nile-clear', { bubbles: true, composed: true }));
|
|
6302
|
-
await settle(byReset);
|
|
6303
|
-
expect(await selectedAfterTyping(byReset), 'Reset').to.equal(5);
|
|
6304
|
-
});
|
|
6305
|
-
it('Y5i. a rejected year ends once a year can be typed: widening the range, then typing 26, commits 2026 on Apply', async () => {
|
|
6306
|
-
const el = await build({ fmt: 'DD/MM/YY', start: 1990, end: 1999 });
|
|
6307
|
-
typeKeys(el, '150698');
|
|
6308
|
-
await blur(el);
|
|
6309
|
-
el.endYear = 2050;
|
|
6310
|
-
await settle(el);
|
|
6311
|
-
caret(el, 6);
|
|
6312
|
-
typeKeys(el, '26');
|
|
6313
|
-
await blur(el);
|
|
6314
|
-
expect(calOf(el).value.getFullYear()).to.equal(2026);
|
|
6315
|
-
const [ev] = await apply(el);
|
|
6316
|
-
expect(ev.detail.value).to.match(/^2026-06-15T/);
|
|
6317
|
-
});
|
|
6318
|
-
it('Y5j. while the year is rejected nothing can be committed from the mask: Apply is disabled and Enter / Space / click do nothing', async () => {
|
|
6319
|
-
const el = await build({ fmt: 'DD/MM/YY', start: 1990, end: 1999 });
|
|
6320
|
-
typeKeys(el, '150698');
|
|
6321
|
-
await blur(el);
|
|
6322
|
-
const btn = calOf(el).shadowRoot.querySelector('.apply-button');
|
|
6323
|
-
await btn.updateComplete;
|
|
6324
|
-
expect(btn.hasAttribute('disabled')).to.be.true;
|
|
6325
|
-
const events = [];
|
|
6326
|
-
el.addEventListener('nile-change', ((e) => events.push(e)));
|
|
6327
|
-
btn.click();
|
|
6328
|
-
btn.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, composed: true }));
|
|
6329
|
-
btn.dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true, composed: true }));
|
|
6330
|
-
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, composed: true, cancelable: true }));
|
|
6331
|
-
await settle(el);
|
|
6332
|
-
expect(events).to.have.length(0);
|
|
6333
|
-
expect(el.value ?? null).to.be.null;
|
|
6334
|
-
});
|
|
6335
|
-
it('Y5g. a seeded year outside the range stays untouched by an edit to another segment (no rejection, no clamp)', async () => {
|
|
6336
|
-
const el = await build({ fmt: 'DD/MM/YY', start: 2150, end: 2200, value: SEED('1999') });
|
|
6337
|
-
caret(el, 0);
|
|
6338
|
-
typeKeys(el, '17');
|
|
6339
|
-
await blur(el);
|
|
6340
|
-
expect(yearText(el)).to.equal('99');
|
|
6341
|
-
const [ev] = await apply(el);
|
|
6342
|
-
expect(ev.detail.value).to.match(/^1999-06-17T/);
|
|
6343
|
-
});
|
|
6344
|
-
});
|
|
6345
|
-
// ── Y2. clamping and leap day while overtyping the year ─────────────────────
|
|
6346
|
-
describe('Y2. year overtype is normalised once, when the year is complete', () => {
|
|
6347
|
-
const win = { start: 2020, end: 2035 };
|
|
6348
|
-
const cases = [
|
|
6349
|
-
['1999', '2020', 'below the range → start'],
|
|
6350
|
-
['2040', '2035', 'above the range → end'],
|
|
6351
|
-
['2025', '2025', 'in range'],
|
|
6352
|
-
['2028', '2028', 'in range'],
|
|
6353
|
-
['2030', '2030', 'in range'],
|
|
6354
|
-
['2022', '2022', 'in range'],
|
|
6355
|
-
];
|
|
6356
|
-
for (const [typed, expected, why] of cases) {
|
|
6357
|
-
it(`Y2a. seeded 2026, window 2020-2035, overtype ${typed} → ${expected} (${why})`, async () => {
|
|
6358
|
-
const el = await build({ fmt: 'DD/MM/YYYY', ...win, value: SEED('2026') });
|
|
6359
|
-
caret(el, 6);
|
|
6360
|
-
typeKeys(el, typed);
|
|
6361
|
-
await blur(el);
|
|
6362
|
-
expect(yearText(el)).to.equal(expected);
|
|
6363
|
-
const [ev] = await apply(el);
|
|
6364
|
-
expect(yearOf(ev.detail.value)).to.equal(Number(expected));
|
|
6365
|
-
expect(calOf(el).value.getFullYear()).to.equal(Number(expected));
|
|
6366
|
-
});
|
|
6367
|
-
it(`Y2b. empty picker, window 2020-2035, typing ${typed} → ${expected}`, async () => {
|
|
6368
|
-
const el = await build({ fmt: 'DD/MM/YYYY', ...win });
|
|
6369
|
-
typeKeys(el, '1506' + typed);
|
|
6370
|
-
await blur(el);
|
|
6371
|
-
expect(yearText(el)).to.equal(expected);
|
|
6372
|
-
});
|
|
6373
|
-
it(`Y2c. paste ${typed} over the seeded year, window 2020-2035 → ${expected}`, async () => {
|
|
6374
|
-
const el = await build({ fmt: 'DD/MM/YYYY', ...win, value: SEED('2026') });
|
|
6375
|
-
caret(el, 6, 10);
|
|
6376
|
-
paste(el, typed);
|
|
6377
|
-
await blur(el);
|
|
6378
|
-
expect(yearText(el)).to.equal(expected);
|
|
6379
|
-
});
|
|
6380
|
-
}
|
|
6381
|
-
for (const [typed, expected] of [['99', '35'], ['19', '20'], ['28', '28'], ['40', '35']]) {
|
|
6382
|
-
it(`Y2d. YY seeded 2026, window 2020-2035, overtype ${typed} → ${expected}`, async () => {
|
|
6383
|
-
const el = await build({ fmt: 'DD/MM/YY', ...win, value: SEED('2026') });
|
|
6384
|
-
caret(el, 6);
|
|
6385
|
-
typeKeys(el, typed);
|
|
6386
|
-
await blur(el);
|
|
6387
|
-
expect(yearText(el)).to.equal(expected);
|
|
6388
|
-
const [ev] = await apply(el);
|
|
6389
|
-
expect(yearOf(ev.detail.value)).to.equal(2000 + Number(expected));
|
|
6390
|
-
});
|
|
6391
|
-
}
|
|
6392
|
-
it('Y2e. partial overtype never rewrites the digits: 2026 → 1026 → 1926 → 1996 → clamp on the 4th', async () => {
|
|
6393
|
-
const el = await build({ fmt: 'DD/MM/YYYY', ...win, value: SEED('2026') });
|
|
6394
|
-
caret(el, 6);
|
|
6395
|
-
const seen = [];
|
|
6396
|
-
for (const ch of '1999') {
|
|
6397
|
-
press(el, ch);
|
|
6398
|
-
seen.push(yearText(el));
|
|
6399
|
-
}
|
|
6400
|
-
expect(seen).to.deep.equal(['1026', '1926', '1996', '2020']);
|
|
6401
|
-
});
|
|
6402
|
-
it('Y2f. wide window (1900-3000): overtyping 1999 and 2030 shows no clamped intermediate (1900 / 2036 flicker)', async () => {
|
|
6403
|
-
const a = await build({ fmt: 'DD/MM/YYYY', value: SEED('2026') });
|
|
6404
|
-
caret(a, 6);
|
|
6405
|
-
const seenA = [];
|
|
6406
|
-
for (const ch of '1999') {
|
|
6407
|
-
press(a, ch);
|
|
6408
|
-
seenA.push(yearText(a));
|
|
6409
|
-
}
|
|
6410
|
-
expect(seenA).to.deep.equal(['1026', '1926', '1996', '1999']);
|
|
6411
|
-
const b = await build({ fmt: 'DD/MM/YYYY', value: SEED('2026') });
|
|
6412
|
-
caret(b, 6);
|
|
6413
|
-
const seenB = [];
|
|
6414
|
-
for (const ch of '2030') {
|
|
6415
|
-
press(b, ch);
|
|
6416
|
-
seenB.push(yearText(b));
|
|
6417
|
-
}
|
|
6418
|
-
expect(seenB).to.deep.equal(['2026', '2026', '2036', '2030']);
|
|
6419
|
-
});
|
|
6420
|
-
it('Y2g. a half-typed year is clamped on blur and does not reach the calendar while typing', async () => {
|
|
6421
|
-
const el = await build({ fmt: 'DD/MM/YYYY', ...win, value: SEED('2026') });
|
|
6422
|
-
caret(el, 6);
|
|
6423
|
-
typeKeys(el, '19'); // 1926: abandoned mid-edit
|
|
6424
|
-
expect(calOf(el).currentYear, 'calendar not driven by 1926').to.equal(2026);
|
|
6425
|
-
await blur(el);
|
|
6426
|
-
expect(yearText(el)).to.equal('2020');
|
|
6427
|
-
expect(calOf(el).currentYear).to.equal(2020);
|
|
6428
|
-
});
|
|
6429
|
-
it('Y2h. editing another segment first normalises an abandoned year edit', async () => {
|
|
6430
|
-
const el = await build({ fmt: 'DD/MM/YYYY', ...win, value: SEED('2026') });
|
|
6431
|
-
caret(el, 6);
|
|
6432
|
-
typeKeys(el, '19'); // 1926
|
|
6433
|
-
caret(el, 0);
|
|
6434
|
-
typeKeys(el, '17');
|
|
6435
|
-
expect(yearText(el)).to.equal('2020');
|
|
6436
|
-
expect(calOf(el).currentYear).to.equal(2020);
|
|
6437
|
-
});
|
|
6438
|
-
it('Y2i2. focusing, selecting and blurring an unchanged out-of-range seeded year does not clamp it or emit', async () => {
|
|
6439
|
-
const el = await build({ fmt: 'DD/MM/YYYY', ...win, value: SEED('2010') });
|
|
6440
|
-
const events = [];
|
|
6441
|
-
for (const n of ['nile-change', 'nile-changed', 'nile-input'])
|
|
6442
|
-
el.addEventListener(n, () => events.push(n));
|
|
6443
|
-
caret(el, 0);
|
|
6444
|
-
await blur(el);
|
|
6445
|
-
caret(el, 6, 10); // select the whole year, change nothing
|
|
6446
|
-
await blur(el);
|
|
6447
|
-
caret(el, 6);
|
|
6448
|
-
press(el, 'ArrowRight');
|
|
6449
|
-
await blur(el);
|
|
6450
|
-
expect(yearText(el)).to.equal('2010');
|
|
6451
|
-
expect(calOf(el).value.getFullYear()).to.equal(2010);
|
|
6452
|
-
expect(events).to.deep.equal([]);
|
|
6453
|
-
});
|
|
6454
|
-
it('Y2i3. completing an explicit year edit clamps it, whichever digits were typed', async () => {
|
|
6455
|
-
const el = await build({ fmt: 'DD/MM/YYYY', ...win, value: SEED('2010') });
|
|
6456
|
-
caret(el, 6);
|
|
6457
|
-
typeKeys(el, '2011'); // changed digits, still out of range
|
|
6458
|
-
await blur(el);
|
|
6459
|
-
expect(yearText(el)).to.equal('2020');
|
|
6460
|
-
const same = await build({ fmt: 'DD/MM/YYYY', ...win, value: SEED('2010') });
|
|
6461
|
-
caret(same, 6);
|
|
6462
|
-
typeKeys(same, '2010'); // the same digits, completed by typing
|
|
6463
|
-
await blur(same);
|
|
6464
|
-
expect(yearText(same)).to.equal('2020');
|
|
6465
|
-
});
|
|
6466
|
-
it('Y2i4. YY: an out-of-range seeded 1999 survives an edit to another segment', async () => {
|
|
6467
|
-
const el = await build({ fmt: 'DD/MM/YY', start: 2000, end: 2050, value: SEED('1999') });
|
|
6468
|
-
caret(el, 0);
|
|
6469
|
-
typeKeys(el, '17');
|
|
6470
|
-
await blur(el);
|
|
6471
|
-
expect(yearText(el)).to.equal('99');
|
|
6472
|
-
const [ev] = await apply(el);
|
|
6473
|
-
expect(ev.detail.value).to.match(/^1999-06-17T/);
|
|
6474
|
-
});
|
|
6475
|
-
it('Y2i. a seeded year outside the range survives an edit to another segment (seedMask)', async () => {
|
|
6476
|
-
const el = await build({ fmt: 'DD/MM/YYYY', ...win, value: SEED('2010') });
|
|
6477
|
-
expect(yearText(el)).to.equal('2010');
|
|
6478
|
-
caret(el, 0);
|
|
6479
|
-
typeKeys(el, '17');
|
|
6480
|
-
await blur(el);
|
|
6481
|
-
expect(yearText(el)).to.equal('2010');
|
|
6482
|
-
});
|
|
6483
|
-
const leap = [
|
|
6484
|
-
['2032', '29/02/2032', '2032-02-29'],
|
|
6485
|
-
['2036', '29/02/2036', '2036-02-29'],
|
|
6486
|
-
['2031', '28/02/2031', '2031-02-28'],
|
|
6487
|
-
];
|
|
6488
|
-
for (const [typed, shown, iso] of leap) {
|
|
6489
|
-
it(`Y2j. seeded 2028-02-29, retype ${typed} → ${shown}`, async () => {
|
|
6490
|
-
const el = await build({ fmt: 'DD/MM/YYYY', value: SEED('2028', '02-29') });
|
|
6491
|
-
caret(el, 6);
|
|
6492
|
-
typeKeys(el, typed);
|
|
6493
|
-
expect(textOf(el).slice(0, 10), 'trigger').to.equal(shown);
|
|
6494
|
-
await blur(el);
|
|
6495
|
-
const [ev] = await apply(el);
|
|
6496
|
-
expect(ev.detail.value).to.match(new RegExp(`^${iso}T`));
|
|
6497
|
-
});
|
|
6498
|
-
}
|
|
6499
|
-
it('Y2k. the day is not clamped against an intermediate year (2028 → 203x keeps 29 until the year is final)', async () => {
|
|
6500
|
-
const el = await build({ fmt: 'DD/MM/YYYY', value: SEED('2028', '02-29') });
|
|
6501
|
-
caret(el, 6);
|
|
6502
|
-
const days = [];
|
|
6503
|
-
for (const ch of '2032') {
|
|
6504
|
-
press(el, ch);
|
|
6505
|
-
days.push(textOf(el).slice(0, 2));
|
|
6506
|
-
}
|
|
6507
|
-
expect(days).to.deep.equal(['29', '29', '29', '29']);
|
|
6508
|
-
});
|
|
6509
|
-
it('Y2l. YY seeded 2028-02-29, retype 32 → 29/02/32', async () => {
|
|
6510
|
-
const el = await build({ fmt: 'DD/MM/YY', value: SEED('2028', '02-29') });
|
|
6511
|
-
caret(el, 6);
|
|
6512
|
-
typeKeys(el, '32');
|
|
6513
|
-
expect(textOf(el).slice(0, 8)).to.equal('29/02/32');
|
|
6514
|
-
});
|
|
6515
|
-
it('Y2m. segmented time input is unchanged: 25 into hours still yields 02', async () => {
|
|
6516
|
-
const el = await build({ fmt: 'DD/MM/YYYY', value: SEED('2026') });
|
|
6517
|
-
caret(el, textOf(el).indexOf('-') + 2);
|
|
6518
|
-
typeKeys(el, '25');
|
|
6519
|
-
expect(textOf(el)).to.match(/ - 02:20:30\.000/);
|
|
6520
|
-
});
|
|
6521
|
-
});
|
|
6522
|
-
// ── Y3. calendar view synchronisation ───────────────────────────────────────
|
|
6523
|
-
describe('Y3. year/month dropdowns navigate only; reopening shows the selected date', () => {
|
|
6524
|
-
const matrix = [
|
|
6525
|
-
['DD/MM/YY', { fmt: 'DD/MM/YY' }],
|
|
6526
|
-
['DD/MM/YYYY', { fmt: 'DD/MM/YYYY' }],
|
|
6527
|
-
['DD/MM/YY, hours+minutes hidden', { fmt: 'DD/MM/YY', hide: ['hours', 'minutes'] }],
|
|
6528
|
-
['DD/MM/YYYY, hours+minutes hidden', { fmt: 'DD/MM/YYYY', hide: ['hours', 'minutes'] }],
|
|
6529
|
-
];
|
|
6530
|
-
for (const [label, base] of matrix) {
|
|
6531
|
-
const seeded = () => build({ ...base, dropdowns: true, value: '2026-10-13T00:00:00.000[GMT+00:00 UTC]' });
|
|
6532
|
-
it(`Y3a. [${label}] picking a year without a day leaves the selection, value and trigger unchanged`, async () => {
|
|
6533
|
-
const el = await seeded();
|
|
6534
|
-
const before = textOf(el);
|
|
6535
|
-
const events = [];
|
|
6536
|
-
for (const n of ['nile-change', 'nile-changed'])
|
|
6537
|
-
el.addEventListener(n, () => events.push(n));
|
|
6538
|
-
await pickYear(el, 2020);
|
|
6539
|
-
expect(calOf(el).currentYear).to.equal(2020);
|
|
6540
|
-
expect(calOf(el).value.getFullYear(), 'selected date').to.equal(2026);
|
|
6541
|
-
expect(yearOf(el.value)).to.equal(2026);
|
|
6542
|
-
expect(textOf(el)).to.equal(before);
|
|
6543
|
-
expect(events, 'navigation emits no change').to.deep.equal([]);
|
|
6544
|
-
});
|
|
6545
|
-
it(`Y3b. [${label}] picking a year then Apply commits the selected date, once, without a navigation-induced extra change`, async () => {
|
|
6546
|
-
const el = await seeded();
|
|
6547
|
-
await pickYear(el, 2020);
|
|
6548
|
-
const events = await apply(el);
|
|
6549
|
-
expect(events).to.have.length(1);
|
|
6550
|
-
expect(events[0].detail.value).to.match(/^2026-10-13T/);
|
|
6551
|
-
expect(new Date(events[0].detail.unixEpoch).getUTCFullYear()).to.equal(2026);
|
|
6552
|
-
expect(yearOf(el.value)).to.equal(2026);
|
|
6553
|
-
});
|
|
6554
|
-
it(`Y3c. [${label}] picking a year then a day selects that day in the picked year`, async () => {
|
|
6555
|
-
const el = await seeded();
|
|
6556
|
-
await pickYear(el, 2020);
|
|
6557
|
-
const cal = calOf(el);
|
|
6558
|
-
cal.shadowRoot.querySelectorAll('.day_date:not(.filler)')[3].click();
|
|
6559
|
-
await cal.updateComplete;
|
|
6560
|
-
expect(cal.value.getFullYear()).to.equal(2020);
|
|
6561
|
-
const [ev] = await apply(el);
|
|
6562
|
-
expect(yearOf(ev.detail.value)).to.equal(2020);
|
|
6563
|
-
expect(new Date(ev.detail.unixEpoch).getUTCFullYear()).to.equal(2020);
|
|
6564
|
-
});
|
|
6565
|
-
it(`Y3d. [${label}] picking a month without a day leaves the selected date unchanged`, async () => {
|
|
6566
|
-
const el = await seeded();
|
|
6567
|
-
await pickMonth(el, 2);
|
|
6568
|
-
expect(calOf(el).currentMonth).to.equal(2);
|
|
6569
|
-
expect(calOf(el).value.getMonth(), 'selected month').to.equal(9);
|
|
6570
|
-
const [ev] = await apply(el);
|
|
6571
|
-
expect(ev.detail.value).to.match(/^2026-10-13T/);
|
|
6572
|
-
});
|
|
6573
|
-
it(`Y3e. [${label}] Apply → close → reopen shows the committed month and year`, async () => {
|
|
6574
|
-
const el = await seeded();
|
|
6575
|
-
await openPanel(el);
|
|
6576
|
-
await pickYear(el, 2020);
|
|
6577
|
-
await pickMonth(el, 2);
|
|
6578
|
-
await apply(el);
|
|
6579
|
-
await closePanel(el);
|
|
6580
|
-
await openPanel(el);
|
|
6581
|
-
expect(calOf(el).currentYear, 'year').to.equal(2026);
|
|
6582
|
-
expect(calOf(el).currentMonth, 'month').to.equal(9);
|
|
6583
|
-
expect(yearOf(el.value), 'committed date unchanged').to.equal(2026);
|
|
6584
|
-
});
|
|
6585
|
-
}
|
|
6586
|
-
it('Y3f. browsing while the panel is open is not reset; dismissing without Apply keeps the view as it was left', async () => {
|
|
6587
|
-
const el = await build({ dropdowns: true, value: '2026-10-13T00:00:00.000[GMT+00:00 UTC]' });
|
|
6588
|
-
await openPanel(el);
|
|
6589
|
-
await pickYear(el, 2020);
|
|
6590
|
-
await new Promise(r => setTimeout(r, 150));
|
|
6591
|
-
expect(calOf(el).currentYear, 'still browsing').to.equal(2020);
|
|
6592
|
-
await closePanel(el);
|
|
6593
|
-
await openPanel(el);
|
|
6594
|
-
expect(calOf(el).currentYear, 'existing dismissal semantics: the browsed view is kept').to.equal(2020);
|
|
6595
|
-
expect(calOf(el).value.getFullYear(), 'selection untouched').to.equal(2026);
|
|
6596
|
-
expect(yearOf(el.value), 'committed value untouched').to.equal(2026);
|
|
6597
|
-
});
|
|
6598
|
-
it('Y3i. a pending (unapplied) selection survives dismissal and reopening, and Apply then commits it', async () => {
|
|
6599
|
-
const el = await build({ dropdowns: true, value: '2026-10-13T00:00:00.000[GMT+00:00 UTC]' });
|
|
6600
|
-
const events = [];
|
|
6601
|
-
el.addEventListener('nile-change', ((e) => events.push(e)));
|
|
6602
|
-
await openPanel(el);
|
|
6603
|
-
await pickYear(el, 2020);
|
|
6604
|
-
const cal = calOf(el);
|
|
6605
|
-
cal.shadowRoot.querySelectorAll('.day_date:not(.filler)')[3].click();
|
|
6606
|
-
await cal.updateComplete;
|
|
6607
|
-
const pending = cal.value.getTime();
|
|
6608
|
-
expect(cal.value.getFullYear()).to.equal(2020);
|
|
6609
|
-
await closePanel(el); // dismissed, not applied
|
|
6610
|
-
expect(events, 'dismissal emits nothing').to.have.length(0);
|
|
6611
|
-
expect(yearOf(el.value), 'committed value unchanged').to.equal(2026);
|
|
6612
|
-
await openPanel(el);
|
|
6613
|
-
expect(cal.value.getTime(), 'pending selection kept').to.equal(pending);
|
|
6614
|
-
expect(cal.currentYear, 'and still visible').to.equal(2020);
|
|
6615
|
-
const [ev] = await apply(el);
|
|
6616
|
-
expect(yearOf(ev.detail.value)).to.equal(2020);
|
|
6617
|
-
});
|
|
6618
|
-
it('Y3j. after Apply the next reopen shows the committed month and year even when another year was browsed first', async () => {
|
|
6619
|
-
const el = await build({ dropdowns: true, value: '2026-10-13T00:00:00.000[GMT+00:00 UTC]' });
|
|
6620
|
-
await openPanel(el);
|
|
6621
|
-
await pickYear(el, 2020);
|
|
6622
|
-
await apply(el); // commits the selected 2026-10-13
|
|
6623
|
-
await closePanel(el);
|
|
6624
|
-
await openPanel(el);
|
|
6625
|
-
expect(calOf(el).currentYear).to.equal(2026);
|
|
6626
|
-
expect(calOf(el).currentMonth).to.equal(9);
|
|
6627
|
-
// the sync is one-shot: browsing and dismissing again keeps that view
|
|
6628
|
-
await pickYear(el, 2021);
|
|
6629
|
-
await closePanel(el);
|
|
6630
|
-
await openPanel(el);
|
|
6631
|
-
expect(calOf(el).currentYear).to.equal(2021);
|
|
6632
|
-
});
|
|
6633
|
-
it('Y3g. an initially empty picker: navigation commits nothing, and reopening does not invent a selection', async () => {
|
|
6634
|
-
const el = await build({ dropdowns: true });
|
|
6635
|
-
const events = [];
|
|
6636
|
-
el.addEventListener('nile-change', () => events.push('nile-change'));
|
|
6637
|
-
await openPanel(el);
|
|
6638
|
-
await pickYear(el, 2020);
|
|
6639
|
-
expect(calOf(el).value).to.be.null;
|
|
6640
|
-
expect(el.value ?? null).to.be.null;
|
|
6641
|
-
expect(textOf(el)).to.equal('');
|
|
6642
|
-
await closePanel(el);
|
|
6643
|
-
await openPanel(el);
|
|
6644
|
-
expect(calOf(el).value).to.be.null;
|
|
6645
|
-
expect(calOf(el).currentYear, 'empty picker keeps its own view').to.equal(2020);
|
|
6646
|
-
expect(events).to.deep.equal([]);
|
|
6647
|
-
});
|
|
6648
|
-
it('Y3h. an empty picker: select a day in 2020, Apply, reopen → shows 2020', async () => {
|
|
6649
|
-
const el = await build({ dropdowns: true });
|
|
6650
|
-
await openPanel(el);
|
|
6651
|
-
await pickYear(el, 2020);
|
|
6652
|
-
const cal = calOf(el);
|
|
6653
|
-
cal.shadowRoot.querySelectorAll('.day_date:not(.filler)')[3].click();
|
|
6654
|
-
await cal.updateComplete;
|
|
6655
|
-
const [ev] = await apply(el);
|
|
6656
|
-
expect(yearOf(ev.detail.value)).to.equal(2020);
|
|
6657
|
-
await closePanel(el);
|
|
6658
|
-
await openPanel(el);
|
|
6659
|
-
expect(calOf(el).currentYear).to.equal(2020);
|
|
6660
|
-
});
|
|
6661
|
-
});
|
|
6662
|
-
});
|
|
6663
|
-
describe('NileDateTimePicker values: a clock face that is not a time of day is unparseable, never rolled into the next day', () => {
|
|
6664
|
-
const textOf = (el) => el.shadowRoot.querySelector('nile-input').input.value;
|
|
6665
|
-
const make = async (value, format = 'DD/MM/YYYY') => {
|
|
6666
|
-
const el = await fixture(html `<nile-date-time-picker dateFormat=${format} value=${value}></nile-date-time-picker>`);
|
|
6667
|
-
await el.updateComplete;
|
|
6668
|
-
await el.calendarElement.updateComplete;
|
|
6669
|
-
await new Promise(r => setTimeout(r, 120));
|
|
6670
|
-
return el;
|
|
6671
|
-
};
|
|
6672
|
-
const applyOnce = async (el) => {
|
|
6673
|
-
const events = [];
|
|
6674
|
-
el.addEventListener('nile-change', (e) => events.push(e.detail));
|
|
6675
|
-
el.calendarElement.shadowRoot.querySelector('.apply-button').dispatchEvent(new MouseEvent('click', { bubbles: true, composed: true }));
|
|
6676
|
-
await new Promise(r => setTimeout(r, 80));
|
|
6677
|
-
return events;
|
|
6678
|
-
};
|
|
6679
|
-
for (const value of [
|
|
6680
|
-
'2026-03-01T25:61:00', '2026-03-01T10:61:00', '2026-03-01T10:30:61', '2026-03-01T24:00:01',
|
|
6681
|
-
'2026-03-01T25:61:00.000[GMT+00:00 UTC]', '2026-03-01T10:61:00.000[GMT+00:00 UTC]',
|
|
6682
|
-
]) {
|
|
6683
|
-
it(`V1. ${value} leaves the picker empty: no trigger text, no selection, and Apply emits nothing`, async () => {
|
|
6684
|
-
const el = await make(value);
|
|
6685
|
-
expect(textOf(el), 'trigger text').to.equal('');
|
|
6686
|
-
expect(el.calendarElement.value ?? null, 'calendar selection').to.be.null;
|
|
6687
|
-
expect(await applyOnce(el), 'Apply').to.have.length(0);
|
|
6688
|
-
});
|
|
6689
|
-
}
|
|
6690
|
-
for (const [value, text] of [
|
|
6691
|
-
['2026-03-01T24:00:00', '02/03/2026 - 00:00:00.000'],
|
|
6692
|
-
['2026-03-01T24:00:00.000', '02/03/2026 - 00:00:00.000'],
|
|
6693
|
-
['2026-03-01T24:00:00.000[GMT+00:00 UTC]', '02/03/2026 - 00:00:00.000'],
|
|
6694
|
-
]) {
|
|
6695
|
-
it(`V2. ${value} (ISO end-of-day) still resolves to the next midnight`, async () => {
|
|
6696
|
-
const el = await make(value);
|
|
6697
|
-
expect(textOf(el).startsWith(text), textOf(el)).to.be.true;
|
|
6698
|
-
});
|
|
6699
|
-
}
|
|
6700
|
-
for (const value of ['2026-03-01T24:00:00', '2026-03-01T24:00:00.000', '2026-03-01T24:00:00.000[GMT+00:00 UTC]']) {
|
|
6701
|
-
it(`V2b. ${value}: the trigger and the Calendar panel agree on the next day, and Apply emits it`, async () => {
|
|
6702
|
-
const el = await make(value);
|
|
6703
|
-
expect(textOf(el).startsWith('02/03/2026 - 00:00:00.000'), `trigger ${textOf(el)}`).to.be.true;
|
|
6704
|
-
const sel = el.calendarElement.value;
|
|
6705
|
-
expect([sel.getFullYear(), sel.getMonth() + 1, sel.getDate()], 'panel selection').to.deep.equal([2026, 3, 2]);
|
|
6706
|
-
expect(el.calendarElement.shadowRoot.querySelector('.apply-button').hasAttribute('disabled'), 'Apply enabled').to.be.false;
|
|
6707
|
-
const events = await applyOnce(el);
|
|
6708
|
-
expect(events).to.have.length(1);
|
|
6709
|
-
expect(events[0].value).to.include('2026-03-02T00:00:00');
|
|
6710
|
-
});
|
|
6711
|
-
}
|
|
6712
|
-
it('V3. valid values, date-only seeding and the month-end clamp are unchanged', async () => {
|
|
6713
|
-
expect(textOf(await make('2026-03-01T23:59:59.999')).startsWith('01/03/2026 - 23:59:59.999')).to.be.true;
|
|
6714
|
-
expect(textOf(await make('2026-03-01')).startsWith('01/03/2026 - 00:00:00.000')).to.be.true;
|
|
6715
|
-
expect(textOf(await make('2026-02-31T10:00:00')).startsWith('28/02/2026 - 10:00:00.000')).to.be.true;
|
|
6716
|
-
expect(textOf(await make('2026-06-15T10:20:30.000[GMT+00:00 UTC]')).startsWith('15/06/2026 - 10:20:30.000')).to.be.true;
|
|
6717
|
-
});
|
|
6718
|
-
it('V4. the same rule is shared: isClockTime accepts exactly what the picker accepts', () => {
|
|
6719
|
-
expect(isClockTime(24, 0, 0, 0)).to.be.true;
|
|
6720
|
-
expect(isClockTime(25, 61, 0, 0)).to.be.false;
|
|
6721
|
-
});
|
|
6722
|
-
it('V5. correcting a rejected value recovers normally', async () => {
|
|
6723
|
-
const el = await make('2026-03-01T25:61:00');
|
|
6724
|
-
expect(textOf(el)).to.equal('');
|
|
6725
|
-
el.value = '2026-03-01T10:30:00';
|
|
6726
|
-
await el.updateComplete;
|
|
6727
|
-
await el.calendarElement.updateComplete;
|
|
6728
|
-
await new Promise(r => setTimeout(r, 150));
|
|
6729
|
-
expect(textOf(el).startsWith('01/03/2026 - 10:30:00.000')).to.be.true;
|
|
6730
|
-
const [ev] = await applyOnce(el);
|
|
6731
|
-
expect(ev.value).to.match(/^2026-03-01T10:30:00\.000\[GMT\+00:00 UTC\]$/);
|
|
6732
|
-
});
|
|
6733
|
-
});
|
|
6734
|
-
describe('NileDateTimePicker — Escape returns focus to the trigger', () => {
|
|
6735
|
-
const make = async () => {
|
|
6736
|
-
const el = await fixture(html `<nile-date-time-picker timezone="UTC"></nile-date-time-picker>`);
|
|
6737
|
-
await el.updateComplete;
|
|
6738
|
-
return el;
|
|
6739
|
-
};
|
|
6740
|
-
const triggerNative = (el) => el.shadowRoot.querySelector('nile-input').shadowRoot.querySelector('input');
|
|
6741
|
-
const triggerHasFocus = (el) => el.shadowRoot.querySelector('nile-input').shadowRoot.activeElement === triggerNative(el);
|
|
6742
|
-
const open = async (el) => {
|
|
6743
|
-
el.open = true;
|
|
6744
|
-
await el.updateComplete;
|
|
6745
|
-
await el.calendarElement.updateComplete;
|
|
6746
|
-
await aTimeout(300);
|
|
6747
|
-
};
|
|
6748
|
-
// the popper is portaled, so the calendar is a direct child of <body> as seen by document.activeElement
|
|
6749
|
-
const focusInPanel = (el) => {
|
|
6750
|
-
const cal = el.calendarElement;
|
|
6751
|
-
cal.shadowRoot.querySelector('[aria-label="Next month"]').focus();
|
|
6752
|
-
expect(document.activeElement, 'focus is inside the panel').to.equal(cal);
|
|
6753
|
-
};
|
|
6754
|
-
const pressEscape = (target) => target.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, composed: true, cancelable: true }));
|
|
6755
|
-
it('EF1. Escape with focus inside the panel closes it and focuses the trigger', async () => {
|
|
6756
|
-
const el = await make();
|
|
6757
|
-
await open(el);
|
|
6758
|
-
focusInPanel(el);
|
|
6759
|
-
pressEscape(document.activeElement);
|
|
6760
|
-
await aTimeout(400);
|
|
6761
|
-
expect(el.open).to.be.false;
|
|
6762
|
-
expect(triggerHasFocus(el), 'trigger input has focus').to.be.true;
|
|
6763
|
-
});
|
|
6764
|
-
it('EF2. Escape with focus on the trigger closes the panel and keeps focus there', async () => {
|
|
6765
|
-
const el = await make();
|
|
6766
|
-
triggerNative(el).focus();
|
|
6767
|
-
await open(el);
|
|
6768
|
-
triggerNative(el).focus();
|
|
6769
|
-
pressEscape(triggerNative(el));
|
|
6770
|
-
await aTimeout(400);
|
|
6771
|
-
expect(el.open).to.be.false;
|
|
6772
|
-
expect(triggerHasFocus(el)).to.be.true;
|
|
6773
|
-
});
|
|
6774
|
-
it('EF3. Escape does not pull focus from an unrelated element outside the picker', async () => {
|
|
6775
|
-
const wrap = await fixture(html `<div><button id="other">other</button><nile-date-time-picker timezone="UTC"></nile-date-time-picker></div>`);
|
|
6776
|
-
const el = wrap.querySelector('nile-date-time-picker');
|
|
6777
|
-
const other = wrap.querySelector('#other');
|
|
6778
|
-
await el.updateComplete;
|
|
6779
|
-
await open(el);
|
|
6780
|
-
other.focus();
|
|
6781
|
-
pressEscape(other);
|
|
6782
|
-
await aTimeout(400);
|
|
6783
|
-
expect(el.open).to.be.false;
|
|
6784
|
-
expect(document.activeElement).to.equal(other);
|
|
6785
|
-
});
|
|
6786
|
-
it('EF4. Escape only dismisses: no event, no commit, the pending selection survives', async () => {
|
|
6787
|
-
const el = await make();
|
|
6788
|
-
const events = [];
|
|
6789
|
-
el.addEventListener('nile-change', () => events.push('change'));
|
|
6790
|
-
el.addEventListener('nile-clear', () => events.push('clear'));
|
|
6791
|
-
await open(el);
|
|
6792
|
-
const cal = el.calendarElement;
|
|
6793
|
-
cal.shadowRoot.querySelectorAll('.day_date:not(.filler)')[5].click();
|
|
6794
|
-
await cal.updateComplete;
|
|
6795
|
-
focusInPanel(el);
|
|
6796
|
-
pressEscape(document.activeElement);
|
|
6797
|
-
await aTimeout(400);
|
|
6798
|
-
expect(el.open).to.be.false;
|
|
6799
|
-
expect(events).to.deep.equal([]);
|
|
6800
|
-
expect(el.value ?? null).to.equal(null);
|
|
6801
|
-
expect(cal.value, 'pending selection kept').to.be.instanceOf(Date);
|
|
6802
|
-
});
|
|
6803
|
-
it('EF5. other keys inside the panel do not move focus or close it', async () => {
|
|
6804
|
-
const el = await make();
|
|
6805
|
-
await open(el);
|
|
6806
|
-
focusInPanel(el);
|
|
6807
|
-
document.activeElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, composed: true }));
|
|
6808
|
-
await aTimeout(200);
|
|
6809
|
-
expect(el.open).to.be.true;
|
|
6810
|
-
expect(document.activeElement).to.equal(el.calendarElement);
|
|
6811
|
-
});
|
|
6812
|
-
});
|
|
6813
|
-
describe('NileDateTimePicker — accessible name of the role="dialog" container', () => {
|
|
6814
|
-
const make = async (attrs = '') => {
|
|
6815
|
-
const wrap = await fixture(html `<div .innerHTML=${`<nile-date-time-picker timezone="UTC" ${attrs}></nile-date-time-picker>`}></div>`);
|
|
6816
|
-
const el = wrap.querySelector('nile-date-time-picker');
|
|
6817
|
-
await el.updateComplete;
|
|
6818
|
-
return el;
|
|
6819
|
-
};
|
|
6820
|
-
const open = async (el) => {
|
|
6821
|
-
el.open = true;
|
|
6822
|
-
await el.updateComplete;
|
|
6823
|
-
await el.calendarElement.updateComplete;
|
|
6824
|
-
await aTimeout(300);
|
|
6825
|
-
};
|
|
6826
|
-
// the element that actually carries role="dialog" around this picker's calendar (the panel is portaled)
|
|
6827
|
-
const dialogOf = (el) => el.calendarElement.closest('[role="dialog"]');
|
|
6828
|
-
it('DN1. the portaled role="dialog" element has the default name', async () => {
|
|
6829
|
-
const el = await make();
|
|
6830
|
-
await open(el);
|
|
6831
|
-
const dialog = dialogOf(el);
|
|
6832
|
-
expect(dialog, 'a role=dialog ancestor of the calendar exists').to.exist;
|
|
6833
|
-
expect(dialog.getAttribute('role')).to.equal('dialog');
|
|
6834
|
-
expect(dialog.getRootNode(), 'portaled out of the picker shadow root').to.equal(document);
|
|
6835
|
-
expect(el.shadowRoot.contains(dialog)).to.be.false;
|
|
6836
|
-
expect(dialog.getAttribute('aria-label')).to.equal('Date and time picker');
|
|
6837
|
-
});
|
|
6838
|
-
it('DN2. aria-label on the picker names the dialog', async () => {
|
|
6839
|
-
const el = await make('aria-label="Start"');
|
|
6840
|
-
await open(el);
|
|
6841
|
-
expect(dialogOf(el).getAttribute('aria-label')).to.equal('Start picker');
|
|
6842
|
-
});
|
|
6843
|
-
it('DN3. a visible label names the dialog', async () => {
|
|
6844
|
-
const el = await make('label="Due date"');
|
|
6845
|
-
await open(el);
|
|
6846
|
-
expect(dialogOf(el).getAttribute('aria-label')).to.equal('Due date picker');
|
|
6847
|
-
});
|
|
6848
|
-
it('DN4. changing the label while open renames the dialog', async () => {
|
|
6849
|
-
const el = await make();
|
|
6850
|
-
await open(el);
|
|
6851
|
-
el.label = 'End';
|
|
6852
|
-
await el.updateComplete;
|
|
6853
|
-
await aTimeout(50);
|
|
6854
|
-
expect(dialogOf(el).getAttribute('aria-label')).to.equal('End picker');
|
|
6855
|
-
});
|
|
6856
|
-
it('DN5. the name survives close and reopen', async () => {
|
|
6857
|
-
const el = await make();
|
|
6858
|
-
await open(el);
|
|
6859
|
-
el.open = false;
|
|
6860
|
-
await el.updateComplete;
|
|
6861
|
-
await aTimeout(400);
|
|
6862
|
-
await open(el);
|
|
6863
|
-
expect(dialogOf(el).getAttribute('aria-label')).to.equal('Date and time picker');
|
|
6864
|
-
});
|
|
6865
|
-
it('DN6. the shared nile-floating-panel is unchanged: its own dialog stays unnamed', async () => {
|
|
6866
|
-
const wrap = await fixture(html `<div><nile-floating-panel trigger="click"><button>anchor</button><p>content</p></nile-floating-panel></div>`);
|
|
6867
|
-
const fp = wrap.querySelector('nile-floating-panel');
|
|
6868
|
-
await fp.updateComplete;
|
|
6869
|
-
fp.show();
|
|
6870
|
-
await aTimeout(300);
|
|
6871
|
-
const dialogs = [...document.querySelectorAll('[role="dialog"]')].filter(d => d.textContent.includes('content'));
|
|
6872
|
-
expect(dialogs.length).to.be.greaterThan(0);
|
|
6873
|
-
dialogs.forEach(d => expect(d.hasAttribute('aria-label'), 'no aria-label added globally').to.be.false);
|
|
6874
|
-
fp.hide();
|
|
6875
|
-
});
|
|
6876
|
-
});
|
|
6877
|
-
describe('Y18. a `value` string is read only in the documented formats, never through engine-dependent Date parsing', () => {
|
|
6878
|
-
const make = async (value, timezone = 'UTC') => {
|
|
6879
|
-
const el = await fixture(html `<nile-date-time-picker
|
|
6880
|
-
.timezone=${timezone} dateFormat="DD/MM/YYYY" .hideTimeFields=${['timezone']}
|
|
6881
|
-
.startYear=${0} .endYear=${9999} value=${value}></nile-date-time-picker>`);
|
|
6882
|
-
await settle2(el);
|
|
6883
|
-
return el;
|
|
6884
|
-
};
|
|
6885
|
-
const textOf = (el) => el.shadowRoot.querySelector('nile-input').input.value;
|
|
6886
|
-
const p = (n, l = 2) => String(n).padStart(l, '0');
|
|
6887
|
-
const SUPPORTED = [
|
|
6888
|
-
{ label: 'date-only', value: '2026-03-05', tz: 'UTC', text: '05/03/2026 - 00:00:00.000' },
|
|
6889
|
-
{ label: 'date-only, impossible day clamps to month end', value: '2026-02-31', tz: 'UTC', text: '28/02/2026 - 00:00:00.000' },
|
|
6890
|
-
{ label: 'date-only, year 0-99 keeps its literal year', value: '0050-03-05', tz: 'UTC', text: '05/03/0050 - 00:00:00.000' },
|
|
6891
|
-
{ label: 'offset-less, no seconds', value: '2026-03-05T10:20', tz: 'UTC', text: '05/03/2026 - 10:20:00.000' },
|
|
6892
|
-
{ label: 'offset-less, seconds and milliseconds', value: '2026-03-05T10:20:30.250', tz: 'UTC', text: '05/03/2026 - 10:20:30.250' },
|
|
6893
|
-
{ label: 'offset-less ignores the component zone', value: '2026-03-05T10:20:30.250', tz: 'Asia/Kolkata', text: '05/03/2026 - 10:20:30.250' },
|
|
6894
|
-
{ label: 'UTC instant read in Asia/Kolkata', value: '2026-03-05T10:00:00Z', tz: 'Asia/Kolkata', text: '05/03/2026 - 15:30:00.000' },
|
|
6895
|
-
{ label: 'UTC instant read in America/New_York', value: '2026-03-05T10:00:00Z', tz: 'America/New_York', text: '05/03/2026 - 05:00:00.000' },
|
|
6896
|
-
{ label: 'offset instant read in UTC', value: '2026-03-05T10:00:00+05:30', tz: 'UTC', text: '05/03/2026 - 04:30:00.000' },
|
|
6897
|
-
{ label: 'bracketed value keeps the digits as written', value: '2026-03-05T10:20:30.250[GMT+05:30 Asia/Kolkata]', tz: 'UTC', text: '05/03/2026 - 10:20:30.250' },
|
|
6898
|
-
];
|
|
6899
|
-
for (const c of SUPPORTED) {
|
|
6900
|
-
it(`Y18 supported — ${c.label}: ${c.value} in ${c.tz}`, async () => {
|
|
6901
|
-
const el = await make(c.value, c.tz);
|
|
6902
|
-
expect(textOf(el)).to.equal(c.text);
|
|
6903
|
-
}).timeout(60000);
|
|
6904
|
-
}
|
|
6905
|
-
it('Y18 a bracketed value adopts its own zone; an unknown bracket zone falls back to UTC with the digits kept', async () => {
|
|
6906
|
-
const known = await make('2026-03-05T10:20:30.250[GMT+05:30 Asia/Kolkata]', 'UTC');
|
|
6907
|
-
expect(known.timezone).to.equal('Asia/Kolkata');
|
|
6908
|
-
const unknown = await make('2026-03-05T10:20:30.250[GMT+05:30 Mars/Phobos]', 'Asia/Kolkata');
|
|
6909
|
-
expect(unknown.timezone).to.equal('UTC');
|
|
6910
|
-
expect(textOf(unknown)).to.equal('05/03/2026 - 10:20:30.250');
|
|
6911
|
-
}).timeout(60000);
|
|
6912
|
-
it('Y18 an instant with an unusable zone reads in the browser zone, as before', async () => {
|
|
6913
|
-
const host = new Date(Date.UTC(2026, 2, 5, 10, 0, 0, 0));
|
|
6914
|
-
const want = `${p(host.getDate())}/${p(host.getMonth() + 1)}/${host.getFullYear()}` +
|
|
6915
|
-
` - ${p(host.getHours())}:${p(host.getMinutes())}:${p(host.getSeconds())}.${p(host.getMilliseconds(), 3)}`;
|
|
6916
|
-
const el = await make('2026-03-05T10:00:00Z', 'Mars/Phobos');
|
|
6917
|
-
expect(textOf(el)).to.equal(want);
|
|
6918
|
-
}).timeout(60000);
|
|
6919
|
-
// strings a lenient engine (Date.parse) reads, in a browser-specific way; the documented formats are the only contract
|
|
6920
|
-
const ENGINE_ONLY = [
|
|
6921
|
-
'March 5 2026', '5 Mar 2026 10:00', '2026/03/05', '2026-3-5', '03/05/2026',
|
|
6922
|
-
'2026-03-05 10:00', 'Thu, 05 Mar 2026 10:00:00 GMT',
|
|
6923
|
-
];
|
|
6924
|
-
const TRAILING_GARBAGE = [
|
|
6925
|
-
'2026-03-05garbage',
|
|
6926
|
-
'2026-03-05T10:20 garbage',
|
|
6927
|
-
'2026-03-05T10:20:30.250xyz',
|
|
6928
|
-
'2026-03-05T10:00:00Zjunk',
|
|
6929
|
-
'2026-03-05T10:00:00+05:30junk',
|
|
6930
|
-
'2026-03-05T10:20:30.250[GMT+05:30 Asia/Kolkata]junk',
|
|
6931
|
-
];
|
|
6932
|
-
it('Y18 premise: this browser does read the engine-only strings, so the rejections below are the picker\'s own', () => {
|
|
6933
|
-
expect(isNaN(new Date('March 5 2026').getTime())).to.equal(false);
|
|
6934
|
-
expect(isNaN(new Date('2026/03/05').getTime())).to.equal(false);
|
|
6935
|
-
});
|
|
6936
|
-
for (const bad of [...ENGINE_ONLY, ...TRAILING_GARBAGE]) {
|
|
6937
|
-
it(`Y18 unsupported ${JSON.stringify(bad)}: the trigger is emptied, the value and zone are left alone`, async () => {
|
|
6938
|
-
const el = await make('2026-06-15T10:20:30.000[GMT+05:30 Asia/Kolkata]', 'Asia/Kolkata');
|
|
6939
|
-
expect(textOf(el), 'precondition').to.contain('15/06/2026');
|
|
6940
|
-
el.value = bad;
|
|
6941
|
-
await settle2(el);
|
|
6942
|
-
expect(textOf(el), 'trigger text').to.equal('');
|
|
6943
|
-
expect(el.value, 'the consumer\'s value is never rewritten').to.equal(bad);
|
|
6944
|
-
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
6945
|
-
}).timeout(60000);
|
|
6946
|
-
}
|
|
6947
|
-
describe('the text of a calendar `nile-change` payload', () => {
|
|
6948
|
-
const emit = async (el, value) => {
|
|
6949
|
-
el.calendarElement.dispatchEvent(new CustomEvent('nile-change', {
|
|
6950
|
-
detail: { value, timezone: 'UTC' }, bubbles: true, composed: true,
|
|
6951
|
-
}));
|
|
6952
|
-
await settle2(el);
|
|
6953
|
-
};
|
|
6954
|
-
const WANT = '15/06/2026 - 14:30:00.000';
|
|
6955
|
-
for (const ok of ['2026-06-15T14:30:00.000[GMT+00:00 UTC]', '2026-06-15T14:30:00.000']) {
|
|
6956
|
-
it(`Y18 payload accepted: ${ok}`, async () => {
|
|
6957
|
-
const el = await make('2026-01-02T03:04:05.000');
|
|
6958
|
-
await emit(el, ok);
|
|
6959
|
-
expect(textOf(el)).to.equal(WANT);
|
|
6960
|
-
}).timeout(60000);
|
|
6961
|
-
}
|
|
6962
|
-
// not a payload shape, but an absolute payload is also adopted as `value`, which re-seeds the trigger from it:
|
|
6963
|
-
// these are documented `value` formats, so the text comes from that read (an instant in the component zone, a day at midnight)
|
|
6964
|
-
for (const [adopted, text] of [
|
|
6965
|
-
['2026-06-15T14:30:00.000Z', WANT],
|
|
6966
|
-
['2026-06-15', '15/06/2026 - 00:00:00.000'],
|
|
6967
|
-
]) {
|
|
6968
|
-
it(`Y18 payload adopted as \`value\`: ${adopted}`, async () => {
|
|
6969
|
-
const el = await make('2026-01-02T03:04:05.000');
|
|
6970
|
-
await emit(el, adopted);
|
|
6971
|
-
expect(el.value).to.equal(adopted);
|
|
6972
|
-
expect(textOf(el)).to.equal(text);
|
|
6973
|
-
}).timeout(60000);
|
|
6974
|
-
}
|
|
6975
|
-
for (const bad of [
|
|
6976
|
-
'2026-06-15T14:30:00.000 junk',
|
|
6977
|
-
'2026-06-15T14:30:00.000[GMT+00:00 UTC]junk',
|
|
6978
|
-
'June 15 2026 14:30',
|
|
6979
|
-
]) {
|
|
6980
|
-
it(`Y18 payload rejected: ${JSON.stringify(bad)}`, async () => {
|
|
6981
|
-
const el = await make('2026-01-02T03:04:05.000');
|
|
6982
|
-
expect(textOf(el), 'precondition').to.contain('02/01/2026');
|
|
6983
|
-
await emit(el, bad);
|
|
6984
|
-
expect(textOf(el)).to.equal('');
|
|
6985
|
-
}).timeout(60000);
|
|
6986
|
-
}
|
|
6987
|
-
});
|
|
6988
|
-
});
|
|
6989
|
-
describe('NileDateTimePicker — keyboard open, day navigation and Tab order', () => {
|
|
6990
|
-
const make = async (value) => {
|
|
6991
|
-
const el = await fixture(html `<nile-date-time-picker timezone="UTC" .value=${value ?? ''}></nile-date-time-picker>`);
|
|
6992
|
-
await el.updateComplete;
|
|
6993
|
-
return el;
|
|
6994
|
-
};
|
|
6995
|
-
const triggerNative = (el) => el.shadowRoot.querySelector('nile-input').shadowRoot.querySelector('input');
|
|
6996
|
-
const cal = (el) => el.calendarElement;
|
|
6997
|
-
const key = (target, k, init = {}) => {
|
|
6998
|
-
const ev = new KeyboardEvent('keydown', { key: k, bubbles: true, composed: true, cancelable: true, ...init });
|
|
6999
|
-
target.dispatchEvent(ev);
|
|
7000
|
-
return ev;
|
|
7001
|
-
};
|
|
7002
|
-
const settle = async (el) => {
|
|
7003
|
-
await el.updateComplete;
|
|
7004
|
-
await cal(el).updateComplete;
|
|
7005
|
-
await aTimeout(300);
|
|
7006
|
-
};
|
|
7007
|
-
const deepActive = () => {
|
|
7008
|
-
let a = document.activeElement;
|
|
7009
|
-
while (a?.shadowRoot?.activeElement)
|
|
7010
|
-
a = a.shadowRoot.activeElement;
|
|
7011
|
-
return a;
|
|
7012
|
-
};
|
|
7013
|
-
const dayCells = (el) => [...cal(el).shadowRoot.querySelectorAll('.day_date[data-tp-date]')];
|
|
7014
|
-
const stops = (el) => dayCells(el).filter(c => c.getAttribute('tabindex') === '0');
|
|
7015
|
-
const dayOf = (c) => Number(c.getAttribute('data-tp-date').split('-')[2]);
|
|
7016
|
-
describe('opening from the field', () => {
|
|
7017
|
-
it('K1. ArrowDown opens the panel and moves focus to the day that owns the tab stop', async () => {
|
|
7018
|
-
const el = await make('2026-06-15T10:00:00.000[GMT+00:00 UTC]');
|
|
7019
|
-
triggerNative(el).focus();
|
|
7020
|
-
const ev = key(triggerNative(el), 'ArrowDown');
|
|
7021
|
-
expect(ev.defaultPrevented).to.be.true;
|
|
7022
|
-
await settle(el);
|
|
7023
|
-
expect(el.open).to.be.true;
|
|
7024
|
-
const active = deepActive();
|
|
7025
|
-
expect(active.classList.contains('day_date')).to.be.true;
|
|
7026
|
-
expect(dayOf(active), 'the selected day').to.equal(15);
|
|
7027
|
-
}).timeout(60000);
|
|
7028
|
-
it('K2. Alt+ArrowDown opens it too', async () => {
|
|
7029
|
-
const el = await make();
|
|
7030
|
-
triggerNative(el).focus();
|
|
7031
|
-
key(triggerNative(el), 'ArrowDown', { altKey: true });
|
|
7032
|
-
await settle(el);
|
|
7033
|
-
expect(el.open).to.be.true;
|
|
7034
|
-
}).timeout(60000);
|
|
7035
|
-
it('K3. Enter, Space and typed characters do not open it', async () => {
|
|
7036
|
-
const el = await make();
|
|
7037
|
-
triggerNative(el).focus();
|
|
7038
|
-
for (const k of ['Enter', ' ', '1'])
|
|
7039
|
-
key(triggerNative(el), k);
|
|
7040
|
-
await settle(el);
|
|
7041
|
-
expect(el.open).to.be.false;
|
|
7042
|
-
}).timeout(60000);
|
|
7043
|
-
it('K4. Enter on the field is not swallowed (a form can still submit)', async () => {
|
|
7044
|
-
const el = await make();
|
|
7045
|
-
triggerNative(el).focus();
|
|
7046
|
-
expect(key(triggerNative(el), 'Enter').defaultPrevented).to.be.false;
|
|
7047
|
-
}).timeout(60000);
|
|
7048
|
-
it('K5. ArrowDown does nothing when disabled or already open', async () => {
|
|
7049
|
-
const el = await make();
|
|
7050
|
-
el.disabled = true;
|
|
7051
|
-
await el.updateComplete;
|
|
7052
|
-
expect(key(triggerNative(el), 'ArrowDown').defaultPrevented).to.be.false;
|
|
7053
|
-
expect(el.open).to.be.false;
|
|
7054
|
-
el.disabled = false;
|
|
7055
|
-
el.open = true;
|
|
7056
|
-
await settle(el);
|
|
7057
|
-
expect(key(triggerNative(el), 'ArrowDown').defaultPrevented, 'already open: left to the browser').to.be.false;
|
|
7058
|
-
}).timeout(60000);
|
|
7059
|
-
it('K6. ArrowDown opens in Relative mode and focuses a control inside the panel', async () => {
|
|
7060
|
-
const el = await fixture(html `<nile-date-time-picker type="relative"></nile-date-time-picker>`);
|
|
7061
|
-
await el.updateComplete;
|
|
7062
|
-
triggerNative(el).focus();
|
|
7063
|
-
key(triggerNative(el), 'ArrowDown');
|
|
7064
|
-
await settle(el);
|
|
7065
|
-
expect(el.open).to.be.true;
|
|
7066
|
-
expect(deepActive()).to.not.equal(triggerNative(el));
|
|
7067
|
-
expect(document.activeElement, 'focus is inside the panel').to.equal(cal(el));
|
|
7068
|
-
}).timeout(60000);
|
|
7069
|
-
it('K7. opening by keyboard emits no event and commits nothing', async () => {
|
|
7070
|
-
const el = await make();
|
|
7071
|
-
const seen = [];
|
|
7072
|
-
for (const n of ['nile-change', 'nile-clear'])
|
|
7073
|
-
el.addEventListener(n, () => seen.push(n));
|
|
7074
|
-
triggerNative(el).focus();
|
|
7075
|
-
key(triggerNative(el), 'ArrowDown');
|
|
7076
|
-
await settle(el);
|
|
7077
|
-
expect(seen).to.deep.equal([]);
|
|
7078
|
-
expect(el.value || '').to.equal('');
|
|
7079
|
-
}).timeout(60000);
|
|
7080
|
-
});
|
|
7081
|
-
describe('day grid', () => {
|
|
7082
|
-
const openAt = async (value = '2026-06-15T10:00:00.000[GMT+00:00 UTC]') => {
|
|
7083
|
-
const el = await make(value);
|
|
7084
|
-
el.open = true;
|
|
7085
|
-
await settle(el);
|
|
7086
|
-
// the expanded grid shows the whole month
|
|
7087
|
-
cal(el).shadowRoot.querySelector('.tp-chevron').click();
|
|
7088
|
-
await settle(el);
|
|
7089
|
-
return el;
|
|
7090
|
-
};
|
|
7091
|
-
const press = async (el, k, init = {}) => {
|
|
7092
|
-
key(deepActive(), k, init);
|
|
7093
|
-
await settle(el);
|
|
7094
|
-
};
|
|
7095
|
-
const focusDay = (el, d) => dayCells(el).find(c => dayOf(c) === d).focus();
|
|
7096
|
-
it('K8. exactly one day is a tab stop (roving tabindex), on the selection', async () => {
|
|
7097
|
-
const el = await openAt();
|
|
7098
|
-
expect(stops(el).length).to.equal(1);
|
|
7099
|
-
expect(dayOf(stops(el)[0])).to.equal(15);
|
|
7100
|
-
}).timeout(60000);
|
|
7101
|
-
it('K9. with no selection the tab stop is today when it is in view, else the first day', async () => {
|
|
7102
|
-
const el = await make();
|
|
7103
|
-
el.open = true;
|
|
7104
|
-
await settle(el);
|
|
7105
|
-
cal(el).shadowRoot.querySelector('.tp-chevron').click();
|
|
7106
|
-
await settle(el);
|
|
7107
|
-
expect(stops(el).length).to.equal(1);
|
|
7108
|
-
expect(dayOf(stops(el)[0])).to.equal(new Date().getDate());
|
|
7109
|
-
cal(el).currentMonth = (new Date().getMonth() + 1) % 12;
|
|
7110
|
-
cal(el).currentYear = new Date().getFullYear() + (new Date().getMonth() === 11 ? 1 : 0);
|
|
7111
|
-
await settle(el);
|
|
7112
|
-
expect(dayOf(stops(el)[0]), 'first day of the other month').to.equal(1);
|
|
7113
|
-
}).timeout(60000);
|
|
7114
|
-
it('K10. Arrow keys move by a day and a week and move the tab stop with focus', async () => {
|
|
7115
|
-
const el = await openAt();
|
|
7116
|
-
focusDay(el, 15);
|
|
7117
|
-
await press(el, 'ArrowRight');
|
|
7118
|
-
expect(dayOf(deepActive())).to.equal(16);
|
|
7119
|
-
await press(el, 'ArrowLeft');
|
|
7120
|
-
await press(el, 'ArrowLeft');
|
|
7121
|
-
expect(dayOf(deepActive())).to.equal(14);
|
|
7122
|
-
await press(el, 'ArrowDown');
|
|
7123
|
-
expect(dayOf(deepActive())).to.equal(21);
|
|
7124
|
-
await press(el, 'ArrowUp');
|
|
7125
|
-
expect(dayOf(deepActive())).to.equal(14);
|
|
7126
|
-
expect(stops(el).length).to.equal(1);
|
|
7127
|
-
expect(dayOf(stops(el)[0]), 'roving tab stop follows focus').to.equal(14);
|
|
7128
|
-
}).timeout(60000);
|
|
7129
|
-
it('K11. Home and End go to the first and last day of the week', async () => {
|
|
7130
|
-
const el = await openAt(); // 15 June 2026 is a Monday
|
|
7131
|
-
focusDay(el, 15);
|
|
7132
|
-
await press(el, 'Home');
|
|
7133
|
-
expect(dayOf(deepActive())).to.equal(14);
|
|
7134
|
-
await press(el, 'End');
|
|
7135
|
-
expect(dayOf(deepActive())).to.equal(20);
|
|
7136
|
-
}).timeout(60000);
|
|
7137
|
-
it('K12. ArrowRight past the month end shows and focuses the next month', async () => {
|
|
7138
|
-
const el = await openAt('2026-06-30T10:00:00.000[GMT+00:00 UTC]');
|
|
7139
|
-
focusDay(el, 30);
|
|
7140
|
-
await press(el, 'ArrowRight');
|
|
7141
|
-
expect(cal(el).currentMonth).to.equal(6);
|
|
7142
|
-
expect(dayOf(deepActive())).to.equal(1);
|
|
7143
|
-
expect(deepActive().getAttribute('data-tp-date')).to.equal('2026-6-1');
|
|
7144
|
-
}).timeout(60000);
|
|
7145
|
-
it('K13. PageDown / PageUp move a month (clamped to its length), Shift moves a year', async () => {
|
|
7146
|
-
const el = await openAt('2026-01-31T10:00:00.000[GMT+00:00 UTC]');
|
|
7147
|
-
focusDay(el, 31);
|
|
7148
|
-
await press(el, 'PageDown');
|
|
7149
|
-
expect(cal(el).currentMonth).to.equal(1);
|
|
7150
|
-
expect(dayOf(deepActive()), '31 Jan -> 28 Feb').to.equal(28);
|
|
7151
|
-
await press(el, 'PageUp');
|
|
7152
|
-
expect(cal(el).currentMonth).to.equal(0);
|
|
7153
|
-
await press(el, 'PageDown', { shiftKey: true });
|
|
7154
|
-
expect(cal(el).currentYear).to.equal(2027);
|
|
7155
|
-
}).timeout(60000);
|
|
7156
|
-
it('K14. Enter and Space still select the focused day, and only Apply commits', async () => {
|
|
7157
|
-
const el = await openAt();
|
|
7158
|
-
const seen = [];
|
|
7159
|
-
el.addEventListener('nile-change', ((e) => seen.push(e.detail)));
|
|
7160
|
-
focusDay(el, 15);
|
|
7161
|
-
await press(el, 'ArrowRight');
|
|
7162
|
-
await press(el, 'Enter');
|
|
7163
|
-
expect(cal(el).value.getDate()).to.equal(16);
|
|
7164
|
-
await press(el, ' ');
|
|
7165
|
-
expect(cal(el).value.getDate()).to.equal(16);
|
|
7166
|
-
expect(seen, 'selecting a day commits nothing').to.deep.equal([]);
|
|
7167
|
-
}).timeout(60000);
|
|
7168
|
-
it('K15. navigation keys are ignored while disabled, and Ctrl/Alt/Meta combinations are left alone', async () => {
|
|
7169
|
-
const el = await openAt();
|
|
7170
|
-
focusDay(el, 15);
|
|
7171
|
-
expect(key(deepActive(), 'ArrowRight', { ctrlKey: true }).defaultPrevented).to.be.false;
|
|
7172
|
-
expect(key(deepActive(), 'ArrowRight', { altKey: true }).defaultPrevented).to.be.false;
|
|
7173
|
-
expect(key(deepActive(), 'ArrowRight').defaultPrevented).to.be.true;
|
|
7174
|
-
}).timeout(60000);
|
|
7175
|
-
it('K16. in the collapsed three-week window an arrow past the visible weeks expands the calendar', async () => {
|
|
7176
|
-
const el = await make('2026-06-15T10:00:00.000[GMT+00:00 UTC]');
|
|
7177
|
-
el.open = true;
|
|
7178
|
-
await settle(el);
|
|
7179
|
-
expect(cal(el).expanded).to.be.false;
|
|
7180
|
-
const first = dayCells(el)[0];
|
|
7181
|
-
first.focus();
|
|
7182
|
-
key(first, 'ArrowUp');
|
|
7183
|
-
key(deepActive(), 'ArrowUp');
|
|
7184
|
-
await settle(el);
|
|
7185
|
-
key(deepActive(), 'ArrowUp');
|
|
7186
|
-
await settle(el);
|
|
7187
|
-
expect(deepActive().classList.contains('day_date')).to.be.true;
|
|
7188
|
-
}).timeout(60000);
|
|
7189
|
-
it('K17. the default nile-calendar is unchanged: every allowed day is still a tab stop, no arrow handling', async () => {
|
|
7190
|
-
const c = await fixture(html `<nile-calendar></nile-calendar>`);
|
|
7191
|
-
await c.updateComplete;
|
|
7192
|
-
const cells = [...c.shadowRoot.querySelectorAll('.day_date')].filter((x) => x.getAttribute('tabindex') === '0');
|
|
7193
|
-
expect(cells.length).to.be.greaterThan(20);
|
|
7194
|
-
const ev = new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true, cancelable: true });
|
|
7195
|
-
cells[0].dispatchEvent(ev);
|
|
7196
|
-
expect(ev.defaultPrevented).to.be.false;
|
|
7197
|
-
}).timeout(60000);
|
|
7198
|
-
});
|
|
7199
|
-
describe('Tab order and focus restoration', () => {
|
|
7200
|
-
const openByKey = async (el) => {
|
|
7201
|
-
triggerNative(el).focus();
|
|
7202
|
-
key(triggerNative(el), 'ArrowDown');
|
|
7203
|
-
await settle(el);
|
|
7204
|
-
};
|
|
7205
|
-
it('K18. Tab from the field while open enters the panel (not the next page element)', async () => {
|
|
7206
|
-
const el = await make('2026-06-15T10:00:00.000[GMT+00:00 UTC]');
|
|
7207
|
-
el.open = true;
|
|
7208
|
-
await settle(el);
|
|
7209
|
-
triggerNative(el).focus();
|
|
7210
|
-
const ev = key(triggerNative(el), 'Tab');
|
|
7211
|
-
expect(ev.defaultPrevented, 'the browser must not skip to the end of <body>').to.be.true;
|
|
7212
|
-
expect(document.activeElement).to.equal(cal(el));
|
|
7213
|
-
expect(deepActive(), 'the first control, so Shift+Tab from it returns to the field').to.equal(el.panelTabbables()[0]);
|
|
7214
|
-
}).timeout(60000);
|
|
7215
|
-
it('K19. Shift+Tab from the field is left to the browser', async () => {
|
|
7216
|
-
const el = await make();
|
|
7217
|
-
el.open = true;
|
|
7218
|
-
await settle(el);
|
|
7219
|
-
triggerNative(el).focus();
|
|
7220
|
-
expect(key(triggerNative(el), 'Tab', { shiftKey: true }).defaultPrevented).to.be.false;
|
|
7221
|
-
expect(el.open).to.be.true;
|
|
7222
|
-
}).timeout(60000);
|
|
7223
|
-
it('K20. Shift+Tab from the first control returns to the field', async () => {
|
|
7224
|
-
const el = await make();
|
|
7225
|
-
await openByKey(el);
|
|
7226
|
-
const tabbables = el.panelTabbables();
|
|
7227
|
-
tabbables[0].focus();
|
|
7228
|
-
const ev = key(deepActive(), 'Tab', { shiftKey: true });
|
|
7229
|
-
expect(ev.defaultPrevented).to.be.true;
|
|
7230
|
-
expect(deepActive()).to.equal(triggerNative(el));
|
|
7231
|
-
}).timeout(60000);
|
|
7232
|
-
it('K21. Tab from the last control hands focus to the field (so the browser moves on) and closes the panel', async () => {
|
|
7233
|
-
const el = await make('2026-06-15T10:00:00.000[GMT+00:00 UTC]');
|
|
7234
|
-
await openByKey(el);
|
|
7235
|
-
const tabbables = el.panelTabbables();
|
|
7236
|
-
const last = tabbables[tabbables.length - 1];
|
|
7237
|
-
last.focus();
|
|
7238
|
-
const ev = key(deepActive(), 'Tab');
|
|
7239
|
-
expect(ev.defaultPrevented, 'default Tab then continues from the field').to.be.false;
|
|
7240
|
-
expect(deepActive()).to.equal(triggerNative(el));
|
|
7241
|
-
await aTimeout(400);
|
|
7242
|
-
expect(el.open).to.be.false;
|
|
7243
|
-
}).timeout(60000);
|
|
7244
|
-
it('K22. Tab between controls in the middle of the panel is untouched', async () => {
|
|
7245
|
-
const el = await make();
|
|
7246
|
-
await openByKey(el);
|
|
7247
|
-
const tabbables = el.panelTabbables();
|
|
7248
|
-
expect(tabbables.length).to.be.greaterThan(2);
|
|
7249
|
-
tabbables[1].focus();
|
|
7250
|
-
expect(key(deepActive(), 'Tab').defaultPrevented).to.be.false;
|
|
7251
|
-
expect(el.open).to.be.true;
|
|
7252
|
-
}).timeout(60000);
|
|
7253
|
-
it('K23. Escape from a day returns focus to the field; Apply returns it too', async () => {
|
|
7254
|
-
const el = await make('2026-06-15T10:00:00.000[GMT+00:00 UTC]');
|
|
7255
|
-
await openByKey(el);
|
|
7256
|
-
key(deepActive(), 'Escape');
|
|
7257
|
-
await aTimeout(400);
|
|
7258
|
-
expect(el.open).to.be.false;
|
|
7259
|
-
expect(deepActive()).to.equal(triggerNative(el));
|
|
7260
|
-
await openByKey(el);
|
|
7261
|
-
cal(el).shadowRoot.querySelector('.apply-button').click();
|
|
7262
|
-
await aTimeout(400);
|
|
7263
|
-
expect(el.open).to.be.false;
|
|
7264
|
-
expect(deepActive()).to.equal(triggerNative(el));
|
|
7265
|
-
}).timeout(60000);
|
|
7266
|
-
it('K24. panelTabbables skips disabled and non-visible controls', async () => {
|
|
7267
|
-
const el = await make();
|
|
7268
|
-
await openByKey(el);
|
|
7269
|
-
const tabbables = el.panelTabbables();
|
|
7270
|
-
for (const t of tabbables) {
|
|
7271
|
-
expect(t.matches(':disabled'), 'enabled').to.be.false;
|
|
7272
|
-
expect(t.getClientRects().length, 'rendered').to.be.greaterThan(0);
|
|
7273
|
-
}
|
|
7274
|
-
}).timeout(60000);
|
|
7275
|
-
});
|
|
7276
|
-
});
|
|
7277
2783
|
//# sourceMappingURL=nile-date-time-picker.test.js.map
|