adhoc_variable_specs.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {describe, beforeEach, it, sinon, expect, angularMocks} 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. ]
  11. });
  12. var urlValue = variable.getValueForUrl();
  13. expect(urlValue).to.eql(["key1|=|value1", "key2|!=|value2"]);
  14. });
  15. });
  16. describe('when deserializing from url', function() {
  17. it('should restore filters', function() {
  18. var variable = new AdhocVariable({});
  19. variable.setValueFromUrl(["key1|=|value1", "key2|!=|value2"]);
  20. expect(variable.filters[0].key).to.be('key1');
  21. expect(variable.filters[0].operator).to.be('=');
  22. expect(variable.filters[0].value).to.be('value1');
  23. expect(variable.filters[1].key).to.be('key2');
  24. expect(variable.filters[1].operator).to.be('!=');
  25. expect(variable.filters[1].value).to.be('value2');
  26. });
  27. });
  28. });