2017-12-20 12:33:33 +01:00
|
|
|
import { containsVariable, assignModelProperties } from '../variable';
|
2016-09-16 16:50:30 +02:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('containsVariable', function() {
|
|
|
|
|
describe('when checking if a string contains a variable', function() {
|
|
|
|
|
it('should find it with $var syntax', function() {
|
|
|
|
|
var contains = containsVariable('this.$test.filters', 'test');
|
2017-10-22 12:48:20 +02:00
|
|
|
expect(contains).toBe(true);
|
2016-09-16 16:50:30 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should not find it if only part matches with $var syntax', function() {
|
|
|
|
|
var contains = containsVariable('this.$serverDomain.filters', 'server');
|
2017-10-22 12:48:20 +02:00
|
|
|
expect(contains).toBe(false);
|
2016-09-16 16:50:30 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should find it if it ends with variable and passing multiple test strings', function() {
|
2017-12-21 08:39:31 +01:00
|
|
|
var contains = containsVariable('show field keys from $pgmetric', 'test string2', 'pgmetric');
|
2017-10-22 12:48:20 +02:00
|
|
|
expect(contains).toBe(true);
|
2017-02-20 09:31:50 +01:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should find it with [[var]] syntax', function() {
|
|
|
|
|
var contains = containsVariable('this.[[test]].filters', 'test');
|
2017-10-22 12:48:20 +02:00
|
|
|
expect(contains).toBe(true);
|
2016-09-16 16:50:30 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should find it when part of segment', function() {
|
|
|
|
|
var contains = containsVariable('metrics.$env.$group-*', 'group');
|
2017-10-22 12:48:20 +02:00
|
|
|
expect(contains).toBe(true);
|
2016-09-16 16:50:30 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should find it its the only thing', function() {
|
|
|
|
|
var contains = containsVariable('$env', 'env');
|
2017-10-22 12:48:20 +02:00
|
|
|
expect(contains).toBe(true);
|
2016-09-16 16:50:30 +02:00
|
|
|
});
|
2016-09-17 11:28:45 +02:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('should be able to pass in multiple test strings', function() {
|
|
|
|
|
var contains = containsVariable('asd', 'asd2.$env', 'env');
|
2017-10-22 12:48:20 +02:00
|
|
|
expect(contains).toBe(true);
|
2016-09-17 11:28:45 +02:00
|
|
|
});
|
2016-09-16 16:50:30 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
describe('assignModelProperties', function() {
|
|
|
|
|
it('only set properties defined in defaults', function() {
|
|
|
|
|
var target: any = { test: 'asd' };
|
2017-12-19 16:06:54 +01:00
|
|
|
assignModelProperties(target, { propA: 1, propB: 2 }, { propB: 0 });
|
2017-10-22 12:48:20 +02:00
|
|
|
expect(target.propB).toBe(2);
|
2017-12-20 12:33:33 +01:00
|
|
|
expect(target.test).toBe('asd');
|
2016-09-19 15:15:15 +02:00
|
|
|
});
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
it('use default value if not found on source', function() {
|
|
|
|
|
var target: any = { test: 'asd' };
|
2017-12-19 16:06:54 +01:00
|
|
|
assignModelProperties(target, { propA: 1, propB: 2 }, { propC: 10 });
|
2017-10-22 12:48:20 +02:00
|
|
|
expect(target.propC).toBe(10);
|
2016-09-19 15:15:15 +02:00
|
|
|
});
|
|
|
|
|
});
|