@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
|
@@ -0,0 +1,1618 @@
|
|
|
1
|
+
import { aTimeout, expect, fixture, html } from '@open-wc/testing';
|
|
2
|
+
import { utcFromFields, formatYear4 } from '../nile-calendar/timezones';
|
|
3
|
+
import { instantFromBracketedValue, wallClockFromOffsetLess } from '../nile-calendar/nile-calendar';
|
|
4
|
+
import './nile-date-time-picker';
|
|
5
|
+
import '../nile-calendar';
|
|
6
|
+
import '../nile-input';
|
|
7
|
+
import type { NileDateTimePicker } from './nile-date-time-picker';
|
|
8
|
+
import {
|
|
9
|
+
makePicker,
|
|
10
|
+
settle,
|
|
11
|
+
settle2,
|
|
12
|
+
applyButton,
|
|
13
|
+
apply,
|
|
14
|
+
roundTrip,
|
|
15
|
+
} from './nile-date-time-picker.test-helpers';
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Regressions, type sync / paste, and the Y-series (Y, Y9-Y21).
|
|
19
|
+
* Split out of nile-date-time-picker.test.ts so CI can run it on its own shard;
|
|
20
|
+
* helpers shared across the split files live in nile-date-time-picker.test-helpers.ts.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ── R. REGRESSIONS (code-review findings #1, #2a, #3, #6) ───────────────────
|
|
25
|
+
*/
|
|
26
|
+
describe('NileDateTimePicker regressions', () => {
|
|
27
|
+
const VALUE = '2026-03-15T10:30:00';
|
|
28
|
+
const inputOf = (el: any) => el.shadowRoot.querySelector('nile-input') as any;
|
|
29
|
+
const textOf = (el: any) => (inputOf(el).input as HTMLInputElement).value;
|
|
30
|
+
const openPanel = async (el: any) => {
|
|
31
|
+
el.open = true;
|
|
32
|
+
await settle2(el);
|
|
33
|
+
await aTimeout(50);
|
|
34
|
+
return el.calendarElement as any;
|
|
35
|
+
};
|
|
36
|
+
const days = (cal: any): HTMLElement[] =>
|
|
37
|
+
[...cal.shadowRoot.querySelectorAll('.day_date:not(.filler)')] as HTMLElement[];
|
|
38
|
+
const pad = (n: number) => String(n).padStart(2, '0');
|
|
39
|
+
|
|
40
|
+
it('R1. setting value to null clears the trigger text (#1)', async () => {
|
|
41
|
+
const el = await fixture<NileDateTimePicker>(
|
|
42
|
+
html`<nile-date-time-picker .dateFormat=${'YYYY-MM-DD'} .value=${VALUE}></nile-date-time-picker>`
|
|
43
|
+
);
|
|
44
|
+
await settle2(el);
|
|
45
|
+
expect(textOf(el), 'precondition').to.contain('2026-03-15');
|
|
46
|
+
el.value = null;
|
|
47
|
+
await settle2(el);
|
|
48
|
+
expect(textOf(el)).to.equal('');
|
|
49
|
+
// a later value still seeds normally
|
|
50
|
+
el.value = '2026-04-01T08:00:00';
|
|
51
|
+
await settle2(el);
|
|
52
|
+
expect(textOf(el)).to.contain('2026-04-01');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('R2. the typing mask still works after the picker is moved in the DOM (#2a)', async () => {
|
|
56
|
+
const el = await fixture<NileDateTimePicker>(
|
|
57
|
+
html`<nile-date-time-picker .dateFormat=${'DD/MM/YY'}></nile-date-time-picker>`
|
|
58
|
+
);
|
|
59
|
+
await settle2(el);
|
|
60
|
+
const host = el.parentNode!;
|
|
61
|
+
el.remove();
|
|
62
|
+
host.appendChild(el);
|
|
63
|
+
await settle2(el);
|
|
64
|
+
await inputOf(el).updateComplete;
|
|
65
|
+
for (const key of '23') {
|
|
66
|
+
inputOf(el).dispatchEvent(
|
|
67
|
+
new KeyboardEvent('keydown', { key, bubbles: true, composed: true, cancelable: true })
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
expect(textOf(el)).to.equal('23/');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('R3a. a relative range is rendered in the zone it is labelled with, not the host zone (#3)', async () => {
|
|
74
|
+
const el = await fixture<NileDateTimePicker>(
|
|
75
|
+
html`<nile-date-time-picker type="relative" .dateFormat=${'YYYY-MM-DD'}></nile-date-time-picker>`
|
|
76
|
+
);
|
|
77
|
+
await settle2(el);
|
|
78
|
+
const cal = el.calendarElement as any;
|
|
79
|
+
cal.dispatchEvent(new CustomEvent('nile-change', {
|
|
80
|
+
bubbles: true, composed: true,
|
|
81
|
+
detail: {
|
|
82
|
+
startDate: new Date(Date.UTC(2026, 5, 15, 3, 0, 0)),
|
|
83
|
+
endDate: new Date(Date.UTC(2026, 5, 15, 5, 0, 0)),
|
|
84
|
+
timezone: 'Asia/Kolkata',
|
|
85
|
+
},
|
|
86
|
+
}));
|
|
87
|
+
await settle2(el);
|
|
88
|
+
// 03:00Z / 05:00Z are 08:30 / 10:30 in Kolkata, whatever zone the browser runs in
|
|
89
|
+
expect(textOf(el)).to.contain('2026-06-15 - 08:30');
|
|
90
|
+
expect(textOf(el)).to.contain('2026-06-15 - 10:30');
|
|
91
|
+
expect(textOf(el)).to.match(/ - Asia\/Kolkata$/);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('R3b. a relative Apply shows the UTC wall-clock it is labelled with (#3)', async () => {
|
|
95
|
+
const el = await fixture<NileDateTimePicker>(
|
|
96
|
+
html`<nile-date-time-picker type="relative" .dateFormat=${'YYYY-MM-DD'}></nile-date-time-picker>`
|
|
97
|
+
);
|
|
98
|
+
await settle2(el);
|
|
99
|
+
const cal = await openPanel(el);
|
|
100
|
+
let detail: any = null;
|
|
101
|
+
el.addEventListener('nile-change', ((e: CustomEvent) => { detail = e.detail; }) as EventListener);
|
|
102
|
+
cal.handleTimeValueClick('hours', 2, new Event('click'));
|
|
103
|
+
await settle2(el);
|
|
104
|
+
applyButton(cal).click();
|
|
105
|
+
await settle2(el);
|
|
106
|
+
const end = new Date(detail.endDate);
|
|
107
|
+
expect(detail.timezone).to.equal('UTC');
|
|
108
|
+
expect(textOf(el)).to.contain(`${pad(end.getUTCHours())}:${pad(end.getUTCMinutes())}`);
|
|
109
|
+
expect(textOf(el)).to.match(/ - UTC$/);
|
|
110
|
+
expect(el.value, 'a relative apply does not write value').to.be.null;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('R3c. with the timezone label hidden, a relative range keeps the host wall-clock (unchanged)', async () => {
|
|
114
|
+
const el = await fixture<NileDateTimePicker>(
|
|
115
|
+
html`<nile-date-time-picker type="relative" .dateFormat=${'YYYY-MM-DD'}
|
|
116
|
+
.hideTimeFields=${['timezone']}></nile-date-time-picker>`
|
|
117
|
+
);
|
|
118
|
+
await settle2(el);
|
|
119
|
+
const start = new Date(Date.UTC(2026, 5, 15, 3, 0, 0));
|
|
120
|
+
const cal = el.calendarElement as any;
|
|
121
|
+
cal.dispatchEvent(new CustomEvent('nile-change', {
|
|
122
|
+
bubbles: true, composed: true,
|
|
123
|
+
detail: { startDate: start, endDate: new Date(Date.UTC(2026, 5, 15, 5, 0, 0)), timezone: 'Asia/Kolkata' },
|
|
124
|
+
}));
|
|
125
|
+
await settle2(el);
|
|
126
|
+
expect(textOf(el)).to.contain(`${pad(start.getHours())}:${pad(start.getMinutes())}`);
|
|
127
|
+
expect(textOf(el)).to.not.contain('Asia/Kolkata');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('R6. Apply updates value, and a later timezone change keeps the applied pick (#6)', async () => {
|
|
131
|
+
const el = await fixture<NileDateTimePicker>(
|
|
132
|
+
html`<nile-date-time-picker .dateFormat=${'YYYY-MM-DD'} .value=${VALUE}></nile-date-time-picker>`
|
|
133
|
+
);
|
|
134
|
+
await settle2(el);
|
|
135
|
+
const cal = await openPanel(el);
|
|
136
|
+
days(cal)[20].click();
|
|
137
|
+
await settle2(el);
|
|
138
|
+
let detail: any = null;
|
|
139
|
+
el.addEventListener('nile-change', ((e: CustomEvent) => { detail = e.detail; }) as EventListener);
|
|
140
|
+
applyButton(cal).click();
|
|
141
|
+
await settle2(el);
|
|
142
|
+
const pickedDay = detail.value.slice(0, 10);
|
|
143
|
+
expect(pickedDay, 'precondition: a different day was applied').to.not.equal('2026-03-15');
|
|
144
|
+
expect(el.value).to.equal(detail.value);
|
|
145
|
+
expect(textOf(el)).to.contain(pickedDay);
|
|
146
|
+
el.timezone = 'Asia/Kolkata';
|
|
147
|
+
await settle2(el);
|
|
148
|
+
expect(textOf(el)).to.contain(pickedDay);
|
|
149
|
+
expect(textOf(el)).to.not.contain('2026-03-15');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// ── M. review fixes: type sync, Clear keeps the configured zone, non-keydown mask input ──
|
|
154
|
+
describe('NileDateTimePicker — type sync, timezone on Clear, paste / beforeinput', () => {
|
|
155
|
+
const dtpFixture = () =>
|
|
156
|
+
fixture<NileDateTimePicker>(html`<nile-date-time-picker></nile-date-time-picker>`);
|
|
157
|
+
const innerCalendar = (el: NileDateTimePicker): any => (el as any).calendarElement;
|
|
158
|
+
const triggerInput = (el: NileDateTimePicker): any => el.shadowRoot!.querySelector('nile-input');
|
|
159
|
+
const settle = async (el: NileDateTimePicker) => {
|
|
160
|
+
await el.updateComplete;
|
|
161
|
+
const cal = innerCalendar(el);
|
|
162
|
+
if (cal) await cal.updateComplete;
|
|
163
|
+
return cal;
|
|
164
|
+
};
|
|
165
|
+
const settle2 = async (el: NileDateTimePicker) => { await settle(el); return settle(el); };
|
|
166
|
+
const dayCells = (cal: any): NodeListOf<HTMLElement> =>
|
|
167
|
+
cal.shadowRoot!.querySelectorAll('.day_date:not(.filler)');
|
|
168
|
+
const clickDay = (cal: any, i = 5) => (dayCells(cal)[i] as HTMLElement).click();
|
|
169
|
+
const resetBtn = (cal: any) => cal.shadowRoot!.querySelector('.clear-button') as HTMLElement;
|
|
170
|
+
const switchTab = async (el: NileDateTimePicker, value: string) => {
|
|
171
|
+
const cal = await settle(el);
|
|
172
|
+
cal.shadowRoot!.querySelector(`nile-tab[panel="${value}"]`)!.dispatchEvent(
|
|
173
|
+
new CustomEvent('nile-tab-show', { detail: { value }, bubbles: true, composed: true })
|
|
174
|
+
);
|
|
175
|
+
await cal.updateComplete;
|
|
176
|
+
await el.updateComplete;
|
|
177
|
+
};
|
|
178
|
+
const maskFixture = () =>
|
|
179
|
+
fixture<NileDateTimePicker>(html`<nile-date-time-picker></nile-date-time-picker>`);
|
|
180
|
+
const nativeOf = (el: any) => (triggerInput(el) as any).input as HTMLInputElement;
|
|
181
|
+
const ready = async (el: any) => { await el.updateComplete; await triggerInput(el).updateComplete; };
|
|
182
|
+
const paste = (el: any, text: string) => {
|
|
183
|
+
const dt = new DataTransfer();
|
|
184
|
+
dt.setData('text', text);
|
|
185
|
+
const ev = new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, composed: true, cancelable: true });
|
|
186
|
+
triggerInput(el).dispatchEvent(ev);
|
|
187
|
+
return ev;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
it('M1. switching the calendar to Relative updates the picker type (and attribute)', async () => {
|
|
191
|
+
const el = await dtpFixture();
|
|
192
|
+
expect(el.type).to.equal('absolute');
|
|
193
|
+
await switchTab(el, 'relative');
|
|
194
|
+
expect(el.type).to.equal('relative');
|
|
195
|
+
expect(el.getAttribute('type')).to.equal('relative');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('M2. switching back to Absolute restores type', async () => {
|
|
199
|
+
const el = await dtpFixture();
|
|
200
|
+
await switchTab(el, 'relative');
|
|
201
|
+
await switchTab(el, 'absolute');
|
|
202
|
+
expect(el.type).to.equal('absolute');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('M3. nile-type-change is still forwarded after the type is synced', async () => {
|
|
206
|
+
const el = await dtpFixture();
|
|
207
|
+
let detail: any = null;
|
|
208
|
+
el.addEventListener('nile-type-change', ((e: CustomEvent) => { detail = e.detail; }) as EventListener);
|
|
209
|
+
await switchTab(el, 'relative');
|
|
210
|
+
expect(detail?.value).to.equal('relative');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('M4. Reset in the calendar keeps the consumer-configured timezone', async () => {
|
|
214
|
+
const el = await fixture<NileDateTimePicker>(
|
|
215
|
+
html`<nile-date-time-picker timezone="America/New_York"></nile-date-time-picker>`
|
|
216
|
+
);
|
|
217
|
+
const cal = await settle2(el);
|
|
218
|
+
clickDay(cal, 5);
|
|
219
|
+
await cal.updateComplete;
|
|
220
|
+
resetBtn(cal).click();
|
|
221
|
+
await settle2(el);
|
|
222
|
+
expect(el.timezone).to.equal('America/New_York');
|
|
223
|
+
expect(cal.timezone).to.equal('America/New_York');
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('M5. handleClear keeps the configured timezone and empties value', async () => {
|
|
227
|
+
const el = await fixture<NileDateTimePicker>(
|
|
228
|
+
html`<nile-date-time-picker timezone="Asia/Kolkata"></nile-date-time-picker>`
|
|
229
|
+
);
|
|
230
|
+
await settle2(el);
|
|
231
|
+
(el as any).handleClear();
|
|
232
|
+
await settle2(el);
|
|
233
|
+
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
234
|
+
expect(el.value == null).to.be.true;
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('M6. with no configured timezone, Clear still lands on UTC', async () => {
|
|
238
|
+
const el = await dtpFixture();
|
|
239
|
+
await settle2(el);
|
|
240
|
+
(el as any).handleClear();
|
|
241
|
+
await settle2(el);
|
|
242
|
+
expect(el.timezone).to.equal('UTC');
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('M8. a zone picked in the calendar dropdown is undone by Reset: wrapper and calendar both land on the configured zone', async () => {
|
|
246
|
+
const el = await fixture<NileDateTimePicker>(
|
|
247
|
+
html`<nile-date-time-picker timezone="Europe/London"></nile-date-time-picker>`
|
|
248
|
+
);
|
|
249
|
+
const cal = await settle2(el);
|
|
250
|
+
cal.handleTimezoneChange(new CustomEvent('nile-change', { detail: { value: 'Asia/Tokyo' } }));
|
|
251
|
+
await cal.updateComplete;
|
|
252
|
+
resetBtn(cal).click();
|
|
253
|
+
await settle2(el);
|
|
254
|
+
expect(cal.timezone).to.equal('Europe/London');
|
|
255
|
+
expect(el.timezone).to.equal('Europe/London');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('M9. a dynamic consumer timezone change is what Reset restores, in the wrapper and the calendar', async () => {
|
|
259
|
+
const el = await fixture<NileDateTimePicker>(
|
|
260
|
+
html`<nile-date-time-picker timezone="Europe/London"></nile-date-time-picker>`
|
|
261
|
+
);
|
|
262
|
+
const cal = await settle2(el);
|
|
263
|
+
el.timezone = 'Asia/Kolkata';
|
|
264
|
+
await settle2(el);
|
|
265
|
+
cal.handleTimezoneChange(new CustomEvent('nile-change', { detail: { value: 'UTC' } }));
|
|
266
|
+
await cal.updateComplete;
|
|
267
|
+
resetBtn(cal).click();
|
|
268
|
+
await settle2(el);
|
|
269
|
+
expect(cal.timezone).to.equal('Asia/Kolkata');
|
|
270
|
+
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
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 () => {
|
|
274
|
+
const el = await fixture<NileDateTimePicker>(
|
|
275
|
+
html`<nile-date-time-picker timezone="Europe/London" .hideTimeFields=${['timezone']}></nile-date-time-picker>`
|
|
276
|
+
);
|
|
277
|
+
const cal = await settle2(el);
|
|
278
|
+
const host = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
279
|
+
(cal.shadowRoot!.querySelector('.tp-set-to-now-button') as HTMLElement).click();
|
|
280
|
+
await cal.updateComplete;
|
|
281
|
+
expect(cal.timezone).to.equal(host);
|
|
282
|
+
resetBtn(cal).click();
|
|
283
|
+
await settle2(el);
|
|
284
|
+
expect(cal.timezone).to.equal('Europe/London');
|
|
285
|
+
expect(el.timezone).to.equal('Europe/London');
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('M7. a date-only range seeded into the calendar keeps its days, and Reset still keeps the configured zone (default stays UTC)', async () => {
|
|
289
|
+
const el = await fixture<NileDateTimePicker>(
|
|
290
|
+
html`<nile-date-time-picker timezone="Asia/Kolkata"></nile-date-time-picker>`
|
|
291
|
+
);
|
|
292
|
+
const cal = await settle2(el);
|
|
293
|
+
cal.range = true;
|
|
294
|
+
cal.valueAttribute = '{"startDate":"2025-12-31","endDate":"2026-01-02"}';
|
|
295
|
+
await settle2(el);
|
|
296
|
+
const ymd = (d: Date) => [d.getFullYear(), d.getMonth() + 1, d.getDate()];
|
|
297
|
+
expect(ymd(cal.startDate)).to.deep.equal([2025, 12, 31]);
|
|
298
|
+
expect(ymd(cal.endDate)).to.deep.equal([2026, 1, 2]);
|
|
299
|
+
resetBtn(cal).click();
|
|
300
|
+
await settle2(el);
|
|
301
|
+
expect(cal.startDate).to.equal(null);
|
|
302
|
+
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
303
|
+
expect(cal.timezone).to.equal('Asia/Kolkata');
|
|
304
|
+
|
|
305
|
+
const plain = await dtpFixture();
|
|
306
|
+
expect(plain.timezone, 'unconfigured default').to.equal('UTC');
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('M6b. a timezone set by the consumer AFTER first render is what Clear restores', async () => {
|
|
310
|
+
const el = await dtpFixture();
|
|
311
|
+
await settle2(el);
|
|
312
|
+
el.timezone = 'Asia/Tokyo';
|
|
313
|
+
await settle2(el);
|
|
314
|
+
(el as any).handleClear();
|
|
315
|
+
await settle2(el);
|
|
316
|
+
expect(el.timezone).to.equal('Asia/Tokyo');
|
|
317
|
+
expect(innerCalendar(el).timezone).to.equal('Asia/Tokyo');
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('M6c. calendar Reset after a later consumer zone change keeps that zone (picker + calendar agree)', async () => {
|
|
321
|
+
const el = await dtpFixture();
|
|
322
|
+
await settle2(el);
|
|
323
|
+
el.timezone = 'Europe/Paris';
|
|
324
|
+
await settle2(el);
|
|
325
|
+
const cal = innerCalendar(el);
|
|
326
|
+
clickDay(cal, 5);
|
|
327
|
+
await cal.updateComplete;
|
|
328
|
+
resetBtn(cal).click();
|
|
329
|
+
await settle2(el);
|
|
330
|
+
expect(el.timezone).to.equal('Europe/Paris');
|
|
331
|
+
expect(cal.timezone).to.equal('Europe/Paris');
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('M6d. a zone picked in the calendar dropdown is NOT adopted as the default; Reset returns to the configured zone', async () => {
|
|
335
|
+
const el = await fixture<NileDateTimePicker>(
|
|
336
|
+
html`<nile-date-time-picker timezone="Asia/Kolkata"></nile-date-time-picker>`
|
|
337
|
+
);
|
|
338
|
+
const cal = await settle2(el);
|
|
339
|
+
cal.handleTimezoneChange(new CustomEvent('nile-change', { detail: { value: 'America/Chicago' } }));
|
|
340
|
+
await settle2(el);
|
|
341
|
+
expect(cal.timezone).to.equal('America/Chicago');
|
|
342
|
+
resetBtn(cal).click();
|
|
343
|
+
await settle2(el);
|
|
344
|
+
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
345
|
+
expect(cal.timezone).to.equal('Asia/Kolkata');
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('M6e. a zone adopted from a bracketed value is not mistaken for the configured default', async () => {
|
|
349
|
+
const el = await dtpFixture();
|
|
350
|
+
await settle2(el);
|
|
351
|
+
el.value = '2026-03-01T10:00:00.000[GMT+05:30 Asia/Kolkata]';
|
|
352
|
+
await settle2(el);
|
|
353
|
+
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
354
|
+
(el as any).handleClear();
|
|
355
|
+
await settle2(el);
|
|
356
|
+
expect(el.timezone).to.equal('UTC');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('M7. pasting a full datetime fills the mask like typing it', async () => {
|
|
360
|
+
const el = await maskFixture();
|
|
361
|
+
await ready(el);
|
|
362
|
+
const ev = paste(el, '230326172456426');
|
|
363
|
+
expect(ev.defaultPrevented).to.be.true;
|
|
364
|
+
expect(nativeOf(el).value).to.equal('23/03/26 - 17:24:56.426');
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('M8. pasting separator-formatted text uses only its digits', async () => {
|
|
368
|
+
const el = await maskFixture();
|
|
369
|
+
await ready(el);
|
|
370
|
+
paste(el, '23/03/26 - 17:24');
|
|
371
|
+
expect(nativeOf(el).value.startsWith('23/03/26 - 17:24')).to.be.true;
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('M9. pasting with no digits leaves the mask unchanged', async () => {
|
|
375
|
+
const el = await maskFixture();
|
|
376
|
+
await ready(el);
|
|
377
|
+
paste(el, 'hello');
|
|
378
|
+
expect(nativeOf(el).value).to.equal('');
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it('M10. pasted out-of-range segments are clamped', async () => {
|
|
382
|
+
const el = await maskFixture();
|
|
383
|
+
await ready(el);
|
|
384
|
+
paste(el, '992026');
|
|
385
|
+
expect(nativeOf(el).value).to.not.contain('99');
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('M11. soft-keyboard style insertText (no usable keydown) is picked up by the mask', async () => {
|
|
389
|
+
const el = await maskFixture();
|
|
390
|
+
await ready(el);
|
|
391
|
+
const native = nativeOf(el);
|
|
392
|
+
native.value = '2303';
|
|
393
|
+
triggerInput(el).dispatchEvent(
|
|
394
|
+
new InputEvent('beforeinput', { inputType: 'insertText', data: '3', bubbles: true, composed: true })
|
|
395
|
+
);
|
|
396
|
+
await aTimeout(20);
|
|
397
|
+
expect(native.value).to.equal('23/03/');
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it('M12. a cut (deleteByCut) rebuilds the slots from the remaining text', async () => {
|
|
401
|
+
const el = await maskFixture();
|
|
402
|
+
await ready(el);
|
|
403
|
+
paste(el, '230326');
|
|
404
|
+
await ready(el); // let the input's own re-render land before simulating the cut
|
|
405
|
+
const native = nativeOf(el);
|
|
406
|
+
native.value = '23/03/';
|
|
407
|
+
triggerInput(el).dispatchEvent(
|
|
408
|
+
new InputEvent('beforeinput', { inputType: 'deleteByCut', bubbles: true, composed: true })
|
|
409
|
+
);
|
|
410
|
+
await aTimeout(20);
|
|
411
|
+
expect(native.value).to.equal('23/03/');
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it('M13. paste is ignored in Relative mode', async () => {
|
|
415
|
+
const el = await maskFixture();
|
|
416
|
+
await ready(el);
|
|
417
|
+
await switchTab(el, 'relative');
|
|
418
|
+
const ev = paste(el, '230326');
|
|
419
|
+
expect(ev.defaultPrevented).to.be.false;
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* ── Y. YEARS 0-99 (Date.UTC remap regression) ───────────────────────────────
|
|
425
|
+
* `Date.UTC(y, …)` treats years 0-99 as 1900-1999, so year 0001 used to become 1901: the bracketed offset was
|
|
426
|
+
* computed for the wrong year (`[GMT+16655040:00 UTC]`) and offset-less / bracketed values re-parsed a century off.
|
|
427
|
+
* Epochs here are built with setUTCFullYear — never Date.UTC — so the oracle does not share the bug.
|
|
428
|
+
*/
|
|
429
|
+
describe('Y. years 0-99 keep their literal year', () => {
|
|
430
|
+
const epochOf = (y: number, mo1: number, d: number, h = 0, mi = 0, s = 0, ms = 0) => {
|
|
431
|
+
const dt = new Date(0);
|
|
432
|
+
dt.setUTCFullYear(y, mo1 - 1, d);
|
|
433
|
+
dt.setUTCHours(h, mi, s, ms);
|
|
434
|
+
return dt.getTime();
|
|
435
|
+
};
|
|
436
|
+
const pad4 = (y: number) => String(y).padStart(4, '0');
|
|
437
|
+
const YEARS = [1, 99, 100];
|
|
438
|
+
|
|
439
|
+
it('Y1. utcFromFields equals Date.UTC for years >= 100 (incl. overflowing fields)', () => {
|
|
440
|
+
for (const args of [
|
|
441
|
+
[2026, 5, 15, 12, 30, 15, 250], [100, 0, 1], [1900, 2, 1], [2100, 1, 29], [2024, 12, 32, 25, 61, 61, 1001],
|
|
442
|
+
[2026, 2, 0],
|
|
443
|
+
] as number[][]) {
|
|
444
|
+
expect(utcFromFields(args[0], args[1], args[2], args[3], args[4], args[5], args[6]),
|
|
445
|
+
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));
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it('Y2. utcFromFields keeps years 0-99 literal and returns NaN for NaN input', () => {
|
|
450
|
+
expect(new Date(utcFromFields(1, 0, 1)).getUTCFullYear()).to.equal(1);
|
|
451
|
+
expect(new Date(utcFromFields(99, 11, 31, 23, 59, 59, 999)).getUTCFullYear()).to.equal(99);
|
|
452
|
+
expect(new Date(utcFromFields(0, 1, 29)).getUTCDate()).to.equal(29); // year 0 is a leap year
|
|
453
|
+
expect(utcFromFields(1, 0, 1)).to.equal(epochOf(1, 1, 1));
|
|
454
|
+
expect(utcFromFields(NaN, 0, 1)).to.be.NaN;
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('Y3. wallClockFromOffsetLess keeps the literal year, month length and digits', () => {
|
|
458
|
+
for (const y of YEARS) {
|
|
459
|
+
const w = wallClockFromOffsetLess(`${pad4(y)}-06-15T12:30:15.250`)!;
|
|
460
|
+
expect(w, `year ${y}`).to.deep.equal({ year: y, month: 6, day: 15, hours: 12, minutes: 30, seconds: 15, ms: 250 });
|
|
461
|
+
}
|
|
462
|
+
// year 0 is leap (400 | 0); the 1900 remap would clamp Feb 29 to 28
|
|
463
|
+
expect(wallClockFromOffsetLess('0000-02-29T10:00:00')!.day).to.equal(29);
|
|
464
|
+
// year 1 is not leap: Feb 29 clamps to 28
|
|
465
|
+
expect(wallClockFromOffsetLess('0001-02-29T10:00:00')!.day).to.equal(28);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('Y4. instantFromBracketedValue returns the true epoch for years 0001, 0099 and 0100', () => {
|
|
469
|
+
for (const y of YEARS) {
|
|
470
|
+
const r = instantFromBracketedValue(`${pad4(y)}-06-15T12:30:15.250[GMT+00:00 UTC]`);
|
|
471
|
+
expect(r, `year ${y}`).to.deep.equal({ epochMs: epochOf(y, 6, 15, 12, 30, 15, 250), timezone: 'UTC' });
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
for (const y of YEARS) {
|
|
476
|
+
it(`Y5.${y}. Z instant in year ${pad4(y)} emits the true epoch, a sane bracket, and round-trips`, async () => {
|
|
477
|
+
const raw = `${pad4(y)}-06-15T12:30:15.250Z`;
|
|
478
|
+
const p = await apply(await makePicker({ value: raw, timezone: 'UTC' }));
|
|
479
|
+
expect(p, 'payload').to.exist;
|
|
480
|
+
expect(p!.unixEpoch).to.equal(epochOf(y, 6, 15, 12, 30, 15, 250));
|
|
481
|
+
expect(p!.value).to.equal(`${pad4(y)}-06-15T12:30:15.250[GMT+00:00 UTC]`);
|
|
482
|
+
const rt = await roundTrip(p!);
|
|
483
|
+
expect(rt.second && rt.second.unixEpoch, 'epoch after reload').to.equal(p!.unixEpoch);
|
|
484
|
+
expect(rt.second && rt.second.value).to.equal(p!.value);
|
|
485
|
+
}).timeout(60000);
|
|
486
|
+
|
|
487
|
+
it(`Y6.${y}. offset-less value in year ${pad4(y)} keeps its digits (no 19xx remap)`, async () => {
|
|
488
|
+
const p = await apply(await makePicker({ value: `${pad4(y)}-06-15T12:30:15.250`, timezone: 'UTC' }));
|
|
489
|
+
expect(p, 'payload').to.exist;
|
|
490
|
+
expect(p!.unixEpoch).to.equal(epochOf(y, 6, 15, 12, 30, 15, 250));
|
|
491
|
+
expect(p!.value).to.equal(`${pad4(y)}-06-15T12:30:15.250[GMT+00:00 UTC]`);
|
|
492
|
+
}).timeout(60000);
|
|
493
|
+
|
|
494
|
+
it(`Y7.${y}. bracketed value in year ${pad4(y)} reloads to the same epoch`, async () => {
|
|
495
|
+
const p = await apply(await makePicker({
|
|
496
|
+
value: `${pad4(y)}-06-15T12:30:15.250[GMT+00:00 UTC]`, timezone: 'UTC',
|
|
497
|
+
}));
|
|
498
|
+
expect(p, 'payload').to.exist;
|
|
499
|
+
expect(p!.unixEpoch).to.equal(epochOf(y, 6, 15, 12, 30, 15, 250));
|
|
500
|
+
}).timeout(60000);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
it('Y8. a Feb-29 in year 0 (leap) survives; year 0001 shows no absurd offset', async () => {
|
|
504
|
+
const p = await apply(await makePicker({ value: '0001-01-01T00:00:00.000Z', timezone: 'UTC' }));
|
|
505
|
+
expect(p!.value).to.not.match(/GMT[+-]\d{3,}:/);
|
|
506
|
+
expect(p!.value).to.match(/\[GMT[+-]\d{2}:\d{2} UTC\]$/);
|
|
507
|
+
}).timeout(60000);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
describe('Y9. typed date in years 0-99 (mask -> calendar)', () => {
|
|
511
|
+
it('Y9. a fully typed day in year 0050 selects year 50 (not 1950), and Feb 29 of year 0 is kept', async () => {
|
|
512
|
+
const el = await makePicker({});
|
|
513
|
+
el.dateFormat = 'DD/MM/YYYY'; // the default DD/MM/YY reads two digits as 20xx; a literal year 0050 needs YYYY
|
|
514
|
+
await settle(el);
|
|
515
|
+
const layout = (el as any).maskLayout();
|
|
516
|
+
const digitsFor = (mm: string, dd: string, yyyy: string) => {
|
|
517
|
+
const map: Record<string, string> = { month: mm, day: dd, year: yyyy };
|
|
518
|
+
const idx: Record<string, number> = { month: 0, day: 0, year: 0 };
|
|
519
|
+
return layout.slots.map((s: any) => (s.kind in map ? map[s.kind][idx[s.kind]++] : '0'));
|
|
520
|
+
};
|
|
521
|
+
const cal = el.calendarElement as any;
|
|
522
|
+
const run = async (mm: string, dd: string, yyyy: string) => {
|
|
523
|
+
(el as any).maskValues = digitsFor(mm, dd, yyyy);
|
|
524
|
+
(el as any).syncCalendarFromMask();
|
|
525
|
+
await settle(el);
|
|
526
|
+
};
|
|
527
|
+
await run('06', '15', '0050');
|
|
528
|
+
expect(cal.value.getFullYear(), 'year').to.equal(50);
|
|
529
|
+
expect(cal.value.getMonth(), 'month').to.equal(5);
|
|
530
|
+
expect(cal.value.getDate(), 'day').to.equal(15);
|
|
531
|
+
await run('02', '29', '0000');
|
|
532
|
+
expect(cal.value.getFullYear(), 'year 0').to.equal(0);
|
|
533
|
+
expect(cal.value.getDate(), 'Feb 29 exists in year 0 (leap)').to.equal(29);
|
|
534
|
+
await run('02', '29', '0100');
|
|
535
|
+
expect(cal.value.getFullYear(), 'year 100 unchanged').to.equal(100);
|
|
536
|
+
expect(cal.value.getDate(), 'year 100 is not leap: clamps to 28').to.equal(28);
|
|
537
|
+
}).timeout(60000);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
describe('Y10. YYYY display in years 0-99 (picker input)', () => {
|
|
541
|
+
const wall = (year: number, month = 6, day = 15) =>
|
|
542
|
+
({ year, month, day, hours: 12, minutes: 30, seconds: 15, ms: 250 });
|
|
543
|
+
|
|
544
|
+
it('Y10a. formatYear4 pads only years 0-99', () => {
|
|
545
|
+
expect([0, 1, 50, 99].map(formatYear4)).to.deep.equal(['0000', '0001', '0050', '0099']);
|
|
546
|
+
for (const y of [100, 999, 1000, 2000, 9999, 10000]) expect(formatYear4(y)).to.equal(String(y));
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it('Y10b. formatDatePartFields pads YYYY for 0-999, keeps >= 1000, and leaves YY alone', async () => {
|
|
550
|
+
const el = await makePicker({}) as any;
|
|
551
|
+
el.dateFormat = 'DD/MM/YYYY';
|
|
552
|
+
expect(el.formatDatePartFields(wall(50))).to.equal('15/06/0050');
|
|
553
|
+
expect(el.formatDatePartFields(wall(0, 2, 29))).to.equal('29/02/0000');
|
|
554
|
+
expect(el.formatDatePartFields(wall(1))).to.equal('15/06/0001');
|
|
555
|
+
expect(el.formatDatePartFields(wall(99))).to.equal('15/06/0099');
|
|
556
|
+
expect(el.formatDatePartFields(wall(100)), 'the mask has four year slots, so 100-999 are padded too').to.equal('15/06/0100');
|
|
557
|
+
expect(el.formatDatePartFields(wall(999))).to.equal('15/06/0999');
|
|
558
|
+
expect(el.formatDatePartFields(wall(1000))).to.equal('15/06/1000');
|
|
559
|
+
expect(el.formatDatePartFields(wall(2026))).to.equal('15/06/2026');
|
|
560
|
+
el.dateFormat = 'DD/MM/YY';
|
|
561
|
+
expect(el.formatDatePartFields(wall(1)), 'YY is always two characters (Y18)').to.equal('15/06/01');
|
|
562
|
+
expect(el.formatDatePartFields(wall(50))).to.equal('15/06/50');
|
|
563
|
+
expect(el.formatDatePartFields(wall(2026))).to.equal('15/06/26');
|
|
564
|
+
}).timeout(60000);
|
|
565
|
+
|
|
566
|
+
it('Y10c. the trigger input shows a year-0050 value as 0050 with time and timezone, and year 2026 is unchanged', async () => {
|
|
567
|
+
for (const [raw, shown] of [
|
|
568
|
+
['0050-06-15T12:30:15.250Z', '0050-06-15 - 12:30:15.250 - UTC'],
|
|
569
|
+
['2026-06-15T12:30:15.250Z', '2026-06-15 - 12:30:15.250 - UTC'],
|
|
570
|
+
]) {
|
|
571
|
+
const el = await fixture<NileDateTimePicker>(
|
|
572
|
+
html`<nile-date-time-picker .dateFormat=${'YYYY-MM-DD'} .timezone=${'UTC'} .value=${raw}></nile-date-time-picker>`);
|
|
573
|
+
await settle(el);
|
|
574
|
+
expect((el.shadowRoot!.querySelector('nile-input') as any).value, raw).to.equal(shown);
|
|
575
|
+
}
|
|
576
|
+
}).timeout(60000);
|
|
577
|
+
|
|
578
|
+
it('Y10d. typed 0050 -> mask -> calendar -> display round-trips as 0050 (year 50, not 1950)', async () => {
|
|
579
|
+
const el = await makePicker({});
|
|
580
|
+
el.dateFormat = 'DD/MM/YYYY';
|
|
581
|
+
await settle(el);
|
|
582
|
+
const layout = (el as any).maskLayout();
|
|
583
|
+
const map: Record<string, string> = { month: '06', day: '15', year: '0050' };
|
|
584
|
+
const idx: Record<string, number> = { month: 0, day: 0, year: 0 };
|
|
585
|
+
(el as any).maskValues = layout.slots.map((s: any) => (s.kind in map ? map[s.kind][idx[s.kind]++] : '0'));
|
|
586
|
+
(el as any).syncCalendarFromMask();
|
|
587
|
+
await settle(el);
|
|
588
|
+
const cal = el.calendarElement as any;
|
|
589
|
+
expect(cal.value.getFullYear()).to.equal(50);
|
|
590
|
+
expect(cal.formatDate(cal.value)).to.equal('15/06/0050');
|
|
591
|
+
}).timeout(60000);
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
describe('Y11. years 0-999 in the picker input: four-digit display and a stable focus/blur round trip', () => {
|
|
595
|
+
const FORMATS: Array<[string, (y: string) => string]> = [
|
|
596
|
+
['YYYY-MM-DD', y => `${y}-06-15`],
|
|
597
|
+
['MM/DD/YYYY', y => `06/15/${y}`],
|
|
598
|
+
['DD/MM/YYYY', y => `15/06/${y}`],
|
|
599
|
+
];
|
|
600
|
+
const YEARS = ['0001', '0050', '0099', '0100', '0999', '1000', '2026'];
|
|
601
|
+
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
602
|
+
|
|
603
|
+
const make = async (format: string, year: string): Promise<any> => {
|
|
604
|
+
const el: any = await fixture(html`<nile-date-time-picker
|
|
605
|
+
.timezone=${'UTC'} dateFormat=${format} .startYear=${0} .endYear=${9999}
|
|
606
|
+
.hideTimeFields=${DATE_ONLY} value=${`${year}-06-15T10:20:30[GMT+00:00 UTC]`}></nile-date-time-picker>`);
|
|
607
|
+
await settle2(el);
|
|
608
|
+
return el;
|
|
609
|
+
};
|
|
610
|
+
const textOf = (el: any) => el.shadowRoot.querySelector('nile-input').input.value as string;
|
|
611
|
+
const calDay = (el: any) => {
|
|
612
|
+
const c = el.calendarElement;
|
|
613
|
+
return [c.value.getFullYear(), c.value.getMonth(), c.value.getDate(), c.currentYear, c.currentMonth];
|
|
614
|
+
};
|
|
615
|
+
const focusBlur = async (el: any) => {
|
|
616
|
+
const ni = el.shadowRoot.querySelector('nile-input');
|
|
617
|
+
ni.input.focus();
|
|
618
|
+
ni.dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
619
|
+
await settle2(el);
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
for (const [format, expectText] of FORMATS) {
|
|
623
|
+
for (const year of YEARS) {
|
|
624
|
+
it(`Y11 [${format}] year ${year}: four-digit text, and focus/blur x3 leaves text, calendar and value untouched`, async () => {
|
|
625
|
+
const el = await make(format, year);
|
|
626
|
+
const n = Number(year);
|
|
627
|
+
expect(textOf(el), 'seeded text').to.equal(expectText(year));
|
|
628
|
+
const before = calDay(el);
|
|
629
|
+
expect(before, 'seeded calendar').to.deep.equal([n, 5, 15, n, 5]);
|
|
630
|
+
const valueBefore = el.value;
|
|
631
|
+
let emitted = 0;
|
|
632
|
+
el.addEventListener('nile-change', () => { emitted++; });
|
|
633
|
+
el.addEventListener('nile-changed', () => { emitted++; });
|
|
634
|
+
for (let i = 0; i < 3; i++) {
|
|
635
|
+
await focusBlur(el);
|
|
636
|
+
expect(textOf(el), `text after cycle ${i + 1}`).to.equal(expectText(year));
|
|
637
|
+
expect(calDay(el), `calendar after cycle ${i + 1}`).to.deep.equal(before);
|
|
638
|
+
}
|
|
639
|
+
expect(el.value, 'value untouched').to.equal(valueBefore);
|
|
640
|
+
expect(emitted, 'no change event from focus/blur').to.equal(0);
|
|
641
|
+
}).timeout(60000);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
describe('Y12. typed dates are clamped to the allowedDates range (user edits only)', () => {
|
|
647
|
+
const DMY = 'DD/MM/YYYY';
|
|
648
|
+
const make = async (range: [string, string] | null, value: string, tz = 'UTC'): Promise<any> => {
|
|
649
|
+
const el: any = await fixture(html`<nile-date-time-picker
|
|
650
|
+
.timezone=${tz} dateFormat=${DMY} .startYear=${0} .endYear=${9999}
|
|
651
|
+
.allowedDates=${range ? JSON.stringify({ startDate: range[0], endDate: range[1] }) : JSON.stringify({})}
|
|
652
|
+
value=${value}></nile-date-time-picker>`);
|
|
653
|
+
await settle2(el);
|
|
654
|
+
return el;
|
|
655
|
+
};
|
|
656
|
+
const inputOf = (el: any) => el.shadowRoot.querySelector('nile-input') as any;
|
|
657
|
+
const nativeOf = (el: any) => inputOf(el).input as HTMLInputElement;
|
|
658
|
+
const press = (el: any, key: string) =>
|
|
659
|
+
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, composed: true, cancelable: true }));
|
|
660
|
+
const textOf = (el: any) => nativeOf(el).value;
|
|
661
|
+
/** select the DD/MM/YYYY text, delete it, and type a fresh date digit by digit */
|
|
662
|
+
const typeDate = async (el: any, ddmmyyyy: string) => {
|
|
663
|
+
nativeOf(el).setSelectionRange(0, 10);
|
|
664
|
+
press(el, 'Backspace');
|
|
665
|
+
for (const ch of ddmmyyyy) press(el, ch);
|
|
666
|
+
await settle2(el);
|
|
667
|
+
};
|
|
668
|
+
const calDate = (el: any) => {
|
|
669
|
+
const c = el.calendarElement;
|
|
670
|
+
return [c.value.getFullYear(), c.value.getMonth() + 1, c.value.getDate()];
|
|
671
|
+
};
|
|
672
|
+
const focusBlur = async (el: any) => {
|
|
673
|
+
inputOf(el).input.focus();
|
|
674
|
+
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
675
|
+
await settle2(el);
|
|
676
|
+
};
|
|
677
|
+
const applyAndCount = async (el: any) => {
|
|
678
|
+
const cal = el.calendarElement;
|
|
679
|
+
const events: string[] = [];
|
|
680
|
+
const details: any[] = [];
|
|
681
|
+
for (const n of ['nile-change']) {
|
|
682
|
+
el.addEventListener(n, (e: any) => { events.push(n); details.push(e.detail); });
|
|
683
|
+
}
|
|
684
|
+
(cal.shadowRoot.querySelector('.apply-button') as HTMLElement).click();
|
|
685
|
+
await settle2(el);
|
|
686
|
+
return { events, details };
|
|
687
|
+
};
|
|
688
|
+
const SEED = '2026-06-15T10:20:30.250[GMT+00:00 UTC]';
|
|
689
|
+
const JUNE: [string, string] = ['2026-06-10', '2026-06-20'];
|
|
690
|
+
|
|
691
|
+
const CASES: Array<[string, [string, string], string, string, string]> = [
|
|
692
|
+
['before range', JUNE, '05062026', '10/06/2026', '2026-06-10'],
|
|
693
|
+
['lower boundary', JUNE, '10062026', '10/06/2026', '2026-06-10'],
|
|
694
|
+
['inside range', JUNE, '15062026', '15/06/2026', '2026-06-15'],
|
|
695
|
+
['upper boundary', JUNE, '20062026', '20/06/2026', '2026-06-20'],
|
|
696
|
+
['after range', JUNE, '25062026', '20/06/2026', '2026-06-20'],
|
|
697
|
+
['month boundary, before', ['2026-12-29', '2027-01-03'], '28122026', '29/12/2026', '2026-12-29'],
|
|
698
|
+
['year boundary, after', ['2026-12-29', '2027-01-03'], '04012027', '03/01/2027', '2027-01-03'],
|
|
699
|
+
['year boundary, inside', ['2026-12-29', '2027-01-03'], '01012027', '01/01/2027', '2027-01-01'],
|
|
700
|
+
['leap: before 28 Feb', ['2024-02-28', '2024-03-01'], '27022024', '28/02/2024', '2024-02-28'],
|
|
701
|
+
['leap: 29 Feb is inside', ['2024-02-28', '2024-03-01'], '29022024', '29/02/2024', '2024-02-29'],
|
|
702
|
+
['leap: after 1 Mar', ['2024-02-28', '2024-03-01'], '02032024', '01/03/2024', '2024-03-01'],
|
|
703
|
+
['non-leap: before 27 Feb', ['2023-02-27', '2023-03-02'], '26022023', '27/02/2023', '2023-02-27'],
|
|
704
|
+
['non-leap: after 2 Mar', ['2023-02-27', '2023-03-02'], '03032023', '02/03/2023', '2023-03-02'],
|
|
705
|
+
];
|
|
706
|
+
|
|
707
|
+
for (const [name, range, typed, text, iso] of CASES) {
|
|
708
|
+
it(`Y12 ${name}: typing ${typed} gives ${text}; trigger, calendar and Apply agree, time and zone kept`, async () => {
|
|
709
|
+
const el = await make(range, SEED);
|
|
710
|
+
await typeDate(el, typed);
|
|
711
|
+
const [y, m, d] = iso.split('-').map(Number);
|
|
712
|
+
expect(textOf(el).slice(0, 10), 'trigger').to.equal(text);
|
|
713
|
+
expect(calDate(el), 'calendar').to.deep.equal([y, m, d]);
|
|
714
|
+
expect(el.calendarElement.timezone).to.equal('UTC');
|
|
715
|
+
const { events, details } = await applyAndCount(el);
|
|
716
|
+
expect([...events].sort(), 'exactly one change event').to.deep.equal(['nile-change']);
|
|
717
|
+
expect(details[0].value, 'emitted value').to.equal(`${iso}T10:20:30.250[GMT+00:00 UTC]`);
|
|
718
|
+
const typedIso = `${typed.slice(4)}-${typed.slice(2, 4)}-${typed.slice(0, 2)}`;
|
|
719
|
+
if (typedIso !== iso) expect(details[0].value, 'disallowed date never committed').to.not.contain(typedIso);
|
|
720
|
+
}).timeout(60000);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
it('Y12 preserves a non-UTC zone and time of day while clamping', async () => {
|
|
724
|
+
const el = await make(JUNE, '2026-06-15T23:45:10.005[GMT+05:30 Asia/Kolkata]', 'Asia/Kolkata');
|
|
725
|
+
await typeDate(el, '25062026');
|
|
726
|
+
expect(textOf(el).slice(0, 10)).to.equal('20/06/2026');
|
|
727
|
+
expect(el.calendarElement.timezone).to.equal('Asia/Kolkata');
|
|
728
|
+
const { details } = await applyAndCount(el);
|
|
729
|
+
expect(details[0].value).to.equal('2026-06-20T23:45:10.005[GMT+05:30 Asia/Kolkata]');
|
|
730
|
+
}).timeout(60000);
|
|
731
|
+
|
|
732
|
+
it('Y12 focus/blur x3 after a clamp does not change the date again and emits nothing', async () => {
|
|
733
|
+
const el = await make(JUNE, SEED);
|
|
734
|
+
await typeDate(el, '25062026');
|
|
735
|
+
const text = textOf(el);
|
|
736
|
+
const cal = calDate(el);
|
|
737
|
+
let emitted = 0;
|
|
738
|
+
el.addEventListener('nile-change', () => { emitted++; });
|
|
739
|
+
el.addEventListener('nile-changed', () => { emitted++; });
|
|
740
|
+
for (let i = 0; i < 3; i++) {
|
|
741
|
+
await focusBlur(el);
|
|
742
|
+
expect(textOf(el), `text ${i + 1}`).to.equal(text);
|
|
743
|
+
expect(calDate(el), `calendar ${i + 1}`).to.deep.equal(cal);
|
|
744
|
+
}
|
|
745
|
+
expect(emitted).to.equal(0);
|
|
746
|
+
}).timeout(60000);
|
|
747
|
+
|
|
748
|
+
it('Y12 a programmatic value outside the range is not clamped by focus/blur', async () => {
|
|
749
|
+
const el = await make(JUNE, '2026-06-25T10:20:30.250[GMT+00:00 UTC]');
|
|
750
|
+
const text = textOf(el);
|
|
751
|
+
const cal = calDate(el);
|
|
752
|
+
const value = el.value;
|
|
753
|
+
let emitted = 0;
|
|
754
|
+
el.addEventListener('nile-change', () => { emitted++; });
|
|
755
|
+
el.addEventListener('nile-changed', () => { emitted++; });
|
|
756
|
+
for (let i = 0; i < 3; i++) {
|
|
757
|
+
await focusBlur(el);
|
|
758
|
+
expect(textOf(el)).to.equal(text);
|
|
759
|
+
expect(calDate(el)).to.deep.equal(cal);
|
|
760
|
+
}
|
|
761
|
+
expect(text.slice(0, 10)).to.equal('25/06/2026');
|
|
762
|
+
expect(el.value).to.equal(value);
|
|
763
|
+
expect(emitted).to.equal(0);
|
|
764
|
+
}).timeout(60000);
|
|
765
|
+
|
|
766
|
+
it('Y12 without allowedDates a typed date is never clamped', async () => {
|
|
767
|
+
const el = await make(null, SEED);
|
|
768
|
+
await typeDate(el, '25062026');
|
|
769
|
+
expect(textOf(el).slice(0, 10)).to.equal('25/06/2026');
|
|
770
|
+
expect(calDate(el)).to.deep.equal([2026, 6, 25]);
|
|
771
|
+
}).timeout(60000);
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
describe('Y13. changing dateFormat / hideTimeFields after render redraws the trigger from the committed value', () => {
|
|
775
|
+
const ALL_TIME = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
776
|
+
const SEED = '2026-06-15T10:20:30.250[GMT+05:30 Asia/Kolkata]';
|
|
777
|
+
const make = async (extra: { allowed?: [string, string] } = {}): Promise<any> => {
|
|
778
|
+
const el: any = await fixture(html`<nile-date-time-picker
|
|
779
|
+
timezone="Asia/Kolkata" dateFormat="DD/MM/YYYY" .startYear=${0} .endYear=${9999}
|
|
780
|
+
.allowedDates=${extra.allowed ? JSON.stringify({ startDate: extra.allowed[0], endDate: extra.allowed[1] }) : JSON.stringify({})}
|
|
781
|
+
value=${SEED}></nile-date-time-picker>`);
|
|
782
|
+
await settle2(el);
|
|
783
|
+
return el;
|
|
784
|
+
};
|
|
785
|
+
const inputOf = (el: any) => el.shadowRoot.querySelector('nile-input') as any;
|
|
786
|
+
const nativeOf = (el: any) => inputOf(el).input as HTMLInputElement;
|
|
787
|
+
const press = (el: any, key: string) =>
|
|
788
|
+
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, composed: true, cancelable: true }));
|
|
789
|
+
const textOf = (el: any) => nativeOf(el).value;
|
|
790
|
+
const calDate = (el: any) => {
|
|
791
|
+
const c = el.calendarElement;
|
|
792
|
+
return [c.value.getFullYear(), c.value.getMonth() + 1, c.value.getDate()];
|
|
793
|
+
};
|
|
794
|
+
const focusBlur = async (el: any) => {
|
|
795
|
+
inputOf(el).input.focus();
|
|
796
|
+
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
797
|
+
await settle2(el);
|
|
798
|
+
};
|
|
799
|
+
const watch = (el: any) => {
|
|
800
|
+
const seen: string[] = [];
|
|
801
|
+
for (const n of ['nile-change', 'nile-changed', 'nile-type-change']) el.addEventListener(n, () => seen.push(n));
|
|
802
|
+
return seen;
|
|
803
|
+
};
|
|
804
|
+
const apply = async (el: any) => {
|
|
805
|
+
(el.calendarElement.shadowRoot.querySelector('.apply-button') as HTMLElement).click();
|
|
806
|
+
await settle2(el);
|
|
807
|
+
};
|
|
808
|
+
|
|
809
|
+
it('Y13 DD/MM/YYYY -> YYYY-MM-DD -> back keeps the date, time and zone', async () => {
|
|
810
|
+
const el = await make();
|
|
811
|
+
const value = el.value;
|
|
812
|
+
const seen = watch(el);
|
|
813
|
+
expect(textOf(el).startsWith('15/06/2026')).to.be.true;
|
|
814
|
+
el.dateFormat = 'YYYY-MM-DD';
|
|
815
|
+
await settle2(el);
|
|
816
|
+
expect(textOf(el).startsWith('2026-06-15')).to.be.true;
|
|
817
|
+
expect(textOf(el)).to.contain('10:20:30.250').and.to.contain('Asia/Kolkata');
|
|
818
|
+
el.dateFormat = 'DD/MM/YYYY';
|
|
819
|
+
await settle2(el);
|
|
820
|
+
expect(textOf(el).startsWith('15/06/2026')).to.be.true;
|
|
821
|
+
expect(el.value).to.equal(value);
|
|
822
|
+
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
823
|
+
expect(calDate(el)).to.deep.equal([2026, 6, 15]);
|
|
824
|
+
expect(seen).to.deep.equal([]);
|
|
825
|
+
}).timeout(60000);
|
|
826
|
+
|
|
827
|
+
it('Y13 hideTimeFields hides then restores time and zone without losing them', async () => {
|
|
828
|
+
const el = await make();
|
|
829
|
+
const value = el.value;
|
|
830
|
+
const seen = watch(el);
|
|
831
|
+
el.hideTimeFields = ALL_TIME;
|
|
832
|
+
await settle2(el);
|
|
833
|
+
expect(textOf(el)).to.equal('15/06/2026');
|
|
834
|
+
el.hideTimeFields = [];
|
|
835
|
+
await settle2(el);
|
|
836
|
+
expect(textOf(el)).to.contain('10:20:30.250').and.to.contain('Asia/Kolkata');
|
|
837
|
+
expect(el.value).to.equal(value);
|
|
838
|
+
expect(seen).to.deep.equal([]);
|
|
839
|
+
}).timeout(60000);
|
|
840
|
+
|
|
841
|
+
it('Y13 both properties changed in one update give one consistent trigger', async () => {
|
|
842
|
+
const el = await make();
|
|
843
|
+
const value = el.value;
|
|
844
|
+
el.dateFormat = 'YYYY-MM-DD';
|
|
845
|
+
el.hideTimeFields = ALL_TIME;
|
|
846
|
+
await settle2(el);
|
|
847
|
+
expect(textOf(el)).to.equal('2026-06-15');
|
|
848
|
+
el.dateFormat = 'DD/MM/YYYY';
|
|
849
|
+
el.hideTimeFields = [];
|
|
850
|
+
await settle2(el);
|
|
851
|
+
expect(textOf(el)).to.contain('15/06/2026').and.to.contain('10:20:30.250').and.to.contain('Asia/Kolkata');
|
|
852
|
+
expect(el.value).to.equal(value);
|
|
853
|
+
}).timeout(60000);
|
|
854
|
+
|
|
855
|
+
it('Y13 focus/blur after each change does not corrupt the date, time or zone', async () => {
|
|
856
|
+
const el = await make();
|
|
857
|
+
const value = el.value;
|
|
858
|
+
const seen = watch(el);
|
|
859
|
+
for (const [fmt, hide] of [['YYYY-MM-DD', []], ['YYYY-MM-DD', ALL_TIME], ['DD/MM/YYYY', ALL_TIME], ['DD/MM/YYYY', []]] as Array<[string, string[]]>) {
|
|
860
|
+
el.dateFormat = fmt;
|
|
861
|
+
el.hideTimeFields = hide;
|
|
862
|
+
await settle2(el);
|
|
863
|
+
const text = textOf(el);
|
|
864
|
+
for (let i = 0; i < 2; i++) {
|
|
865
|
+
await focusBlur(el);
|
|
866
|
+
expect(textOf(el), `${fmt} ${hide.length}`).to.equal(text);
|
|
867
|
+
}
|
|
868
|
+
expect(el.value).to.equal(value);
|
|
869
|
+
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
870
|
+
expect(calDate(el)).to.deep.equal([2026, 6, 15]);
|
|
871
|
+
}
|
|
872
|
+
expect(seen).to.deep.equal([]);
|
|
873
|
+
}).timeout(60000);
|
|
874
|
+
|
|
875
|
+
it('Y13 an uncommitted draft is discarded and the committed value is redrawn', async () => {
|
|
876
|
+
const el = await make();
|
|
877
|
+
const value = el.value;
|
|
878
|
+
nativeOf(el).setSelectionRange(0, 10);
|
|
879
|
+
press(el, 'Backspace');
|
|
880
|
+
for (const ch of '01012030') press(el, ch);
|
|
881
|
+
await settle2(el);
|
|
882
|
+
expect(textOf(el).startsWith('01/01/2030')).to.be.true;
|
|
883
|
+
const seen = watch(el);
|
|
884
|
+
el.dateFormat = 'YYYY-MM-DD';
|
|
885
|
+
await settle2(el);
|
|
886
|
+
expect(textOf(el).startsWith('2026-06-15')).to.be.true;
|
|
887
|
+
await focusBlur(el);
|
|
888
|
+
expect(textOf(el).startsWith('2026-06-15')).to.be.true;
|
|
889
|
+
expect(el.value).to.equal(value);
|
|
890
|
+
expect(seen).to.deep.equal([]);
|
|
891
|
+
}).timeout(60000);
|
|
892
|
+
|
|
893
|
+
it('Y13 repeated toggles do not drift', async () => {
|
|
894
|
+
const el = await make();
|
|
895
|
+
const value = el.value;
|
|
896
|
+
const first = textOf(el);
|
|
897
|
+
for (let i = 0; i < 4; i++) {
|
|
898
|
+
el.dateFormat = 'YYYY-MM-DD';
|
|
899
|
+
el.hideTimeFields = ALL_TIME;
|
|
900
|
+
await settle2(el);
|
|
901
|
+
el.dateFormat = 'DD/MM/YYYY';
|
|
902
|
+
el.hideTimeFields = [];
|
|
903
|
+
await settle2(el);
|
|
904
|
+
}
|
|
905
|
+
expect(textOf(el)).to.equal(first);
|
|
906
|
+
expect(el.value).to.equal(value);
|
|
907
|
+
}).timeout(60000);
|
|
908
|
+
|
|
909
|
+
it('Y13 a programmatic value after a format change shows in the new format', async () => {
|
|
910
|
+
const el = await make();
|
|
911
|
+
el.dateFormat = 'YYYY-MM-DD';
|
|
912
|
+
await settle2(el);
|
|
913
|
+
el.value = '2027-03-04T05:06:07.008[GMT+05:30 Asia/Kolkata]';
|
|
914
|
+
await settle2(el);
|
|
915
|
+
expect(textOf(el).startsWith('2027-03-04')).to.be.true;
|
|
916
|
+
await focusBlur(el);
|
|
917
|
+
expect(textOf(el).startsWith('2027-03-04')).to.be.true;
|
|
918
|
+
expect(calDate(el)).to.deep.equal([2027, 3, 4]);
|
|
919
|
+
}).timeout(60000);
|
|
920
|
+
|
|
921
|
+
it('Y13 Apply after a format change emits the committed date once', async () => {
|
|
922
|
+
const el = await make();
|
|
923
|
+
el.dateFormat = 'YYYY-MM-DD';
|
|
924
|
+
await settle2(el);
|
|
925
|
+
const seen = watch(el);
|
|
926
|
+
await apply(el);
|
|
927
|
+
expect(seen).to.deep.equal(['nile-change']);
|
|
928
|
+
expect(el.value.startsWith('2026-06-15T10:20:30.250')).to.be.true;
|
|
929
|
+
}).timeout(60000);
|
|
930
|
+
|
|
931
|
+
it('Y13 with no value a format change leaves the trigger empty and emits nothing', async () => {
|
|
932
|
+
const el: any = await fixture(html`<nile-date-time-picker dateFormat="DD/MM/YYYY"></nile-date-time-picker>`);
|
|
933
|
+
await settle2(el);
|
|
934
|
+
const seen = watch(el);
|
|
935
|
+
el.dateFormat = 'YYYY-MM-DD';
|
|
936
|
+
el.hideTimeFields = ALL_TIME;
|
|
937
|
+
await settle2(el);
|
|
938
|
+
expect(textOf(el)).to.equal('');
|
|
939
|
+
expect(el.value ?? '').to.equal('');
|
|
940
|
+
expect(seen).to.deep.equal([]);
|
|
941
|
+
}).timeout(60000);
|
|
942
|
+
|
|
943
|
+
it('Y13 a format change that discards a typed draft (no committed value) emits no nile-input', async () => {
|
|
944
|
+
const el: any = await fixture(html`<nile-date-time-picker dateFormat="DD/MM/YYYY" .startYear=${0} .endYear=${9999}></nile-date-time-picker>`);
|
|
945
|
+
await settle2(el);
|
|
946
|
+
nativeOf(el).setSelectionRange(0, 0);
|
|
947
|
+
for (const ch of '01012030') press(el, ch);
|
|
948
|
+
await settle2(el);
|
|
949
|
+
expect(textOf(el).startsWith('01/01/2030')).to.be.true;
|
|
950
|
+
const seen = watch(el);
|
|
951
|
+
let inputs = 0;
|
|
952
|
+
inputOf(el).addEventListener('nile-input', () => { inputs++; });
|
|
953
|
+
el.dateFormat = 'YYYY-MM-DD';
|
|
954
|
+
await settle2(el);
|
|
955
|
+
el.hideTimeFields = ALL_TIME;
|
|
956
|
+
await settle2(el);
|
|
957
|
+
expect(textOf(el)).to.equal('');
|
|
958
|
+
expect(el.value ?? '').to.equal('');
|
|
959
|
+
expect(inputs).to.equal(0);
|
|
960
|
+
expect(seen).to.deep.equal([]);
|
|
961
|
+
}).timeout(60000);
|
|
962
|
+
|
|
963
|
+
it('Y13 a user Clear still emits nile-input and nile-clear', async () => {
|
|
964
|
+
const el = await make();
|
|
965
|
+
let inputs = 0;
|
|
966
|
+
let clears = 0;
|
|
967
|
+
inputOf(el).addEventListener('nile-input', () => { inputs++; });
|
|
968
|
+
el.addEventListener('nile-clear', () => { clears++; });
|
|
969
|
+
el.handleClear();
|
|
970
|
+
await settle2(el);
|
|
971
|
+
expect(inputs).to.equal(1);
|
|
972
|
+
expect(clears).to.equal(1);
|
|
973
|
+
}).timeout(60000);
|
|
974
|
+
|
|
975
|
+
it('Y13 relative mode ignores a format change', async () => {
|
|
976
|
+
const el: any = await fixture(html`<nile-date-time-picker type="relative" dateFormat="DD/MM/YYYY"></nile-date-time-picker>`);
|
|
977
|
+
await settle2(el);
|
|
978
|
+
const before = el.type;
|
|
979
|
+
el.dateFormat = 'YYYY-MM-DD';
|
|
980
|
+
el.hideTimeFields = ALL_TIME;
|
|
981
|
+
await settle2(el);
|
|
982
|
+
expect(el.type).to.equal(before);
|
|
983
|
+
expect(el.dateFormat).to.equal('YYYY-MM-DD');
|
|
984
|
+
}).timeout(60000);
|
|
985
|
+
|
|
986
|
+
it('Y13 allowedDates clamping still works after a format change', async () => {
|
|
987
|
+
const el = await make({ allowed: ['2026-06-10', '2026-06-20'] });
|
|
988
|
+
el.dateFormat = 'DD/MM/YYYY';
|
|
989
|
+
el.hideTimeFields = [];
|
|
990
|
+
await settle2(el);
|
|
991
|
+
nativeOf(el).setSelectionRange(0, 10);
|
|
992
|
+
press(el, 'Backspace');
|
|
993
|
+
for (const ch of '25062026') press(el, ch);
|
|
994
|
+
await settle2(el);
|
|
995
|
+
expect(textOf(el).startsWith('20/06/2026')).to.be.true;
|
|
996
|
+
expect(calDate(el)).to.deep.equal([2026, 6, 20]);
|
|
997
|
+
}).timeout(60000);
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
describe('Y14. switching Relative -> Absolute redraws the trigger from the retained absolute value', () => {
|
|
1001
|
+
const SEED = '2026-06-15T10:20:30.250[GMT+05:30 Asia/Kolkata]';
|
|
1002
|
+
const make = async (withValue = true): Promise<any> => {
|
|
1003
|
+
const el: any = await fixture(html`<nile-date-time-picker
|
|
1004
|
+
timezone="Asia/Kolkata" dateFormat="DD/MM/YYYY" .startYear=${0} .endYear=${9999}
|
|
1005
|
+
value=${withValue ? SEED : ''}></nile-date-time-picker>`);
|
|
1006
|
+
await settle2(el);
|
|
1007
|
+
return el;
|
|
1008
|
+
};
|
|
1009
|
+
const inputOf = (el: any) => el.shadowRoot.querySelector('nile-input') as any;
|
|
1010
|
+
const nativeOf = (el: any) => inputOf(el).input as HTMLInputElement;
|
|
1011
|
+
const textOf = (el: any) => nativeOf(el).value;
|
|
1012
|
+
const calDate = (el: any) => {
|
|
1013
|
+
const c = el.calendarElement;
|
|
1014
|
+
return [c.value.getFullYear(), c.value.getMonth() + 1, c.value.getDate()];
|
|
1015
|
+
};
|
|
1016
|
+
const focusBlur = async (el: any) => {
|
|
1017
|
+
inputOf(el).input.focus();
|
|
1018
|
+
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
1019
|
+
await settle2(el);
|
|
1020
|
+
};
|
|
1021
|
+
/** user-style mode switch: the calendar's tab group fires nile-tab-show */
|
|
1022
|
+
const switchTab = async (el: any, value: string) => {
|
|
1023
|
+
const cal = el.calendarElement;
|
|
1024
|
+
cal.shadowRoot.querySelector(`nile-tab[panel="${value}"]`).dispatchEvent(
|
|
1025
|
+
new CustomEvent('nile-tab-show', { detail: { value }, bubbles: true, composed: true })
|
|
1026
|
+
);
|
|
1027
|
+
await settle2(el);
|
|
1028
|
+
};
|
|
1029
|
+
const relativeApply = async (el: any) => {
|
|
1030
|
+
const cal = el.calendarElement;
|
|
1031
|
+
(cal.shadowRoot.querySelector('.duration__value') as HTMLElement).click();
|
|
1032
|
+
await cal.updateComplete;
|
|
1033
|
+
(cal.shadowRoot.querySelector('.apply-button') as HTMLElement).click();
|
|
1034
|
+
await settle2(el);
|
|
1035
|
+
};
|
|
1036
|
+
const watch = (el: any) => {
|
|
1037
|
+
const seen: string[] = [];
|
|
1038
|
+
for (const n of ['nile-change', 'nile-changed']) el.addEventListener(n, () => seen.push(n));
|
|
1039
|
+
const types: any[] = [];
|
|
1040
|
+
el.addEventListener('nile-type-change', (e: any) => types.push(e.detail?.value));
|
|
1041
|
+
let inputs = 0;
|
|
1042
|
+
inputOf(el).addEventListener('nile-input', () => { inputs++; });
|
|
1043
|
+
return { seen, types, inputs: () => inputs };
|
|
1044
|
+
};
|
|
1045
|
+
|
|
1046
|
+
it('Y14 Relative -> Absolute restores the retained absolute value, never the relative text', async () => {
|
|
1047
|
+
const el = await make();
|
|
1048
|
+
const value = el.value;
|
|
1049
|
+
await switchTab(el, 'relative');
|
|
1050
|
+
await relativeApply(el);
|
|
1051
|
+
expect(textOf(el)).to.contain(' - ');
|
|
1052
|
+
expect(el.value, 'relative apply leaves value alone').to.equal(value);
|
|
1053
|
+
const w = watch(el);
|
|
1054
|
+
await switchTab(el, 'absolute');
|
|
1055
|
+
expect(el.type).to.equal('absolute');
|
|
1056
|
+
expect(textOf(el).startsWith('15/06/2026')).to.be.true;
|
|
1057
|
+
expect(textOf(el)).to.contain('10:20:30.250').and.to.contain('Asia/Kolkata');
|
|
1058
|
+
expect(el.value).to.equal(value);
|
|
1059
|
+
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
1060
|
+
expect(w.seen).to.deep.equal([]);
|
|
1061
|
+
expect(w.inputs()).to.equal(0);
|
|
1062
|
+
expect(w.types).to.deep.equal(['absolute']);
|
|
1063
|
+
}).timeout(60000);
|
|
1064
|
+
|
|
1065
|
+
it('Y14 with no absolute value the trigger is cleared silently', async () => {
|
|
1066
|
+
const el = await make(false);
|
|
1067
|
+
await switchTab(el, 'relative');
|
|
1068
|
+
await relativeApply(el);
|
|
1069
|
+
expect(textOf(el)).to.contain(' - ');
|
|
1070
|
+
const w = watch(el);
|
|
1071
|
+
await switchTab(el, 'absolute');
|
|
1072
|
+
expect(textOf(el)).to.equal('');
|
|
1073
|
+
expect(el.value ?? '').to.equal('');
|
|
1074
|
+
expect(w.inputs()).to.equal(0);
|
|
1075
|
+
expect(w.seen).to.deep.equal([]);
|
|
1076
|
+
expect(w.types).to.deep.equal(['absolute']);
|
|
1077
|
+
}).timeout(60000);
|
|
1078
|
+
|
|
1079
|
+
it('Y14 focus/blur after returning to Absolute does not corrupt date, time or zone', async () => {
|
|
1080
|
+
const el = await make();
|
|
1081
|
+
const value = el.value;
|
|
1082
|
+
await switchTab(el, 'relative');
|
|
1083
|
+
await relativeApply(el);
|
|
1084
|
+
await switchTab(el, 'absolute');
|
|
1085
|
+
const text = textOf(el);
|
|
1086
|
+
for (let i = 0; i < 3; i++) {
|
|
1087
|
+
await focusBlur(el);
|
|
1088
|
+
expect(textOf(el), `blur ${i + 1}`).to.equal(text);
|
|
1089
|
+
}
|
|
1090
|
+
expect(el.value).to.equal(value);
|
|
1091
|
+
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
1092
|
+
expect(calDate(el)).to.deep.equal([2026, 6, 15]);
|
|
1093
|
+
expect((el as any).maskValues.length).to.be.greaterThan(0);
|
|
1094
|
+
}).timeout(60000);
|
|
1095
|
+
|
|
1096
|
+
it('Y14 with no absolute value, focus/blur after returning leaves the trigger empty', async () => {
|
|
1097
|
+
const el = await make(false);
|
|
1098
|
+
await switchTab(el, 'relative');
|
|
1099
|
+
await relativeApply(el);
|
|
1100
|
+
await switchTab(el, 'absolute');
|
|
1101
|
+
await focusBlur(el);
|
|
1102
|
+
expect(textOf(el)).to.equal('');
|
|
1103
|
+
expect(el.value ?? '').to.equal('');
|
|
1104
|
+
}).timeout(60000);
|
|
1105
|
+
|
|
1106
|
+
it('Y14 Absolute -> Relative -> Absolute and repeated switching show no stale text', async () => {
|
|
1107
|
+
const el = await make();
|
|
1108
|
+
const first = textOf(el);
|
|
1109
|
+
const w = watch(el);
|
|
1110
|
+
for (let i = 0; i < 3; i++) {
|
|
1111
|
+
await switchTab(el, 'relative');
|
|
1112
|
+
expect(el.type).to.equal('relative');
|
|
1113
|
+
await switchTab(el, 'absolute');
|
|
1114
|
+
expect(textOf(el), `round ${i + 1}`).to.equal(first);
|
|
1115
|
+
expect(textOf(el)).to.not.contain(' - Asia/Kolkata - ');
|
|
1116
|
+
}
|
|
1117
|
+
expect(w.types).to.deep.equal(['relative', 'absolute', 'relative', 'absolute', 'relative', 'absolute']);
|
|
1118
|
+
expect(w.seen).to.deep.equal([]);
|
|
1119
|
+
expect(w.inputs()).to.equal(0);
|
|
1120
|
+
}).timeout(60000);
|
|
1121
|
+
|
|
1122
|
+
it('Y14 a programmatic type change back to Absolute also redraws', async () => {
|
|
1123
|
+
const el = await make();
|
|
1124
|
+
const first = textOf(el);
|
|
1125
|
+
el.type = 'relative';
|
|
1126
|
+
await settle2(el);
|
|
1127
|
+
await relativeApply(el);
|
|
1128
|
+
el.type = 'absolute';
|
|
1129
|
+
await settle2(el);
|
|
1130
|
+
expect(textOf(el)).to.equal(first);
|
|
1131
|
+
}).timeout(60000);
|
|
1132
|
+
|
|
1133
|
+
it('Y14 Absolute -> Relative does not change the absolute value', async () => {
|
|
1134
|
+
const el = await make();
|
|
1135
|
+
const value = el.value;
|
|
1136
|
+
await switchTab(el, 'relative');
|
|
1137
|
+
expect(el.value).to.equal(value);
|
|
1138
|
+
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
1139
|
+
}).timeout(60000);
|
|
1140
|
+
|
|
1141
|
+
it('Y14 Absolute Apply and Relative Apply still work after switching back and forth', async () => {
|
|
1142
|
+
const el = await make();
|
|
1143
|
+
await switchTab(el, 'relative');
|
|
1144
|
+
let relative: any = null;
|
|
1145
|
+
el.addEventListener('nile-change', ((e: CustomEvent) => { relative = e.detail; }) as EventListener);
|
|
1146
|
+
await relativeApply(el);
|
|
1147
|
+
expect(relative?.startDate, 'relative apply emits a range').to.exist;
|
|
1148
|
+
await switchTab(el, 'absolute');
|
|
1149
|
+
const events: string[] = [];
|
|
1150
|
+
let detail: any = null;
|
|
1151
|
+
for (const n of ['nile-change', 'nile-changed']) el.addEventListener(n, (e: any) => { events.push(n); detail = e.detail; });
|
|
1152
|
+
(el.calendarElement.shadowRoot.querySelector('.apply-button') as HTMLElement).click();
|
|
1153
|
+
await settle2(el);
|
|
1154
|
+
expect(events).to.deep.equal(['nile-change']);
|
|
1155
|
+
expect(detail.value.startsWith('2026-06-15T10:20:30.250')).to.be.true;
|
|
1156
|
+
expect(el.value.startsWith('2026-06-15T10:20:30.250')).to.be.true;
|
|
1157
|
+
}).timeout(60000);
|
|
1158
|
+
|
|
1159
|
+
it('Y14 dateFormat and hideTimeFields updates still work after returning to Absolute', async () => {
|
|
1160
|
+
const el = await make();
|
|
1161
|
+
await switchTab(el, 'relative');
|
|
1162
|
+
await relativeApply(el);
|
|
1163
|
+
await switchTab(el, 'absolute');
|
|
1164
|
+
el.dateFormat = 'YYYY-MM-DD';
|
|
1165
|
+
el.hideTimeFields = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
1166
|
+
await settle2(el);
|
|
1167
|
+
expect(textOf(el)).to.equal('2026-06-15');
|
|
1168
|
+
el.hideTimeFields = [];
|
|
1169
|
+
el.dateFormat = 'DD/MM/YYYY';
|
|
1170
|
+
await settle2(el);
|
|
1171
|
+
expect(textOf(el).startsWith('15/06/2026')).to.be.true;
|
|
1172
|
+
}).timeout(60000);
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1175
|
+
describe('Y15. focus/blur never clamps a seeded year outside the default startYear/endYear range', () => {
|
|
1176
|
+
// no .startYear/.endYear here on purpose: the default navigation range (2000-2050) is what used to clamp the seed
|
|
1177
|
+
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
1178
|
+
const make = async (year: string, format = 'DD/MM/YYYY'): Promise<any> => {
|
|
1179
|
+
const el: any = await fixture(html`<nile-date-time-picker
|
|
1180
|
+
.timezone=${'UTC'} dateFormat=${format} .hideTimeFields=${DATE_ONLY}
|
|
1181
|
+
value=${`${year}-06-15T10:20:30[GMT+00:00 UTC]`}></nile-date-time-picker>`);
|
|
1182
|
+
await settle2(el);
|
|
1183
|
+
return el;
|
|
1184
|
+
};
|
|
1185
|
+
const inputOf = (el: any) => el.shadowRoot.querySelector('nile-input') as any;
|
|
1186
|
+
const textOf = (el: any) => (inputOf(el).input as HTMLInputElement).value;
|
|
1187
|
+
const calState = (el: any) => {
|
|
1188
|
+
const c = el.calendarElement;
|
|
1189
|
+
return [c.value.getFullYear(), c.value.getMonth(), c.value.getDate(), c.currentYear, c.currentMonth];
|
|
1190
|
+
};
|
|
1191
|
+
const focusBlur = async (el: any) => {
|
|
1192
|
+
inputOf(el).input.focus();
|
|
1193
|
+
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
1194
|
+
await settle2(el);
|
|
1195
|
+
};
|
|
1196
|
+
|
|
1197
|
+
for (const year of ['0050', '1985', '1999', '2051', '2100', '9999']) {
|
|
1198
|
+
for (const format of ['DD/MM/YYYY', 'YYYY-MM-DD']) {
|
|
1199
|
+
it(`Y15 [${format}] seeded year ${year}: focus/blur x3 leaves text, calendar, value and events untouched`, async () => {
|
|
1200
|
+
const el = await make(year, format);
|
|
1201
|
+
const text = textOf(el);
|
|
1202
|
+
const cal = calState(el);
|
|
1203
|
+
const value = el.value;
|
|
1204
|
+
expect(text, 'seeded text carries the literal year').to.contain(year);
|
|
1205
|
+
expect(cal.slice(0, 1), 'seeded calendar year').to.deep.equal([Number(year)]);
|
|
1206
|
+
let emitted = 0;
|
|
1207
|
+
el.addEventListener('nile-change', () => { emitted++; });
|
|
1208
|
+
el.addEventListener('nile-changed', () => { emitted++; });
|
|
1209
|
+
for (let i = 0; i < 3; i++) {
|
|
1210
|
+
await focusBlur(el);
|
|
1211
|
+
expect(textOf(el), `text after cycle ${i + 1}`).to.equal(text);
|
|
1212
|
+
expect(calState(el), `calendar after cycle ${i + 1}`).to.deep.equal(cal);
|
|
1213
|
+
}
|
|
1214
|
+
expect(el.value, 'value untouched').to.equal(value);
|
|
1215
|
+
expect(emitted, 'no change event from focus/blur').to.equal(0);
|
|
1216
|
+
}).timeout(60000);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
it('Y15 a year the USER types outside the range is still clamped (user edits only)', async () => {
|
|
1221
|
+
const el = await make('2026');
|
|
1222
|
+
const native = inputOf(el).input as HTMLInputElement;
|
|
1223
|
+
native.setSelectionRange(0, 10);
|
|
1224
|
+
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace', bubbles: true, composed: true, cancelable: true }));
|
|
1225
|
+
for (const ch of '15061850') {
|
|
1226
|
+
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key: ch, bubbles: true, composed: true, cancelable: true }));
|
|
1227
|
+
}
|
|
1228
|
+
await settle2(el);
|
|
1229
|
+
await focusBlur(el);
|
|
1230
|
+
expect(textOf(el)).to.equal('15/06/2000');
|
|
1231
|
+
}).timeout(60000);
|
|
1232
|
+
|
|
1233
|
+
it('Y15 a year the USER types above the range clamps to the range end', async () => {
|
|
1234
|
+
const el = await make('2026');
|
|
1235
|
+
const native = inputOf(el).input as HTMLInputElement;
|
|
1236
|
+
native.setSelectionRange(0, 10);
|
|
1237
|
+
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key: 'Backspace', bubbles: true, composed: true, cancelable: true }));
|
|
1238
|
+
for (const ch of '15062100') {
|
|
1239
|
+
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key: ch, bubbles: true, composed: true, cancelable: true }));
|
|
1240
|
+
}
|
|
1241
|
+
await settle2(el);
|
|
1242
|
+
await focusBlur(el);
|
|
1243
|
+
expect(textOf(el)).to.equal('15/06/2050');
|
|
1244
|
+
}).timeout(60000);
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
describe('Y16. an unparseable value after a valid one does not leave the old selection on screen', () => {
|
|
1248
|
+
const SEED = '2026-06-15T10:20:30.000[GMT+05:30 Asia/Kolkata]';
|
|
1249
|
+
const BAD = ['not-a-date', '2026-13-45T10:00:00', 'garbage[GMT+00:00 UTC]', ' '];
|
|
1250
|
+
const make = async (value = SEED): Promise<any> => {
|
|
1251
|
+
const el: any = await fixture(html`<nile-date-time-picker
|
|
1252
|
+
timezone="Asia/Kolkata" dateFormat="DD/MM/YYYY" value=${value}></nile-date-time-picker>`);
|
|
1253
|
+
await settle2(el);
|
|
1254
|
+
return el;
|
|
1255
|
+
};
|
|
1256
|
+
const textOf = (el: any) => (el.shadowRoot.querySelector('nile-input').input as HTMLInputElement).value;
|
|
1257
|
+
|
|
1258
|
+
for (const bad of BAD) {
|
|
1259
|
+
it(`Y16 ${JSON.stringify(bad)}: trigger and calendar empty (as for an invalid initial value), zone and events untouched`, async () => {
|
|
1260
|
+
const el = await make();
|
|
1261
|
+
expect(textOf(el), 'precondition').to.contain('15/06/2026');
|
|
1262
|
+
let changes = 0;
|
|
1263
|
+
el.addEventListener('nile-change', () => { changes++; });
|
|
1264
|
+
el.addEventListener('nile-changed', () => { changes++; });
|
|
1265
|
+
el.value = bad;
|
|
1266
|
+
await settle2(el);
|
|
1267
|
+
expect(textOf(el), 'trigger text').to.equal('');
|
|
1268
|
+
expect(el.calendarElement.value, 'calendar selection').to.equal(null);
|
|
1269
|
+
expect(el.timezone, 'zone is not touched').to.equal('Asia/Kolkata');
|
|
1270
|
+
expect(el.value, 'value is the consumer\'s, never rewritten').to.equal(bad);
|
|
1271
|
+
expect(changes, 'no change event').to.equal(0);
|
|
1272
|
+
// and a later valid value seeds normally
|
|
1273
|
+
el.value = '2027-01-02T03:04:05.000[GMT+05:30 Asia/Kolkata]';
|
|
1274
|
+
await settle2(el);
|
|
1275
|
+
expect(textOf(el)).to.contain('02/01/2027');
|
|
1276
|
+
expect(el.calendarElement.value.getFullYear()).to.equal(2027);
|
|
1277
|
+
}).timeout(60000);
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
it('Y16 an invalid INITIAL value shows an empty trigger (the behaviour the after-valid case must match)', async () => {
|
|
1281
|
+
const el = await make('not-a-date');
|
|
1282
|
+
expect(textOf(el)).to.equal('');
|
|
1283
|
+
expect(el.calendarElement.value ?? null).to.equal(null);
|
|
1284
|
+
}).timeout(60000);
|
|
1285
|
+
});
|
|
1286
|
+
|
|
1287
|
+
describe('Y17. focus/blur with a two-digit (YY) format never moves the calendar off a seeded year outside 2000-2099', () => {
|
|
1288
|
+
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
1289
|
+
const make = async (year: string): Promise<any> => {
|
|
1290
|
+
const el: any = await fixture(html`<nile-date-time-picker
|
|
1291
|
+
.timezone=${'UTC'} dateFormat="DD/MM/YY" .startYear=${0} .endYear=${9999} .hideTimeFields=${DATE_ONLY}
|
|
1292
|
+
value=${`${year}-06-15T10:20:30[GMT+00:00 UTC]`}></nile-date-time-picker>`);
|
|
1293
|
+
await settle2(el);
|
|
1294
|
+
return el;
|
|
1295
|
+
};
|
|
1296
|
+
const inputOf = (el: any) => el.shadowRoot.querySelector('nile-input') as any;
|
|
1297
|
+
const calState = (el: any) => {
|
|
1298
|
+
const c = el.calendarElement;
|
|
1299
|
+
return [c.value.getFullYear(), c.value.getMonth(), c.value.getDate(), c.currentYear, c.currentMonth];
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
for (const year of ['1985', '2026', '2099', '2100']) {
|
|
1303
|
+
it(`Y17 seeded year ${year}: focus/blur x3 leaves calendar, text, value and events untouched`, async () => {
|
|
1304
|
+
const el = await make(year);
|
|
1305
|
+
const text = (inputOf(el).input as HTMLInputElement).value;
|
|
1306
|
+
const cal = calState(el);
|
|
1307
|
+
const value = el.value;
|
|
1308
|
+
let emitted = 0;
|
|
1309
|
+
el.addEventListener('nile-change', () => { emitted++; });
|
|
1310
|
+
for (let i = 0; i < 3; i++) {
|
|
1311
|
+
inputOf(el).input.focus();
|
|
1312
|
+
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
1313
|
+
await settle2(el);
|
|
1314
|
+
expect(calState(el), `calendar after cycle ${i + 1}`).to.deep.equal(cal);
|
|
1315
|
+
expect((inputOf(el).input as HTMLInputElement).value, `text after cycle ${i + 1}`).to.equal(text);
|
|
1316
|
+
}
|
|
1317
|
+
expect(el.value).to.equal(value);
|
|
1318
|
+
expect(emitted).to.equal(0);
|
|
1319
|
+
}).timeout(60000);
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
|
|
1323
|
+
describe('Y18. a YY year is always two characters', () => {
|
|
1324
|
+
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
1325
|
+
for (const [year, yy] of [['0005', '05'], ['0009', '09'], ['0010', '10'], ['2005', '05'], ['2026', '26']]) {
|
|
1326
|
+
it(`Y18 year ${year} renders as ${yy} under DD/MM/YY`, async () => {
|
|
1327
|
+
const el: any = await fixture(html`<nile-date-time-picker
|
|
1328
|
+
.timezone=${'UTC'} dateFormat="DD/MM/YY" .startYear=${0} .endYear=${9999} .hideTimeFields=${DATE_ONLY}
|
|
1329
|
+
value=${`${year}-06-15T10:20:30[GMT+00:00 UTC]`}></nile-date-time-picker>`);
|
|
1330
|
+
await settle2(el);
|
|
1331
|
+
expect((el.shadowRoot.querySelector('nile-input').input as HTMLInputElement).value).to.equal(`15/06/${yy}`);
|
|
1332
|
+
}).timeout(60000);
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1336
|
+
describe('Y19. blur clamps only the segments the user actually edited', () => {
|
|
1337
|
+
// default navigation range (2000-2050) on purpose: every seed below is outside it (1999 and 2051 sit just beyond each end)
|
|
1338
|
+
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
1339
|
+
const make = async (value: string, format = 'DD/MM/YYYY'): Promise<any> => {
|
|
1340
|
+
const el: any = await fixture(html`<nile-date-time-picker
|
|
1341
|
+
.timezone=${'UTC'} dateFormat=${format} .hideTimeFields=${DATE_ONLY} value=${value}></nile-date-time-picker>`);
|
|
1342
|
+
await settle2(el);
|
|
1343
|
+
return el;
|
|
1344
|
+
};
|
|
1345
|
+
const inputOf = (el: any) => el.shadowRoot.querySelector('nile-input') as any;
|
|
1346
|
+
const nativeOf = (el: any) => inputOf(el).input as HTMLInputElement;
|
|
1347
|
+
const press = (el: any, key: string) =>
|
|
1348
|
+
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, composed: true, cancelable: true }));
|
|
1349
|
+
const blur = async (el: any) => {
|
|
1350
|
+
nativeOf(el).focus();
|
|
1351
|
+
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
1352
|
+
await settle2(el);
|
|
1353
|
+
};
|
|
1354
|
+
const calDate = (el: any) => {
|
|
1355
|
+
const c = el.calendarElement;
|
|
1356
|
+
return [c.value.getFullYear(), c.value.getMonth() + 1, c.value.getDate()];
|
|
1357
|
+
};
|
|
1358
|
+
/** select [from, to) of the text, delete it, and type digits */
|
|
1359
|
+
const retype = async (el: any, from: number, to: number, digits: string) => {
|
|
1360
|
+
nativeOf(el).setSelectionRange(from, to);
|
|
1361
|
+
press(el, 'Backspace');
|
|
1362
|
+
for (const ch of digits) press(el, ch);
|
|
1363
|
+
await settle2(el);
|
|
1364
|
+
};
|
|
1365
|
+
|
|
1366
|
+
for (const year of ['1985', '1999', '2051', '2100', '0050']) {
|
|
1367
|
+
it(`Y19 seeded ${year}: editing only the day, then blur, leaves the untouched year alone`, async () => {
|
|
1368
|
+
const el = await make(`${year}-06-15T00:00:00[GMT+00:00 UTC]`);
|
|
1369
|
+
await retype(el, 0, 2, '20');
|
|
1370
|
+
await blur(el);
|
|
1371
|
+
expect(nativeOf(el).value).to.equal(`20/06/${year}`);
|
|
1372
|
+
expect(calDate(el)).to.deep.equal([Number(year), 6, 20]);
|
|
1373
|
+
}).timeout(60000);
|
|
1374
|
+
|
|
1375
|
+
it(`Y19 seeded ${year}: editing only the month, then blur, leaves the untouched year alone`, async () => {
|
|
1376
|
+
const el = await make(`${year}-06-15T00:00:00[GMT+00:00 UTC]`);
|
|
1377
|
+
await retype(el, 3, 5, '08');
|
|
1378
|
+
await blur(el);
|
|
1379
|
+
expect(nativeOf(el).value).to.equal(`15/08/${year}`);
|
|
1380
|
+
expect(calDate(el)).to.deep.equal([Number(year), 8, 15]);
|
|
1381
|
+
}).timeout(60000);
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
// the approved default range is 2000-2050: a year the user completes is clamped into it, a year inside it is kept
|
|
1385
|
+
for (const [typed, expected, why] of [
|
|
1386
|
+
['1990', '2000', 'below the range → 2000'],
|
|
1387
|
+
['1999', '2000', 'just below the range → 2000'],
|
|
1388
|
+
['2100', '2050', 'above the range → 2050'],
|
|
1389
|
+
['2051', '2050', 'just above the range → 2050'],
|
|
1390
|
+
['2000', '2000', 'the range start is kept'],
|
|
1391
|
+
['2050', '2050', 'the range end is kept'],
|
|
1392
|
+
['2030', '2030', 'inside the range is kept'],
|
|
1393
|
+
]) {
|
|
1394
|
+
it(`Y19 the year IS clamped when the user edits the year itself: ${typed} → ${expected} (${why})`, async () => {
|
|
1395
|
+
const el = await make('1985-06-15T00:00:00[GMT+00:00 UTC]');
|
|
1396
|
+
await retype(el, 6, 10, typed);
|
|
1397
|
+
await blur(el);
|
|
1398
|
+
expect(nativeOf(el).value).to.equal(`15/06/${expected}`);
|
|
1399
|
+
expect(calDate(el)).to.deep.equal([Number(expected), 6, 15]);
|
|
1400
|
+
}).timeout(60000);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
it('Y19 an in-range seeded year is not changed by editing another segment', async () => {
|
|
1404
|
+
const el = await make('2030-06-15T00:00:00[GMT+00:00 UTC]');
|
|
1405
|
+
await retype(el, 0, 2, '20');
|
|
1406
|
+
await blur(el);
|
|
1407
|
+
expect(nativeOf(el).value).to.equal('20/06/2030');
|
|
1408
|
+
}).timeout(60000);
|
|
1409
|
+
|
|
1410
|
+
it('Y19 a second edit after a blur still leaves the untouched year alone', async () => {
|
|
1411
|
+
const el = await make('1985-06-15T00:00:00[GMT+00:00 UTC]');
|
|
1412
|
+
await retype(el, 0, 2, '20');
|
|
1413
|
+
await blur(el);
|
|
1414
|
+
await retype(el, 3, 5, '08');
|
|
1415
|
+
await blur(el);
|
|
1416
|
+
expect(nativeOf(el).value).to.equal('20/08/1985');
|
|
1417
|
+
}).timeout(60000);
|
|
1418
|
+
|
|
1419
|
+
it('Y19 an edited month/year still clamps the day to the month length (e.g. 31 -> 28 after choosing February)', async () => {
|
|
1420
|
+
const el = await make('1985-01-31T00:00:00[GMT+00:00 UTC]');
|
|
1421
|
+
await retype(el, 3, 5, '02');
|
|
1422
|
+
await blur(el);
|
|
1423
|
+
expect(nativeOf(el).value).to.equal('28/02/1985');
|
|
1424
|
+
}).timeout(60000);
|
|
1425
|
+
});
|
|
1426
|
+
|
|
1427
|
+
describe('Y19b. typed-year clamping: explicit startYear / endYear win, an unset side falls back to 2000 / 2050', () => {
|
|
1428
|
+
const DATE_ONLY = ['hours', 'minutes', 'seconds', 'milliseconds', 'timezone'];
|
|
1429
|
+
const make = async (bounds: { start?: number; end?: number }, format = 'DD/MM/YYYY'): Promise<any> => {
|
|
1430
|
+
const el: any = await fixture(html`<nile-date-time-picker
|
|
1431
|
+
.timezone=${'UTC'} dateFormat=${format} .hideTimeFields=${DATE_ONLY} .startYear=${bounds.start} .endYear=${bounds.end}
|
|
1432
|
+
value="2026-06-15T00:00:00[GMT+00:00 UTC]"></nile-date-time-picker>`);
|
|
1433
|
+
await settle2(el);
|
|
1434
|
+
return el;
|
|
1435
|
+
};
|
|
1436
|
+
const inputOf = (el: any) => el.shadowRoot.querySelector('nile-input') as any;
|
|
1437
|
+
const nativeOf = (el: any) => inputOf(el).input as HTMLInputElement;
|
|
1438
|
+
const press = (el: any, key: string) =>
|
|
1439
|
+
inputOf(el).dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, composed: true, cancelable: true }));
|
|
1440
|
+
/** retype the year segment (the last four characters of DD/MM/YYYY) and blur */
|
|
1441
|
+
const typeYear = async (el: any, digits: string, from = 6, to = 10) => {
|
|
1442
|
+
nativeOf(el).setSelectionRange(from, to);
|
|
1443
|
+
press(el, 'Backspace');
|
|
1444
|
+
for (const ch of digits) press(el, ch);
|
|
1445
|
+
await settle2(el);
|
|
1446
|
+
nativeOf(el).focus();
|
|
1447
|
+
inputOf(el).dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
1448
|
+
await settle2(el);
|
|
1449
|
+
};
|
|
1450
|
+
const calYear = (el: any) => el.calendarElement.value.getFullYear();
|
|
1451
|
+
|
|
1452
|
+
type Case = [string, { start?: number; end?: number }, string, string];
|
|
1453
|
+
const cases: Case[] = [
|
|
1454
|
+
// no bounds: the 2000-2050 default applies on both sides
|
|
1455
|
+
['no bounds, before 2000', {}, '1850', '2000'],
|
|
1456
|
+
['no bounds, 1999', {}, '1999', '2000'],
|
|
1457
|
+
['no bounds, after 2050', {}, '2100', '2050'],
|
|
1458
|
+
['no bounds, 2051', {}, '2051', '2050'],
|
|
1459
|
+
['no bounds, year 0050', {}, '0050', '2000'],
|
|
1460
|
+
['no bounds, 2000 and 2050 are kept', {}, '2000', '2000'],
|
|
1461
|
+
['no bounds, 2050 is kept', {}, '2050', '2050'],
|
|
1462
|
+
// explicit bounds win over the default, including outside 2000-2050
|
|
1463
|
+
['explicit bounds before 2000 are respected', { start: 1850, end: 2100 }, '1850', '1850'],
|
|
1464
|
+
['explicit bounds after 2050 are respected', { start: 1850, end: 2100 }, '2100', '2100'],
|
|
1465
|
+
['explicit bounds still clamp below', { start: 1850, end: 2100 }, '1800', '1850'],
|
|
1466
|
+
['explicit bounds still clamp above', { start: 1850, end: 2100 }, '2200', '2100'],
|
|
1467
|
+
['explicit 0-9999 keeps year 0050', { start: 0, end: 9999 }, '0050', '0050'],
|
|
1468
|
+
['explicit 0-9999 keeps 9999', { start: 0, end: 9999 }, '9999', '9999'],
|
|
1469
|
+
// custom bounds inside the default range
|
|
1470
|
+
['custom bounds, below', { start: 1990, end: 2010 }, '1980', '1990'],
|
|
1471
|
+
['custom bounds, above', { start: 1990, end: 2010 }, '2020', '2010'],
|
|
1472
|
+
['custom bounds, inside', { start: 1990, end: 2010 }, '2000', '2000'],
|
|
1473
|
+
// one-sided: the unset side falls back to 2000 / 2050
|
|
1474
|
+
['startYear only, below it', { start: 1990 }, '1980', '1990'],
|
|
1475
|
+
['startYear only, before 2000 but above it', { start: 1990 }, '1995', '1995'],
|
|
1476
|
+
['startYear only, above the default end', { start: 1990 }, '2100', '2050'],
|
|
1477
|
+
['endYear only, above it', { end: 2010 }, '2020', '2010'],
|
|
1478
|
+
['endYear only, below the default start', { end: 2010 }, '1850', '2000'],
|
|
1479
|
+
['endYear only, past 2050 but within it', { end: 2100 }, '2080', '2080'],
|
|
1480
|
+
['endYear only, past it', { end: 2100 }, '2101', '2100'],
|
|
1481
|
+
];
|
|
1482
|
+
for (const [name, bounds, typed, expected] of cases) {
|
|
1483
|
+
it(`Y19b ${name}: typing ${typed} gives ${expected}`, async () => {
|
|
1484
|
+
const el = await make(bounds);
|
|
1485
|
+
await typeYear(el, typed);
|
|
1486
|
+
expect(nativeOf(el).value).to.equal(`15/06/${expected}`);
|
|
1487
|
+
expect(calYear(el)).to.equal(Number(expected));
|
|
1488
|
+
}).timeout(60000);
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
it('Y19b no bounds: a typed YY year past 2050 is pulled back to 2050 (75 becomes 50)', async () => {
|
|
1492
|
+
const el = await make({}, 'DD/MM/YY');
|
|
1493
|
+
await typeYear(el, '75', 6, 8);
|
|
1494
|
+
expect(nativeOf(el).value).to.equal('15/06/50');
|
|
1495
|
+
expect(calYear(el)).to.equal(2050);
|
|
1496
|
+
}).timeout(60000);
|
|
1497
|
+
|
|
1498
|
+
it('Y19b explicit endYear 2099: a typed YY year 75 is kept (2075)', async () => {
|
|
1499
|
+
const el = await make({ end: 2099 }, 'DD/MM/YY');
|
|
1500
|
+
await typeYear(el, '75', 6, 8);
|
|
1501
|
+
expect(nativeOf(el).value).to.equal('15/06/75');
|
|
1502
|
+
expect(calYear(el)).to.equal(2075);
|
|
1503
|
+
}).timeout(60000);
|
|
1504
|
+
|
|
1505
|
+
it('Y19b endYear only: the calendar the picker renders gets only that bound', async () => {
|
|
1506
|
+
const el = await make({ end: 2010 });
|
|
1507
|
+
const cal = el.calendarElement;
|
|
1508
|
+
expect(cal.startYear).to.be.undefined;
|
|
1509
|
+
expect(Number(cal.endYear)).to.equal(2010);
|
|
1510
|
+
}).timeout(60000);
|
|
1511
|
+
});
|
|
1512
|
+
|
|
1513
|
+
describe('Y20. Set to now uses the machine zone; value = null keeps the configured timezone', () => {
|
|
1514
|
+
const FROZEN = Date.UTC(2026, 5, 15, 18, 42, 37, 456);
|
|
1515
|
+
const textOf = (el: any) => (el.shadowRoot.querySelector('nile-input').input as HTMLInputElement).value;
|
|
1516
|
+
|
|
1517
|
+
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 () => {
|
|
1518
|
+
const HOST = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1519
|
+
const el: any = await fixture(html`<nile-date-time-picker timezone="America/New_York" dateFormat="DD/MM/YYYY"></nile-date-time-picker>`);
|
|
1520
|
+
const cal = await settle2(el);
|
|
1521
|
+
const RealDate = Date;
|
|
1522
|
+
class FrozenDate extends RealDate {
|
|
1523
|
+
constructor(...args: any[]) { if (args.length === 0) super(FROZEN); else super(...(args as [any])); }
|
|
1524
|
+
static now() { return FROZEN; }
|
|
1525
|
+
}
|
|
1526
|
+
let detail: any = null;
|
|
1527
|
+
el.addEventListener('nile-change', (e: CustomEvent) => { detail = e.detail; });
|
|
1528
|
+
(globalThis as any).Date = FrozenDate;
|
|
1529
|
+
try { (cal.shadowRoot!.querySelector('.tp-set-to-now-button') as HTMLElement).click(); }
|
|
1530
|
+
finally { (globalThis as any).Date = RealDate; }
|
|
1531
|
+
await settle2(el);
|
|
1532
|
+
(cal.shadowRoot!.querySelector('.apply-button') as HTMLElement).click();
|
|
1533
|
+
await settle2(el);
|
|
1534
|
+
// the machine's own reading of the frozen instant (host zone differs between runs)
|
|
1535
|
+
const t = new RealDate(FROZEN);
|
|
1536
|
+
const p2 = (n: number) => String(n).padStart(2, '0');
|
|
1537
|
+
expect(textOf(el)).to.equal(
|
|
1538
|
+
`${p2(t.getDate())}/${p2(t.getMonth() + 1)}/${t.getFullYear()} - ${p2(t.getHours())}:${p2(t.getMinutes())}:${p2(t.getSeconds())}.456 - ${HOST}`);
|
|
1539
|
+
expect(el.timezone, 'picker zone becomes the machine zone').to.equal(HOST);
|
|
1540
|
+
expect(cal.timezone).to.equal(HOST);
|
|
1541
|
+
expect(detail.timezone).to.equal(HOST);
|
|
1542
|
+
expect(detail.unixEpoch).to.equal(FROZEN);
|
|
1543
|
+
}).timeout(60000);
|
|
1544
|
+
|
|
1545
|
+
it('Y20 value = null clears value and display and keeps the configured timezone', async () => {
|
|
1546
|
+
const el: any = await fixture(html`<nile-date-time-picker timezone="Asia/Kolkata" dateFormat="DD/MM/YYYY"
|
|
1547
|
+
value="2026-06-15T10:20:30"></nile-date-time-picker>`);
|
|
1548
|
+
await settle2(el);
|
|
1549
|
+
expect(textOf(el), 'precondition').to.contain('15/06/2026');
|
|
1550
|
+
el.value = null;
|
|
1551
|
+
await settle2(el);
|
|
1552
|
+
expect(el.value).to.equal(null);
|
|
1553
|
+
expect(textOf(el)).to.equal('');
|
|
1554
|
+
expect(el.calendarElement.value).to.equal(null);
|
|
1555
|
+
expect(el.timezone).to.equal('Asia/Kolkata');
|
|
1556
|
+
expect(el.calendarElement.timezone).to.equal('Asia/Kolkata');
|
|
1557
|
+
}).timeout(60000);
|
|
1558
|
+
});
|
|
1559
|
+
|
|
1560
|
+
describe('Y21. an overflow Relative duration never reaches the picker (Finding #8)', () => {
|
|
1561
|
+
const fire = (target: HTMLElement, value: string) =>
|
|
1562
|
+
target.dispatchEvent(new CustomEvent('nile-change', { detail: { value }, bubbles: false, composed: true }));
|
|
1563
|
+
const make = async (): Promise<any> => {
|
|
1564
|
+
const el: any = await fixture(html`<nile-date-time-picker timezone="UTC" dateFormat="DD/MM/YYYY"
|
|
1565
|
+
value="2026-06-15T10:20:30.250[GMT+00:00 UTC]"></nile-date-time-picker>`);
|
|
1566
|
+
await settle2(el);
|
|
1567
|
+
return el;
|
|
1568
|
+
};
|
|
1569
|
+
const tab = async (el: any, value: string) => {
|
|
1570
|
+
el.calendarElement.shadowRoot.querySelector(`nile-tab[panel="${value}"]`).dispatchEvent(
|
|
1571
|
+
new CustomEvent('nile-tab-show', { detail: { value }, bubbles: true, composed: true })
|
|
1572
|
+
);
|
|
1573
|
+
await settle2(el);
|
|
1574
|
+
};
|
|
1575
|
+
const enter = async (el: any, unit: string, n: number) => {
|
|
1576
|
+
const cal = el.calendarElement;
|
|
1577
|
+
fire(cal.shadowRoot.querySelector('.time-input') as HTMLElement, unit);
|
|
1578
|
+
fire(cal.shadowRoot.querySelector('.duration-input') as HTMLElement, String(n));
|
|
1579
|
+
await settle2(el);
|
|
1580
|
+
};
|
|
1581
|
+
const apply = (el: any) => el.calendarElement.shadowRoot.querySelector('.apply-button') as HTMLElement;
|
|
1582
|
+
const textOf = (el: any) => (el.shadowRoot.querySelector('nile-input') as any).input.value as string;
|
|
1583
|
+
|
|
1584
|
+
for (const [unit, n] of [['minutes', 999999999999], ['hours', 99999999999], ['days', 999999999], ['weeks', 999999999], ['months', 999999999]] as Array<[string, number]>) {
|
|
1585
|
+
it(`Y21 ${unit}: ${n} -> Apply is disabled, nothing is thrown, emitted or changed; correcting it applies normally`, async () => {
|
|
1586
|
+
const el = await make();
|
|
1587
|
+
const value = el.value;
|
|
1588
|
+
await tab(el, 'relative');
|
|
1589
|
+
const errors: string[] = [];
|
|
1590
|
+
const onError = (e: ErrorEvent) => { errors.push(e.message); e.preventDefault(); };
|
|
1591
|
+
window.addEventListener('error', onError);
|
|
1592
|
+
const seen: string[] = [];
|
|
1593
|
+
for (const name of ['nile-change', 'nile-changed']) el.addEventListener(name, () => seen.push(name));
|
|
1594
|
+
try {
|
|
1595
|
+
const before = textOf(el);
|
|
1596
|
+
await enter(el, unit, n);
|
|
1597
|
+
expect(apply(el).hasAttribute('disabled'), 'Apply disabled').to.be.true;
|
|
1598
|
+
apply(el).click();
|
|
1599
|
+
await settle2(el);
|
|
1600
|
+
expect(errors, 'no uncaught RangeError').to.deep.equal([]);
|
|
1601
|
+
expect(seen, 'no change events').to.deep.equal([]);
|
|
1602
|
+
expect(textOf(el), 'trigger unchanged').to.equal(before);
|
|
1603
|
+
expect(el.value, 'value unchanged').to.equal(value);
|
|
1604
|
+
expect(el.timezone).to.equal('UTC');
|
|
1605
|
+
|
|
1606
|
+
await enter(el, unit, 2);
|
|
1607
|
+
expect(apply(el).hasAttribute('disabled'), 'Apply enabled again').to.be.false;
|
|
1608
|
+
apply(el).click();
|
|
1609
|
+
await settle2(el);
|
|
1610
|
+
expect(seen).to.deep.equal(['nile-change']);
|
|
1611
|
+
expect(textOf(el)).to.contain(' - UTC');
|
|
1612
|
+
expect(errors).to.deep.equal([]);
|
|
1613
|
+
} finally {
|
|
1614
|
+
window.removeEventListener('error', onError);
|
|
1615
|
+
}
|
|
1616
|
+
}).timeout(60000);
|
|
1617
|
+
}
|
|
1618
|
+
});
|