From fef3d5d2b0bd8243a1a9740a22c976b439c9eddc Mon Sep 17 00:00:00 2001 From: Joe Fiorini Date: Wed, 1 Jul 2015 16:18:00 -0400 Subject: [PATCH] [system_tracking] Make sure value array comparison is order insensitive --- .../js/system-tracking/compare-facts/flat.js | 8 ++-- .../compare-facts/flat-test.js | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/awx/ui/static/js/system-tracking/compare-facts/flat.js b/awx/ui/static/js/system-tracking/compare-facts/flat.js index 6ce42a3464..6e487abf94 100644 --- a/awx/ui/static/js/system-tracking/compare-facts/flat.js +++ b/awx/ui/static/js/system-tracking/compare-facts/flat.js @@ -100,11 +100,13 @@ export default var slottedValues = slotFactValues(basisPosition, basisFactValues, comparatorFactValues); - if (!_.isEqual(slottedValues.left, slottedValues.right)) { + var remaining = _.difference(slottedValues.left, slottedValues.right); + + if (_.isEmpty(remaining)) { + slottedValues.isDivergent = false; + } else { slottedValues.isDivergent = true; containsValueArray = true; - } else { - slottedValues.isDivergent = false; } return slottedValues; diff --git a/awx/ui/tests/unit/system-tracking/compare-facts/flat-test.js b/awx/ui/tests/unit/system-tracking/compare-facts/flat-test.js index 6e7034d78f..bd72cb774a 100644 --- a/awx/ui/tests/unit/system-tracking/compare-facts/flat-test.js +++ b/awx/ui/tests/unit/system-tracking/compare-facts/flat-test.js @@ -504,6 +504,47 @@ describe('CompareFacts.Flat', function() { expectation = expect(result).to.be.empty; }); + it('is insensitive to the order of the facts', function() { + var expectation; + var factTemplate = + { hasTemplate: + function() { + return true; + }, + render: function(fact) { + return fact.version; + } + }; + + var result = compareFacts( + { position: 'left', + facts: + [{ 'name': 'some-package', + 'version': 'efgh' + }, + { 'name': 'some-package', + 'version': 'abcd' + }] + }, + { position: 'right', + facts: + [{ 'name': 'some-package', + 'version': 'abcd' + }, + { 'name': 'some-package', + 'version': 'efgh' + }] + + }, options({ compareKey: ['value'], + factTemplate: factTemplate, + supportsValueArray: true + })); + + // Use assignment to avoid jshint warning + expectation = expect(result).to.be.empty; + }); + + }); });