variable.jest.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {containsVariable, assignModelProperties} from '../variable';
  2. describe('containsVariable', function() {
  3. describe('when checking if a string contains a variable', function() {
  4. it('should find it with $var syntax', function() {
  5. var contains = containsVariable('this.$test.filters', 'test');
  6. expect(contains).toBe(true);
  7. });
  8. it('should not find it if only part matches with $var syntax', function() {
  9. var contains = containsVariable('this.$serverDomain.filters', 'server');
  10. expect(contains).toBe(false);
  11. });
  12. it('should find it if it ends with variable and passing multiple test strings', function() {
  13. var contains = containsVariable('show field keys from $pgmetric', 'test string2', 'pgmetric');
  14. expect(contains).toBe(true);
  15. });
  16. it('should find it with [[var]] syntax', function() {
  17. var contains = containsVariable('this.[[test]].filters', 'test');
  18. expect(contains).toBe(true);
  19. });
  20. it('should find it when part of segment', function() {
  21. var contains = containsVariable('metrics.$env.$group-*', 'group');
  22. expect(contains).toBe(true);
  23. });
  24. it('should find it its the only thing', function() {
  25. var contains = containsVariable('$env', 'env');
  26. expect(contains).toBe(true);
  27. });
  28. it('should be able to pass in multiple test strings', function() {
  29. var contains = containsVariable('asd','asd2.$env', 'env');
  30. expect(contains).toBe(true);
  31. });
  32. });
  33. });
  34. describe('assignModelProperties', function() {
  35. it('only set properties defined in defaults', function() {
  36. var target: any = {test: 'asd'};
  37. assignModelProperties(target, {propA: 1, propB: 2}, {propB: 0});
  38. expect(target.propB).toBe(2);
  39. expect(target.test).toBe('asd');
  40. });
  41. it('use default value if not found on source', function() {
  42. var target: any = {test: 'asd'};
  43. assignModelProperties(target, {propA: 1, propB: 2}, {propC: 10});
  44. expect(target.propC).toBe(10);
  45. });
  46. });