mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 03:17:38 -02:30
Allow fact template to flatten or keep key/value structure
This commit is contained in:
16
awx/ui/static/js/shared/format-epoch/format-epoch.filter.js
Normal file
16
awx/ui/static/js/shared/format-epoch/format-epoch.filter.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
export default
|
||||||
|
[ 'moment',
|
||||||
|
function(moment) {
|
||||||
|
return function(seconds, formatStr) {
|
||||||
|
if (!formatStr) {
|
||||||
|
formatStr = 'll LT';
|
||||||
|
}
|
||||||
|
|
||||||
|
var millis = seconds * 1000;
|
||||||
|
|
||||||
|
return moment(millis).format(formatStr);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
9
awx/ui/static/js/shared/format-epoch/main.js
Normal file
9
awx/ui/static/js/shared/format-epoch/main.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import formatEpoch from './format-epoch.filter';
|
||||||
|
import moment from 'tower/shared/moment/main';
|
||||||
|
|
||||||
|
export default
|
||||||
|
angular.module('formatEpoch',
|
||||||
|
[ moment.name
|
||||||
|
])
|
||||||
|
.filter('formatEpoch', formatEpoch);
|
||||||
|
|
||||||
@@ -9,26 +9,39 @@ import compareFlatFacts from './compare-facts/flat';
|
|||||||
import FactTemplate from './compare-facts/fact-template';
|
import FactTemplate from './compare-facts/fact-template';
|
||||||
|
|
||||||
export function compareFacts(module, facts) {
|
export function compareFacts(module, facts) {
|
||||||
|
|
||||||
|
|
||||||
|
var renderOptions = _.merge({}, module);
|
||||||
|
|
||||||
// If the module has a template or includes a list of keys to display,
|
// If the module has a template or includes a list of keys to display,
|
||||||
// then perform a flat comparison, otherwise assume nested
|
// then perform a flat comparison, otherwise assume nested
|
||||||
//
|
//
|
||||||
if (module.factTemplate || module.nameKey) {
|
if (renderOptions.factTemplate || renderOptions.nameKey) {
|
||||||
// For flat structures we compare left-to-right, then right-to-left to
|
// For flat structures we compare left-to-right, then right-to-left to
|
||||||
// make sure we get a good comparison between both hosts
|
// make sure we get a good comparison between both hosts
|
||||||
var compare = _.partialRight(compareFlatFacts,
|
|
||||||
module.nameKey,
|
|
||||||
module.compareKey,
|
|
||||||
new FactTemplate(module.factTemplate));
|
|
||||||
|
|
||||||
var leftToRight = compare(facts[0], facts[1]);
|
if (_.isPlainObject(renderOptions.factTemplate)) {
|
||||||
var rightToLeft = compare(facts[1], facts[0]);
|
renderOptions.factTemplate =
|
||||||
|
_.mapValues(renderOptions.factTemplate, function(template) {
|
||||||
|
if (typeof template === 'string' || typeof template === 'function') {
|
||||||
|
return new FactTemplate(template);
|
||||||
|
} else {
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
renderOptions.factTemplate = new FactTemplate(renderOptions.factTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
var leftToRight = compareFlatFacts(facts[0], facts[1], renderOptions);
|
||||||
|
var rightToLeft = compareFlatFacts(facts[1], facts[0], renderOptions);
|
||||||
|
|
||||||
return _(leftToRight)
|
return _(leftToRight)
|
||||||
.concat(rightToLeft)
|
.concat(rightToLeft)
|
||||||
.unique('displayKeyPath')
|
.unique('displayKeyPath')
|
||||||
.thru(function(result) {
|
.thru(function(result) {
|
||||||
return { factData: result,
|
return { factData: result,
|
||||||
isNestedDisplay: _.isUndefined(module.factTemplate)
|
isNestedDisplay: _.isPlainObject(renderOptions.factTemplate)
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.value();
|
.value();
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import stringFilters from 'tower/shared/string-filters/main';
|
||||||
|
import formatEpoch from 'tower/shared/format-epoch/main';
|
||||||
|
|
||||||
|
var $injector = angular.injector(['ng', stringFilters.name, formatEpoch.name]);
|
||||||
|
var $interpolate = $injector.get('$interpolate');
|
||||||
|
|
||||||
|
function FactTemplate(templateString) {
|
||||||
|
this.templateString = templateString;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadFactTemplate(factTemplate, fact) {
|
||||||
|
if (_.isFunction(factTemplate)) {
|
||||||
|
return factTemplate(fact);
|
||||||
|
} else {
|
||||||
|
return factTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FactTemplate.prototype.render = function(factData) {
|
||||||
|
|
||||||
|
if (_.isUndefined(factData) || _.isEmpty(factData)) {
|
||||||
|
return 'absent';
|
||||||
|
}
|
||||||
|
|
||||||
|
var template = loadFactTemplate(this.templateString, factData);
|
||||||
|
return $interpolate(template)(factData);
|
||||||
|
};
|
||||||
|
|
||||||
|
FactTemplate.prototype.hasTemplate = function() {
|
||||||
|
return !_.isUndefined(this.templateString);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FactTemplate;
|
||||||
@@ -27,7 +27,6 @@ export default
|
|||||||
var nameKey = renderOptions.nameKey;
|
var nameKey = renderOptions.nameKey;
|
||||||
var compareKeys = renderOptions.compareKey;
|
var compareKeys = renderOptions.compareKey;
|
||||||
var keyNameMap = renderOptions.keyNameMap;
|
var keyNameMap = renderOptions.keyNameMap;
|
||||||
var valueFormatter = renderOptions.valueFormatter;
|
|
||||||
var factTemplate = renderOptions.factTemplate;
|
var factTemplate = renderOptions.factTemplate;
|
||||||
|
|
||||||
|
|
||||||
@@ -35,8 +34,6 @@ export default
|
|||||||
var searcher = {};
|
var searcher = {};
|
||||||
searcher[nameKey] = basisFact[nameKey];
|
searcher[nameKey] = basisFact[nameKey];
|
||||||
|
|
||||||
var slottedValues, basisValue, comparatorValue;
|
|
||||||
|
|
||||||
var matchingFact = _.where(comparatorFacts.facts, searcher);
|
var matchingFact = _.where(comparatorFacts.facts, searcher);
|
||||||
var diffs;
|
var diffs;
|
||||||
|
|
||||||
@@ -50,53 +47,75 @@ export default
|
|||||||
var comparisonResults =
|
var comparisonResults =
|
||||||
_.reduce(compareKeys, function(result, compareKey) {
|
_.reduce(compareKeys, function(result, compareKey) {
|
||||||
|
|
||||||
if (_.isEmpty(matchingFact)) {
|
var comparatorFact = matchingFact[0] || {};
|
||||||
comparatorValue = 'absent';
|
var isNestedDisplay = false;
|
||||||
} else {
|
|
||||||
comparatorValue = matchingFact[0][compareKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
var slottedValues = slotFactValues(basisFacts.position,
|
var slottedValues = slotFactValues(basisFacts.position,
|
||||||
basisFact[compareKey],
|
basisFact[compareKey],
|
||||||
comparatorValue);
|
comparatorFact[compareKey]);
|
||||||
|
|
||||||
if (_.isUndefined(slottedValues.left) && _.isUndefined(slottedValues.right)) {
|
if (_.isUndefined(slottedValues.left) && _.isUndefined(slottedValues.right)) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var template = factTemplate;
|
||||||
|
|
||||||
|
if (_.isObject(template) && template.hasOwnProperty(compareKey)) {
|
||||||
|
template = template[compareKey];
|
||||||
|
|
||||||
|
// 'true' means render the key without formatting
|
||||||
|
if (template === true) {
|
||||||
|
template =
|
||||||
|
{ render: function(fact) { return fact[compareKey]; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
isNestedDisplay = true;
|
||||||
|
} else if (typeof template.hasTemplate === 'function' && !template.hasTemplate()) {
|
||||||
|
template =
|
||||||
|
{ render: function(fact) { return fact[compareKey]; }
|
||||||
|
};
|
||||||
|
isNestedDisplay = true;
|
||||||
|
} else if (typeof factTemplate.render === 'function') {
|
||||||
|
template = factTemplate;
|
||||||
|
} else if (!template.hasOwnProperty(compareKey)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (basisFacts.position === 'left') {
|
||||||
|
slottedValues.left = template.render(basisFact);
|
||||||
|
slottedValues.right = template.render(comparatorFact);
|
||||||
|
} else {
|
||||||
|
slottedValues.left = template.render(comparatorFact);
|
||||||
|
slottedValues.right = template.render(basisFact);
|
||||||
|
}
|
||||||
|
|
||||||
if (slottedValues.left !== slottedValues.right) {
|
if (slottedValues.left !== slottedValues.right) {
|
||||||
slottedValues.isDivergent = true;
|
slottedValues.isDivergent = true;
|
||||||
} else {
|
} else {
|
||||||
slottedValues.isDivergent = false;
|
slottedValues.isDivergent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
result[compareKey] = slottedValues;
|
if (isNestedDisplay) {
|
||||||
|
result[compareKey] = slottedValues;
|
||||||
|
} else {
|
||||||
|
result = slottedValues;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
var hasDiffs = _.any(comparisonResults, { isDivergent: true });
|
var hasDiffs =
|
||||||
|
_.any(comparisonResults, { isDivergent: true }) ||
|
||||||
|
comparisonResults.isDivergent === true;
|
||||||
|
|
||||||
if (hasDiffs && factTemplate.hasTemplate()) {
|
if (hasDiffs && typeof factTemplate.render === 'function') {
|
||||||
|
|
||||||
basisValue = factTemplate.render(basisFact);
|
diffs =
|
||||||
|
{ keyName: basisFact[nameKey],
|
||||||
if (_.isEmpty(matchingFact)) {
|
value1: comparisonResults.left,
|
||||||
comparatorValue = 'absent';
|
value2: comparisonResults.right
|
||||||
} else {
|
};
|
||||||
comparatorValue = factTemplate.render(matchingFact[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_.isEmpty(comparisonResults)) {
|
|
||||||
|
|
||||||
slottedValues = slotFactValues(basisFact.position, basisValue, comparatorValue);
|
|
||||||
|
|
||||||
diffs =
|
|
||||||
{ keyName: basisFact[nameKey],
|
|
||||||
value1: slottedValues.left,
|
|
||||||
value2: slottedValues.right
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (hasDiffs) {
|
} else if (hasDiffs) {
|
||||||
|
|
||||||
@@ -111,9 +130,7 @@ export default
|
|||||||
|
|
||||||
return { keyName: keyName,
|
return { keyName: keyName,
|
||||||
value1: slottedValues.left,
|
value1: slottedValues.left,
|
||||||
value1IsAbsent: slottedValues.left === 'absent',
|
|
||||||
value2: slottedValues.right,
|
value2: slottedValues.right,
|
||||||
value2IsAbsent: slottedValues.right === 'absent',
|
|
||||||
isDivergent: slottedValues.isDivergent
|
isDivergent: slottedValues.isDivergent
|
||||||
};
|
};
|
||||||
}).compact()
|
}).compact()
|
||||||
|
|||||||
@@ -13,8 +13,16 @@ var moduleConfig =
|
|||||||
},
|
},
|
||||||
'files':
|
'files':
|
||||||
{ compareKey: ['size', 'mode', 'md5', 'mtime', 'gid', 'uid'],
|
{ compareKey: ['size', 'mode', 'md5', 'mtime', 'gid', 'uid'],
|
||||||
|
keyNameMap:
|
||||||
|
{ 'uid': 'ownership'
|
||||||
|
},
|
||||||
|
factTemplate:
|
||||||
|
{ 'uid': 'user id: {{uid}}, group id: {{gid}}',
|
||||||
|
'mode': true,
|
||||||
|
'md5': true,
|
||||||
|
'mtime': '{{mtime|formatEpoch}}'
|
||||||
|
},
|
||||||
nameKey: 'path',
|
nameKey: 'path',
|
||||||
displayKeys: ['size', 'mode', 'mtime', 'uid', 'gid', 'md5'],
|
|
||||||
sortKey: 3
|
sortKey: 3
|
||||||
},
|
},
|
||||||
'ansible':
|
'ansible':
|
||||||
|
|||||||
@@ -3,14 +3,31 @@ import compareFacts from 'tower/system-tracking/compare-facts/flat';
|
|||||||
/* jshint node: true */
|
/* jshint node: true */
|
||||||
/* globals -expect, -_ */
|
/* globals -expect, -_ */
|
||||||
|
|
||||||
var chai = require('chai');
|
var _, expect;
|
||||||
var _ = require('lodash');
|
|
||||||
var chaiThings = require('chai-things');
|
|
||||||
|
|
||||||
chai.use(chaiThings);
|
// This makes this test runnable in node OR karma. The sheer
|
||||||
|
// number of times I had to run this test made the karma
|
||||||
|
// workflow just too dang slow for me. Maybe this can
|
||||||
|
// be a pattern going forward? Not sure...
|
||||||
|
//
|
||||||
|
(function(global) {
|
||||||
|
var chai = global.chai || require('chai');
|
||||||
|
|
||||||
global.expect = chai.expect;
|
if (typeof window === 'undefined') {
|
||||||
global._ = _;
|
var chaiThings = global.chaiThings || require('chai-things');
|
||||||
|
chai.use(chaiThings);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = global._ || require('lodash');
|
||||||
|
expect = global.expect || chai.expect;
|
||||||
|
|
||||||
|
global.expect = expect;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
global._ = _;
|
||||||
|
|
||||||
|
})(typeof window === 'undefined' ? global : window);
|
||||||
|
|
||||||
describe('CompareFacts.Flat', function() {
|
describe('CompareFacts.Flat', function() {
|
||||||
|
|
||||||
@@ -92,16 +109,12 @@ describe('CompareFacts.Flat', function() {
|
|||||||
facts:
|
facts:
|
||||||
[{ keyName: 'value',
|
[{ keyName: 'value',
|
||||||
value1: 'bar',
|
value1: 'bar',
|
||||||
value1IsAbsent: false,
|
|
||||||
value2: 'baz',
|
value2: 'baz',
|
||||||
value2IsAbsent: false,
|
|
||||||
isDivergent: true
|
isDivergent: true
|
||||||
},
|
},
|
||||||
{ keyName: 'extra',
|
{ keyName: 'extra',
|
||||||
value1: 'doo',
|
value1: 'doo',
|
||||||
value1IsAbsent: false,
|
|
||||||
value2: 'doo',
|
value2: 'doo',
|
||||||
value2IsAbsent: false,
|
|
||||||
isDivergent: false
|
isDivergent: false
|
||||||
}]
|
}]
|
||||||
}]);
|
}]);
|
||||||
@@ -130,16 +143,12 @@ describe('CompareFacts.Flat', function() {
|
|||||||
facts:
|
facts:
|
||||||
[{ keyName: 'value',
|
[{ keyName: 'value',
|
||||||
value1: 'bar',
|
value1: 'bar',
|
||||||
value1IsAbsent: false,
|
|
||||||
value2: 'baz',
|
value2: 'baz',
|
||||||
value2IsAbsent: false,
|
|
||||||
isDivergent: true
|
isDivergent: true
|
||||||
},
|
},
|
||||||
{ keyName: 'extra',
|
{ keyName: 'extra',
|
||||||
value1: 'doo',
|
value1: 'doo',
|
||||||
value1IsAbsent: false,
|
|
||||||
value2: 'doo',
|
value2: 'doo',
|
||||||
value2IsAbsent: false,
|
|
||||||
isDivergent: false
|
isDivergent: false
|
||||||
}]
|
}]
|
||||||
}]);
|
}]);
|
||||||
@@ -172,48 +181,131 @@ describe('CompareFacts.Flat', function() {
|
|||||||
expect(result[0].facts).to.include.something.that.deep.equals(
|
expect(result[0].facts).to.include.something.that.deep.equals(
|
||||||
{ keyName: 'blah',
|
{ keyName: 'blah',
|
||||||
value1: 'doo',
|
value1: 'doo',
|
||||||
value1IsAbsent: false,
|
|
||||||
value2: 'doo',
|
value2: 'doo',
|
||||||
value2IsAbsent: false,
|
|
||||||
isDivergent: false
|
isDivergent: false
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// it('allows formatting values with valueFormat parameter', function() {
|
it('allows flattening values with factTemplate parameter', function() {
|
||||||
// var valueFormat =
|
var factTemplate =
|
||||||
// function(key, values) {
|
{ hasTemplate:
|
||||||
// if (key === 'extra') {
|
function() {
|
||||||
// return 'formatted';
|
return true;
|
||||||
// }
|
},
|
||||||
// }
|
render: function(fact) {
|
||||||
|
return 'value: ' + fact.value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// var result = compareFacts(
|
var result = compareFacts(
|
||||||
// { position: 'left',
|
{ position: 'left',
|
||||||
// facts:
|
facts:
|
||||||
// [{ 'name': 'foo',
|
[{ 'name': 'foo',
|
||||||
// 'value': 'bar',
|
'value': 'bar',
|
||||||
// 'extra': 'doo'
|
'extra': 'doo'
|
||||||
// }]
|
}]
|
||||||
// },
|
},
|
||||||
// { position: 'right',
|
{ position: 'right',
|
||||||
// facts:
|
facts:
|
||||||
// [{ 'name': 'foo',
|
[{ 'name': 'foo',
|
||||||
// 'value': 'baz',
|
'value': 'baz',
|
||||||
// 'extra': 'doo'
|
'extra': 'doo'
|
||||||
// }]
|
}]
|
||||||
// }, 'name', ['value', 'extra', 'blah'], keyNameMap, defaultTemplate, );
|
}, options({ compareKey: ['value'],
|
||||||
|
factTemplate: factTemplate
|
||||||
|
}));
|
||||||
|
|
||||||
// expect(result[0].facts).to.include.something.that.deep.equals(
|
expect(result[0].facts).to.deep.equal(
|
||||||
// { keyName: 'extra',
|
{ keyName: 'foo',
|
||||||
// value1: 'formatted',
|
value1: 'value: bar',
|
||||||
// value1IsAbsent: false,
|
value2: 'value: baz'
|
||||||
// value2: 'formatted',
|
});
|
||||||
// value2IsAbsent: false,
|
});
|
||||||
// isDivergent: false
|
|
||||||
// });
|
|
||||||
|
|
||||||
// });
|
it('allows formatting values with factTemplate parameter', function() {
|
||||||
|
var values = ['value1', 'value2'];
|
||||||
|
var factTemplate =
|
||||||
|
{ 'value':
|
||||||
|
{ hasTemplate: function() {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
render: function() {
|
||||||
|
return values.shift();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'extra': true
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = compareFacts(
|
||||||
|
{ position: 'left',
|
||||||
|
facts:
|
||||||
|
[{ 'name': 'foo',
|
||||||
|
'value': 'bar',
|
||||||
|
'extra': 'doo'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{ position: 'right',
|
||||||
|
facts:
|
||||||
|
[{ 'name': 'foo',
|
||||||
|
'value': 'baz',
|
||||||
|
'extra': 'doo'
|
||||||
|
}]
|
||||||
|
}, options({ compareKey: ['value'],
|
||||||
|
factTemplate: factTemplate
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(result[0].facts).to.include.something.that.deep.equals(
|
||||||
|
{ keyName: 'value',
|
||||||
|
value1: 'value1',
|
||||||
|
value2: 'value2',
|
||||||
|
isDivergent: true
|
||||||
|
},
|
||||||
|
{ keyName: 'extra',
|
||||||
|
value1: 'doo',
|
||||||
|
value2: 'doo',
|
||||||
|
isDivergent: false
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('compares values using the formatted values, not the raw ones', function() {
|
||||||
|
var values = ['value1', 'value2'];
|
||||||
|
var factTemplate =
|
||||||
|
{ 'extra':
|
||||||
|
{ render: function() {
|
||||||
|
return values.shift();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = compareFacts(
|
||||||
|
{ position: 'left',
|
||||||
|
facts:
|
||||||
|
[{ 'name': 'foo',
|
||||||
|
'value': 'bar',
|
||||||
|
'extra': 'doo'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{ position: 'right',
|
||||||
|
facts:
|
||||||
|
[{ 'name': 'foo',
|
||||||
|
'value': 'bar',
|
||||||
|
'extra': 'doo'
|
||||||
|
}]
|
||||||
|
}, options({ factTemplate: factTemplate,
|
||||||
|
compareKey: ['extra']
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(result.length).to.be.greaterThan(0);
|
||||||
|
expect(result[0].facts).to.include.something.that.deep.equals(
|
||||||
|
{ keyName: 'extra',
|
||||||
|
value1: 'value1',
|
||||||
|
value2: 'value2',
|
||||||
|
isDivergent: true
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -230,7 +322,7 @@ describe('CompareFacts.Flat', function() {
|
|||||||
return facts;
|
return facts;
|
||||||
}
|
}
|
||||||
|
|
||||||
it('uses "absent" for the missing value', function() {
|
it('keeps missing values as undefined', function() {
|
||||||
|
|
||||||
var facts = factData([{ 'name': 'foo',
|
var facts = factData([{ 'name': 'foo',
|
||||||
'value': 'bar'
|
'value': 'bar'
|
||||||
@@ -246,14 +338,45 @@ describe('CompareFacts.Flat', function() {
|
|||||||
facts:
|
facts:
|
||||||
[{ keyName: 'value',
|
[{ keyName: 'value',
|
||||||
value1: 'bar',
|
value1: 'bar',
|
||||||
value1IsAbsent: false,
|
value2: undefined,
|
||||||
value2: 'absent',
|
|
||||||
value2IsAbsent: true,
|
|
||||||
isDivergent: true
|
isDivergent: true
|
||||||
}]
|
}]
|
||||||
}]);
|
}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('still keeps missing values as undefined when using a template', function() {
|
||||||
|
|
||||||
|
var factTemplate =
|
||||||
|
{ hasTemplate:
|
||||||
|
function() {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
render:
|
||||||
|
function(fact) {
|
||||||
|
return fact.value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var facts = factData([{ 'name': 'foo',
|
||||||
|
'value': 'bar'
|
||||||
|
}]);
|
||||||
|
|
||||||
|
var result = compareFacts(facts[0], facts[1],
|
||||||
|
options({ compareKey: ['value'],
|
||||||
|
factTemplate: factTemplate
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(result).to.deep.equal(
|
||||||
|
[{ displayKeyPath: 'foo',
|
||||||
|
nestingLevel: 0,
|
||||||
|
facts:
|
||||||
|
{ keyName: 'foo',
|
||||||
|
value1: 'bar',
|
||||||
|
value2: undefined
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
});
|
||||||
|
|
||||||
it('includes given compare keys from basisFacts', function() {
|
it('includes given compare keys from basisFacts', function() {
|
||||||
var facts = factData([{ 'name': 'foo',
|
var facts = factData([{ 'name': 'foo',
|
||||||
'value': 'bar',
|
'value': 'bar',
|
||||||
@@ -270,45 +393,18 @@ describe('CompareFacts.Flat', function() {
|
|||||||
facts:
|
facts:
|
||||||
[{ keyName: 'value',
|
[{ keyName: 'value',
|
||||||
value1: 'bar',
|
value1: 'bar',
|
||||||
value1IsAbsent: false,
|
value2: undefined,
|
||||||
value2: 'absent',
|
|
||||||
value2IsAbsent: true,
|
|
||||||
isDivergent: true
|
isDivergent: true
|
||||||
},
|
},
|
||||||
{ keyName: 'extra',
|
{ keyName: 'extra',
|
||||||
value1: 'doo',
|
value1: 'doo',
|
||||||
value1IsAbsent: false,
|
value2: undefined,
|
||||||
value2: 'absent',
|
|
||||||
value2IsAbsent: true,
|
|
||||||
isDivergent: true
|
isDivergent: true
|
||||||
}]
|
}]
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
context('with factTemplate', function() {
|
|
||||||
it('does not attempt to render the absent fact', function() {
|
|
||||||
var facts = factData([{ 'name': 'foo'
|
|
||||||
}]);
|
|
||||||
|
|
||||||
var renderCallCount = 0;
|
|
||||||
var factTemplate =
|
|
||||||
{ render: function() {
|
|
||||||
renderCallCount++;
|
|
||||||
},
|
|
||||||
hasTemplate: function() { return true; },
|
|
||||||
template: ""
|
|
||||||
};
|
|
||||||
|
|
||||||
compareFacts(facts[0], facts[1],
|
|
||||||
options({ compareKey: ['value'],
|
|
||||||
factTemplate: factTemplate
|
|
||||||
}));
|
|
||||||
|
|
||||||
expect(renderCallCount).to.equal(1);
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
context('with factTemplate', function() {
|
context('with factTemplate', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user