Skip to content

Commit

Permalink
Do not send request if same date range is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-white committed Aug 9, 2019
1 parent 09f7664 commit 5958ef9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/components/audit/filters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,26 @@ export default {
filter() {
this.$emit('filter', { action: this.action, dateRange: this.dateRange });
},
sameDateRange(range1, range2) {
return range1[0].valueOf() === range2[0].valueOf() &&
range1[1].valueOf() === range2[1].valueOf();
},
closeCalendar(dates) {
if (dates.length !== 0) {
this.dateRange = dates.map(date => DateTime.fromJSDate(date));
const dateRange = dates.map(date => DateTime.fromJSDate(date));
if (!this.sameDateRange(dateRange, this.dateRange)) {
this.dateRange = dateRange;
this.filter();
}
} else {
const today = DateTime.local().startOf('day');
this.dateRange = [today, today];
this.dateRangeString = this.dateRangeToString(this.dateRange);
const dateRange = [today, today];
if (!this.sameDateRange(dateRange, this.dateRange)) {
this.dateRange = dateRange;
this.dateRangeString = this.dateRangeToString(dateRange);
this.filter();
}
}
this.filter();
}
}
};
Expand Down
17 changes: 17 additions & 0 deletions test/components/audit/filters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,21 @@ describe('AuditFilters', () => {
.respondWithData(() => testData.extendedAudits.sorted())
.finally(restoreLuxon);
});

it('does not send a request if the same date range is selected', () => {
const restoreLuxon = setLuxon({
defaultZoneName: 'utc',
now: '1970-01-01T12:00:00Z'
});
return mockHttp()
.mount(AuditList)
.respondWithData(() => testData.extendedAudits.sorted())
.complete()
.request(component => {
const date = DateTime.fromISO('1970-01-01').toJSDate();
component.first(AuditFilters).vm.closeCalendar([date, date]);
})
.respondWithData([/* no responses */])
.finally(restoreLuxon);
});
});

0 comments on commit 5958ef9

Please sign in to comment.