Skip to content

Commit 92bbdfc

Browse files
committed
Always set this.dateRangeString when date range is cleared
1 parent 5958ef9 commit 92bbdfc

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

src/components/audit/filters.vue

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,24 @@ export default {
9191
filter() {
9292
this.$emit('filter', { action: this.action, dateRange: this.dateRange });
9393
},
94-
sameDateRange(range1, range2) {
95-
return range1[0].valueOf() === range2[0].valueOf() &&
96-
range1[1].valueOf() === range2[1].valueOf();
94+
todayToToday() {
95+
const today = DateTime.local().startOf('day');
96+
return [today, today];
9797
},
9898
closeCalendar(dates) {
99-
if (dates.length !== 0) {
100-
const dateRange = dates.map(date => DateTime.fromJSDate(date));
101-
if (!this.sameDateRange(dateRange, this.dateRange)) {
102-
this.dateRange = dateRange;
103-
this.filter();
104-
}
105-
} else {
106-
const today = DateTime.local().startOf('day');
107-
const dateRange = [today, today];
108-
if (!this.sameDateRange(dateRange, this.dateRange)) {
109-
this.dateRange = dateRange;
110-
this.dateRangeString = this.dateRangeToString(dateRange);
111-
this.filter();
112-
}
99+
const dateRange = dates.length !== 0
100+
? dates.map(date => DateTime.fromJSDate(date))
101+
: this.todayToToday();
102+
if (dateRange[0].valueOf() !== this.dateRange[0].valueOf() ||
103+
dateRange[1].valueOf() !== this.dateRange[1].valueOf()) {
104+
this.dateRange = dateRange;
105+
this.filter();
113106
}
107+
// If the date range is cleared, this.dateRangeString will be empty, and
108+
// we will need to reset it (regardless of whether this.dateRange
109+
// changed).
110+
if (dates.length === 0)
111+
this.dateRangeString = this.dateRangeToString(dateRange);
114112
}
115113
}
116114
};

test/components/audit/filters.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,38 @@ describe('AuditFilters', () => {
134134
defaultZoneName: 'utc',
135135
now: '1970-01-01T12:00:00Z'
136136
});
137+
let called = false;
137138
return mockHttp()
138139
.mount(AuditList)
139140
.respondWithData(() => testData.extendedAudits.sorted())
140141
.complete()
142+
// Select the same date range.
141143
.request(component => {
142144
const date = DateTime.fromISO('1970-01-01').toJSDate();
143145
component.first(AuditFilters).vm.closeCalendar([date, date]);
144146
})
145147
.respondWithData([/* no responses */])
148+
.complete()
149+
// Clear the date range (defaulting to the same date range).
150+
.request(component => {
151+
const auditFilters = component.first(AuditFilters);
152+
const { dateRangeToString } = auditFilters.vm;
153+
auditFilters.setMethods({
154+
dateRangeToString: (dateRange) => {
155+
called = true;
156+
return dateRangeToString(dateRange);
157+
}
158+
});
159+
return auditFilters.vm.$nextTick().then(() => {
160+
auditFilters.vm.closeCalendar([]);
161+
});
162+
})
163+
.respondWithData([/* no responses */])
164+
.then(() => {
165+
// The date range has not changed, but the dateRangeString property
166+
// still should have been reset.
167+
called.should.be.true();
168+
})
146169
.finally(restoreLuxon);
147170
});
148171
});

0 commit comments

Comments
 (0)