adhoc_variable_specs.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {describe, it, expect} from 'test/lib/common';
  2. import {AdhocVariable} from '../adhoc_variable';
  3. describe('AdhocVariable', function() {
  4. describe('when serializing to url', function() {
  5. it('should set return key value and op seperated by pipe', function() {
  6. var variable = new AdhocVariable({
  7. filters: [
  8. {key: 'key1', operator: '=', value: 'value1'},
  9. {key: 'key2', operator: '!=', value: 'value2'},
  10. {key: 'key3', operator: '=', value: 'value3a|value3b|value3c'},
  11. ]
  12. });
  13. var urlValue = variable.getValueForUrl();
  14. expect(urlValue).to.eql(["key1|=|value1", "key2|!=|value2", "key3|=|value3a__gfp__value3b__gfp__value3c"]);
  15. });
  16. });
  17. describe('when deserializing from url', function() {
  18. it('should restore filters', function() {
  19. var variable = new AdhocVariable({});
  20. variable.setValueFromUrl(["key1|=|value1", "key2|!=|value2", "key3|=|value3a__gfp__value3b__gfp__value3c"]);
  21. expect(variable.filters[0].key).to.be('key1');
  22. expect(variable.filters[0].operator).to.be('=');
  23. expect(variable.filters[0].value).to.be('value1');
  24. expect(variable.filters[1].key).to.be('key2');
  25. expect(variable.filters[1].operator).to.be('!=');
  26. expect(variable.filters[1].value).to.be('value2');
  27. expect(variable.filters[2].key).to.be('key3');
  28. expect(variable.filters[2].operator).to.be('=');
  29. expect(variable.filters[2].value).to.be('value3a|value3b|value3c');
  30. });
  31. });
  32. });