diff --git a/platform/features/imagery/src/controllers/ImageryController.js b/platform/features/imagery/src/controllers/ImageryController.js index 1b29504622..bfa810b2ef 100644 --- a/platform/features/imagery/src/controllers/ImageryController.js +++ b/platform/features/imagery/src/controllers/ImageryController.js @@ -161,13 +161,30 @@ define( * @returns {boolean} falsy when a duplicate datum is given */ ImageryController.prototype.updateHistory = function (datum) { - if (this.$scope.imageHistory.length === 0 || - !_.isEqual(this.$scope.imageHistory.slice(-1)[0], datum)) { + if (!this.datumMatchesMostRecent(datum)) { var index = _.sortedIndex(this.$scope.imageHistory, datum, this.timeFormat.format.bind(this.timeFormat)); this.$scope.imageHistory.splice(index, 0, datum); return true; + } else { + return false; } + }; + /** + * Checks to see if the given datum is the same as the most recent in history. + * @private + * @param {object} [datum] target telemetry datum + * @returns {boolean} true if datum is most recent in history, false otherwise + */ + ImageryController.prototype.datumMatchesMostRecent = function (datum) { + if (this.$scope.imageHistory.length !== 0) { + var datumTime = this.timeFormat.format(datum); + var datumURL = this.imageFormat.format(datum); + var lastHistoryTime = this.timeFormat.format(this.$scope.imageHistory.slice(-1)[0]); + var lastHistoryURL = this.imageFormat.format(this.$scope.imageHistory.slice(-1)[0]); + + return datumTime === lastHistoryTime && datumURL === lastHistoryURL; + } return false; }; diff --git a/platform/features/imagery/test/controllers/ImageryControllerSpec.js b/platform/features/imagery/test/controllers/ImageryControllerSpec.js index 0e298104d8..c63e37e882 100644 --- a/platform/features/imagery/test/controllers/ImageryControllerSpec.js +++ b/platform/features/imagery/test/controllers/ImageryControllerSpec.js @@ -230,10 +230,14 @@ define( }); it ("doesnt append duplicate datum", function () { - var mockDatum = {url: 'image/url', utc: 1434600000000}; + var mockDatum = {value: 'image/url', timestamp: 1434700000000}; + var mockDatum2 = {value: 'image/url', timestamp: 1434700000000}; + var mockDatum3 = {value: 'image/url', url: 'someval', timestamp: 1434700000000}; expect(controller.updateHistory(mockDatum)).toBe(true); expect(controller.updateHistory(mockDatum)).toBe(false); expect(controller.updateHistory(mockDatum)).toBe(false); + expect(controller.updateHistory(mockDatum2)).toBe(false); + expect(controller.updateHistory(mockDatum3)).toBe(false); }); describe("when user clicks on imagery thumbnail", function () {