variable_specs.ts 1.8 KB

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