|
1 |
| -import { aTimeout, expect, fixture, html } from "@open-wc/testing"; |
| 1 | +import { aTimeout, elementUpdated, expect, fixture, html } from "@open-wc/testing"; |
2 | 2 | import { BlButton, BlDatePicker } from "../../baklava";
|
3 | 3 | import { CALENDAR_TYPES } from "../calendar/bl-calendar.constant";
|
4 | 4 | import sinon from "sinon";
|
@@ -95,11 +95,20 @@ describe("BlDatepicker", () => {
|
95 | 95 | element._selectedDates = [new Date(2023, 1, 1)];
|
96 | 96 | await element.updateComplete;
|
97 | 97 |
|
| 98 | + element.addEventListener("bl-datepicker-change", (event) => { |
| 99 | + const customEvent = event as CustomEvent; |
| 100 | + |
| 101 | + expect(customEvent).to.exist; |
| 102 | + expect(customEvent.detail).to.deep.equal([]); |
| 103 | + |
| 104 | + }); |
| 105 | + |
98 | 106 | const clearButton = element.shadowRoot?.querySelector("bl-button") as BlButton;
|
99 | 107 |
|
100 | 108 | clearButton?.click();
|
101 | 109 | await element.updateComplete;
|
102 | 110 |
|
| 111 | + |
103 | 112 | expect(element._selectedDates).to.deep.equal([]);
|
104 | 113 | expect(element._inputValue).to.equal("");
|
105 | 114 | });
|
@@ -275,16 +284,6 @@ describe("BlDatepicker", () => {
|
275 | 284 | expect(element.value).to.be.undefined;
|
276 | 285 | });
|
277 | 286 |
|
278 |
| - it("should warn when 'value' is not an array for multiple/range selection", async () => { |
279 |
| - element = await fixture<BlDatePicker>(html` |
280 |
| - <bl-datepicker type="multiple" locale="en"></bl-datepicker>`); |
281 |
| - element.value = new Date(); |
282 |
| - |
283 |
| - element.firstUpdated(); |
284 |
| - |
285 |
| - expect(consoleWarnSpy.calledOnce).to.be.true; |
286 |
| - }); |
287 |
| - |
288 | 287 | it("should not warn when value is an array for multiple/range selection", () => {
|
289 | 288 | element.type = CALENDAR_TYPES.MULTIPLE;
|
290 | 289 | element.value = [new Date(), new Date()];
|
@@ -376,4 +375,13 @@ describe("BlDatepicker", () => {
|
376 | 375 | expect(focusSpy.called).to.be.true;
|
377 | 376 | });
|
378 | 377 |
|
| 378 | + it("should call setDatePickerInput when _selectedDates changes", async () => { |
| 379 | + const setDatePickerInputSpy = sinon.spy(element, "setDatePickerInput"); |
| 380 | + |
| 381 | + element.value = [new Date(2025,0,10)]; |
| 382 | + await elementUpdated(element); |
| 383 | + |
| 384 | + expect(setDatePickerInputSpy).to.have.been.calledOnceWith(element._selectedDates); |
| 385 | + }); |
| 386 | + |
379 | 387 | });
|
0 commit comments