@internetarchive/histogram-date-range 0.1.12-alpha.2 → 1.0.0
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/dist/src/histogram-date-range.d.ts +3 -0
- package/dist/src/histogram-date-range.js +255 -245
- package/dist/src/histogram-date-range.js.map +1 -1
- package/dist/test/histogram-date-range.test.js +58 -0
- package/dist/test/histogram-date-range.test.js.map +1 -1
- package/docs/dist/src/histogram-date-range.js +11 -2
- package/package.json +1 -1
- package/src/histogram-date-range.ts +920 -912
- package/test/histogram-date-range.test.ts +89 -0
|
@@ -104,6 +104,95 @@ describe('HistogramDateRange', () => {
|
|
|
104
104
|
expect(maxDateInput.value).to.eq('12/31/2199');
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
+
it('when updateWhileFocused option is true, updates are fired upon changing input focus', async () => {
|
|
108
|
+
const el = await createCustomElementInHTMLContainer();
|
|
109
|
+
el.updateWhileFocused = true;
|
|
110
|
+
await el.updateComplete;
|
|
111
|
+
|
|
112
|
+
let updateEventFired = false;
|
|
113
|
+
el.addEventListener(
|
|
114
|
+
'histogramDateRangeUpdated',
|
|
115
|
+
() => (updateEventFired = true)
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
/* -------------------------- minimum (left) slider ------------------------- */
|
|
119
|
+
const minDateInput = el.shadowRoot?.querySelector(
|
|
120
|
+
'#date-min'
|
|
121
|
+
) as HTMLInputElement;
|
|
122
|
+
|
|
123
|
+
/* -------------------------- maximum (right) slider ------------------------- */
|
|
124
|
+
const maxDateInput = el.shadowRoot?.querySelector(
|
|
125
|
+
'#date-max'
|
|
126
|
+
) as HTMLInputElement;
|
|
127
|
+
|
|
128
|
+
minDateInput.focus();
|
|
129
|
+
|
|
130
|
+
// set valid min date, but don't hit Enter -- just switch focus to the max date input
|
|
131
|
+
minDateInput.value = '1950';
|
|
132
|
+
maxDateInput.focus();
|
|
133
|
+
await el.updateComplete;
|
|
134
|
+
await aTimeout(0);
|
|
135
|
+
|
|
136
|
+
// update event should have fired, setting the minSelectedDate prop & slider position accordingly
|
|
137
|
+
expect(updateEventFired).to.be.true;
|
|
138
|
+
expect(Math.floor(el.minSliderX)).to.eq(84);
|
|
139
|
+
expect(el.minSelectedDate).to.eq('1/1/1950');
|
|
140
|
+
|
|
141
|
+
updateEventFired = false;
|
|
142
|
+
await el.updateComplete;
|
|
143
|
+
|
|
144
|
+
// set valid max date, but don't hit Enter -- just switch focus to the min date input
|
|
145
|
+
maxDateInput.value = '3/12/1975';
|
|
146
|
+
minDateInput.focus();
|
|
147
|
+
await el.updateComplete;
|
|
148
|
+
await aTimeout(0);
|
|
149
|
+
|
|
150
|
+
// update event should have fired, setting the maxSelectedDate prop & slider position accordingly
|
|
151
|
+
expect(updateEventFired).to.be.true;
|
|
152
|
+
expect(Math.floor(el.maxSliderX)).to.eq(121);
|
|
153
|
+
expect(el.maxSelectedDate).to.eq('3/12/1975');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('when updateWhileFocused option is false (default), updates are not fired while one of the inputs remains focused', async () => {
|
|
157
|
+
const el = await createCustomElementInHTMLContainer();
|
|
158
|
+
|
|
159
|
+
let updateEventFired = false;
|
|
160
|
+
el.addEventListener(
|
|
161
|
+
'histogramDateRangeUpdated',
|
|
162
|
+
() => (updateEventFired = true)
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
/* -------------------------- minimum (left) slider ------------------------- */
|
|
166
|
+
const minDateInput = el.shadowRoot?.querySelector(
|
|
167
|
+
'#date-min'
|
|
168
|
+
) as HTMLInputElement;
|
|
169
|
+
|
|
170
|
+
/* -------------------------- maximum (right) slider ------------------------- */
|
|
171
|
+
const maxDateInput = el.shadowRoot?.querySelector(
|
|
172
|
+
'#date-max'
|
|
173
|
+
) as HTMLInputElement;
|
|
174
|
+
|
|
175
|
+
minDateInput.focus();
|
|
176
|
+
|
|
177
|
+
// set valid min date, but don't hit Enter -- just switch focus to the max date input
|
|
178
|
+
minDateInput.value = '1950';
|
|
179
|
+
maxDateInput.focus();
|
|
180
|
+
await el.updateComplete;
|
|
181
|
+
await aTimeout(0);
|
|
182
|
+
|
|
183
|
+
// update event should NOT have fired, because focus remains within the inputs
|
|
184
|
+
expect(updateEventFired).to.be.false;
|
|
185
|
+
|
|
186
|
+
// set valid max date, but don't hit Enter -- just switch focus to the min date input
|
|
187
|
+
maxDateInput.value = '3/12/1975';
|
|
188
|
+
minDateInput.focus();
|
|
189
|
+
await el.updateComplete;
|
|
190
|
+
await aTimeout(0);
|
|
191
|
+
|
|
192
|
+
// update event should NOT have fired, because focus remains within the inputs
|
|
193
|
+
expect(updateEventFired).to.be.false;
|
|
194
|
+
});
|
|
195
|
+
|
|
107
196
|
it('handles invalid date inputs', async () => {
|
|
108
197
|
const el = await createCustomElementInHTMLContainer();
|
|
109
198
|
|