From 5958ef99833935d190a85191f81d0fca71275725 Mon Sep 17 00:00:00 2001 From: Matthew White Date: Fri, 9 Aug 2019 16:32:42 -0400 Subject: [PATCH] Do not send request if same date range is selected --- src/components/audit/filters.vue | 19 +++++++++++++++---- test/components/audit/filters.spec.js | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/components/audit/filters.vue b/src/components/audit/filters.vue index bb15c4b49..25149c7ec 100644 --- a/src/components/audit/filters.vue +++ b/src/components/audit/filters.vue @@ -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(); } } }; diff --git a/test/components/audit/filters.spec.js b/test/components/audit/filters.spec.js index 495067907..5b4389800 100644 --- a/test/components/audit/filters.spec.js +++ b/test/components/audit/filters.spec.js @@ -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); + }); });