Files
awx/awx/ui/tests/unit/system-tracking/compare-facts/nested-test.js

180 lines
5.5 KiB
JavaScript

import compareFacts from 'tower/system-tracking/compare-facts/nested';
/* jshint node: true */
/* globals -expect, -_ */
var _, expect;
// 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');
if (typeof window === 'undefined') {
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.Nested', function() {
it('returns empty array with no fact data', function() {
var result = compareFacts({ facts: [] }, { facts: [] });
expect(result).to.deep.equal([]);
});
it('returns empty array when no differences', function() {
var result = compareFacts(
{ facts:
{ 'testing_facts':
{ 'foo': 'bar'
}
}
},
{ facts:
{ 'testing_facts':
{ 'foo': 'bar'
}
}
});
expect(result).to.deep.equal([]);
});
context('when only left set has data', function() {
it('returns values with data for value1 and "absent" for value2', function() {
var result = compareFacts(
{ position: 'left',
facts:
{ 'testing_facts':
{ 'foo': 'bar'
}
}
},
{ position: 'right',
facts:
{}
});
expect(result[0].facts).to.contain
.an.item
.with.property('value1', 'bar');
expect(result[0].facts).to.contain
.an.item
.with.property('value2', 'absent');
});
});
context('when only right set has data', function() {
it('returns values with data for value2 and "absent" for value1', function() {
var result = compareFacts(
{ position: 'left',
facts:
{}
},
{ position: 'right',
facts:
{ 'testing_facts':
{ 'foo': 'bar'
}
}
});
expect(result).not.to.be.empty;
expect(result[0].facts).to.contain
.an.item
.with.property('value1', 'absent');
expect(result[0].facts).to.contain
.an.item
.with.property('value2', 'bar');
});
});
context('when both sets have fact data and differences exist', function() {
it('does not consider false values "absent"', function() {
var result = compareFacts(
{ position: 'left',
facts:
{ 'testing_facts':
{ 'foo': false
}
}
},
{ position: 'right',
facts:
{ 'testing_facts':
{ 'foo': true
}
}
});
expect(result[0].facts).to.contain
.an.item
.with.property('value1', false);
expect(result[0].facts).to.contain
.an.item
.with.property('value2', true);
});
it('uses "absent" for both values when neither has data', function() {
var result = compareFacts(
{ position: 'left',
facts:
{ 'testing_facts':
{ 'foo': 'baz',
'blah': null
}
}
},
{ position: 'right',
facts:
{ 'testing_facts':
{ 'foo': 'bar',
'blah': null
}
}
});
expect(result[0].facts).to.contain
.an.item
.with.property('value1', 'absent');
expect(result[0].facts).to.contain
.an.item
.with.property('value2', 'absent');
});
});
});