Skip to content

Commit c39c6a3

Browse files
committed
test(drp): add test for clear icon shown if there's either start/end set
1 parent 951ea67 commit c39c6a3

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/components/date-range-picker/date-range-picker.common.spec.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('Date range picker - common tests for single and two inputs mode', () =
3636
let calendar: IgcCalendarComponent;
3737

3838
const toggleIcon = 'today';
39+
const clearIcon = 'input_clear';
3940
const today = CalendarDay.today;
4041
const tomorrow = today.add('day', 1);
4142

@@ -84,6 +85,33 @@ describe('Date range picker - common tests for single and two inputs mode', () =
8485
expect(calendar).not.to.be.undefined;
8586
expect(calendar.parentElement).to.equal(dialog);
8687
});
88+
it('should render the clear icon as soon as there is a start or end date defined', async () => {
89+
expect(picker.open).to.equal(false);
90+
expect(picker.value).to.deep.equal({ start: null, end: null });
91+
92+
let clear = getIcon(picker, clearIcon);
93+
expect(clear).to.be.null;
94+
95+
picker.value = { start: today.native, end: null };
96+
await elementUpdated(picker);
97+
98+
expect(picker.value).to.deep.equal({
99+
start: today.native,
100+
end: null,
101+
});
102+
clear = getIcon(picker, clearIcon);
103+
expect(clear).not.to.be.null;
104+
105+
picker.value = { start: null, end: tomorrow.native };
106+
await elementUpdated(picker);
107+
108+
expect(picker.value).to.deep.equal({
109+
start: null,
110+
end: tomorrow.native,
111+
});
112+
clear = getIcon(picker, clearIcon);
113+
expect(clear).not.to.be.null;
114+
});
87115
});
88116

89117
describe('Properties', () => {
@@ -578,7 +606,7 @@ describe('Date range picker - common tests for single and two inputs mode', () =
578606
expect(picker.open).to.be.false;
579607
});
580608

581-
it('should not clear the value by clicking on the clear icon', async () => {
609+
it('should not clear the value by clicking on the toggle icon', async () => {
582610
simulateClick(getIcon(picker, toggleIcon));
583611
await elementUpdated(picker);
584612

@@ -611,7 +639,7 @@ describe('Date range picker - common tests for single and two inputs mode', () =
611639
expect(picker.open).to.be.false;
612640
});
613641

614-
it('should not clear the value by clicking on the clear icon', async () => {
642+
it('should not clear the value by clicking on the toggle icon', async () => {
615643
simulateClick(getIcon(picker, toggleIcon));
616644
await elementUpdated(picker);
617645

0 commit comments

Comments
 (0)